author | Claus Gittinger <cg@exept.de> |
Thu, 12 Feb 2004 19:39:06 +0100 | |
changeset 1482 | d80c83f1167a |
parent 1471 | 8752bd8a5581 |
child 1487 | c3af432fdd7c |
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 |
||
1043 | 13 |
"{ Package: 'stx:libcomp' }" |
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 |
1077
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
18 |
currentBlock parseForCode readInstVars readClassVars readGlobals |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
19 |
usedInstVars usedClassVars usedVars modifiedInstVars |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
20 |
modifiedClassVars modifiedGlobals usesSuper usedGlobals |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
21 |
usedSymbols messagesSent messagesSentToSelf messagesSentToSuper |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
22 |
localVarDefPosition evalExitBlock selfNode superNode nilNode |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
23 |
hasPrimitiveCode hasNonOptionalPrimitiveCode primitiveNr |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
24 |
primitiveResource logged warnedUndefVars warnedUnknownNamespaces |
1160 | 25 |
warnSTXHereExtensionUsed warnUnusedVars correctedSource |
26 |
foldConstants lineNumberInfo currentNamespace |
|
27 |
currentUsedNamespaces warnUndeclared methodNode |
|
28 |
alreadyWarnedClassInstVarRefs localBlockVarDefPosition |
|
29 |
endOfSelectorPosition startOfBlockPosition primitiveContextInfo |
|
30 |
usedLocalVars modifiedLocalVars alreadyWarnedUninitializedVars |
|
1295 | 31 |
alreadyWarnedUnimplementedSelectors returnedValues currentPackage |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
32 |
doItTemporaries inFunctionCallArgument' |
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
33 |
classVariableNames:'PrevClass PrevInstVarNames PrevClassVarNames |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
34 |
PrevClassInstVarNames LazyCompilation ArraysAreImmutable |
1160 | 35 |
ImplicitSelfSends WarnST80Directives WarnUnusedVars FoldConstants |
36 |
LineNumberInfo SuppressDoItCompilation StringsAreImmutable |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
37 |
ParseErrorSignal RestartCompilationSignal |
1295 | 38 |
AllowFunctionCallSyntaxForBlockEvaluation AllowLazyValueExtension |
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
39 |
AllowVariableReferences AllowReservedWordsAsSelectors |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
40 |
AllowLocalVariableDeclarationWithInitializerExpression |
1471 | 41 |
AllowArrayIndexSyntaxExtension AllowDomainVariables' |
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
42 |
poolDictionaries:'' |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
43 |
category:'System-Compiler' |
0 | 44 |
! |
45 |
||
1423 | 46 |
ProceedableError subclass:#ParseError |
1434
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
47 |
instanceVariableNames:'errorMessage startPosition endPosition lineNumber' |
971 | 48 |
classVariableNames:'' |
49 |
poolDictionaries:'' |
|
50 |
privateIn:Parser |
|
51 |
! |
|
52 |
||
53 |
Parser::ParseError subclass:#UndefinedSuperclassError |
|
54 |
instanceVariableNames:'' |
|
55 |
classVariableNames:'' |
|
56 |
poolDictionaries:'' |
|
57 |
privateIn:Parser |
|
58 |
! |
|
59 |
||
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
60 |
Notification subclass:#UndefinedVariableNotification |
1399
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
61 |
instanceVariableNames:'parser' |
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
62 |
classVariableNames:'' |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
63 |
poolDictionaries:'' |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
64 |
privateIn:Parser |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
65 |
! |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
66 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
67 |
!Parser class methodsFor:'documentation'! |
19 | 68 |
|
20 | 69 |
copyright |
70 |
" |
|
71 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
44 | 72 |
All Rights Reserved |
20 | 73 |
|
74 |
This software is furnished under a license and may be used |
|
75 |
only in accordance with the terms of that license and with the |
|
76 |
inclusion of the above copyright notice. This software may not |
|
77 |
be provided or otherwise made available to, or used by, any |
|
78 |
other person. No title to or ownership of the software is |
|
79 |
hereby transferred. |
|
80 |
" |
|
81 |
! |
|
82 |
||
19 | 83 |
documentation |
84 |
" |
|
85 |
Parser is used for both parsing and evaluating smalltalk expressions; |
|
86 |
it first builds a parseTree which is then interpreted (evaluate) or |
|
87 |
compiled. Compilation is done in the subclass ByteCodeCompiler and/or |
|
88 |
the (planned) MachineCodeCompiler. |
|
89 |
||
173
247ae4b8af76
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
171
diff
changeset
|
90 |
methods of main interest are: |
755 | 91 |
Parser evaluateExpression:... |
19 | 92 |
|
93 |
and: |
|
755 | 94 |
Parser parseExpression:... |
95 |
Parser parseMethod:... |
|
19 | 96 |
|
97 |
there is protocol to parse complete methods, selector specs, body only etc. |
|
98 |
||
99 |
Parser is also used to find the referenced/modified inst/classvars of |
|
100 |
a method - this is done by sending parseXXX message to a parser and asking |
|
101 |
the parser for referencedXVars or modifiedXVars (see SystemBrowser). |
|
102 |
||
103 |
You can also use parsers for all kinds of other things (ChangesBrowser for |
|
104 |
example analyzes the expressions in the changelist ...) by looking at the |
|
105 |
parsers tree. (Although this is somewhat dangerous, since it exports the |
|
755 | 106 |
compilers internals ... better style is to add specialized query methods here) |
19 | 107 |
|
108 |
One instance of Parser is created to parse one method or expression - i.e. |
|
109 |
its not suggested to reuse parsers. |
|
110 |
||
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
111 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
112 |
Constant folding: |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
113 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
114 |
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
|
115 |
expressions involving integers and floats are constant folded |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
116 |
(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
|
117 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
Therefore, this mode is a bit dangerous and disabled by default. |
755 | 124 |
The current implementation, base upon a global constant-folding setting is somewhat stupid |
125 |
and intermediate - a better solution would be to allow the optimization to be controlled |
|
126 |
by a method-pragma, since it may make sense to disable optimization on a method level, |
|
127 |
if its known that the used constant objects are subject of modifications as described above. |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
128 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
129 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
130 |
Immutable arrays: |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
131 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
132 |
Immutable arrays are experimental and being evaluated. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
return the modified array. These are hard to find bugs. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
of st/x. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
143 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
144 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
145 |
|
260 | 146 |
[Instance variables:] |
147 |
||
755 | 148 |
classToCompileFor <Class> the class (or nil) we are compiling for |
149 |
||
150 |
selfValue <any> value to use as self when interpreting |
|
151 |
||
152 |
contextToEvaluateIn <Context> the context (or nil) when interpreting |
|
153 |
||
154 |
selector <Symbol> the selector of the parsed method |
|
155 |
(valid after parseMethodSpecification) |
|
156 |
methodArgs internal |
|
157 |
||
158 |
methodArgNames <Collection> the names of the arguments |
|
159 |
(valid after parseMethodSpecification) |
|
160 |
||
161 |
methodVars internal |
|
162 |
||
163 |
methodVarNames <Collection> the names of the method locals |
|
164 |
(valid after parseMethodBodyVarSpec) |
|
165 |
||
166 |
tree <ParseTree> the parse tree - valid after parsing |
|
167 |
||
168 |
currentBlock if currently parsing for a block |
|
169 |
||
170 |
usedInstVars set of all accessed instances variables |
|
171 |
(valid after parsing) |
|
172 |
||
173 |
usedClassVars same for classVars |
|
174 |
||
175 |
usedVars all used variables (inst, class & globals) |
|
176 |
||
177 |
modifiedInstVars set of all modified instance variables |
|
178 |
||
179 |
modifiedClassVars same for clasVars |
|
180 |
||
181 |
localVarDefPosition <Integer> the character offset of the local variable |
|
182 |
def. (i.e. the first '|' if any) |
|
183 |
Not yet used - prepared for automatic add of |
|
184 |
undefined variables |
|
185 |
||
186 |
evalExitBlock internal for interpretation |
|
187 |
||
188 |
selfNode <Node> cached one-and-only 'self' node |
|
189 |
superNode <Node> cached one-and-only 'super' node |
|
190 |
||
191 |
hasPrimitiveCode <Boolean> true, if it contains ST/X style primitive code |
|
192 |
hasNonOptionalPrimitiveCode |
|
193 |
<Boolean> true, if it contains ST/X style primitive code |
|
194 |
which is NOT flagged by the OPTIONAL directive. |
|
195 |
||
196 |
primitiveNr <Integer> the parsed ST-80 type primitive number (or nil) |
|
197 |
||
198 |
logged |
|
199 |
||
200 |
warnedUndefVars <Set> set of all variables which the parser has |
|
201 |
already output a warning (to avoid multiple |
|
202 |
warnings about the same variable) |
|
260 | 203 |
|
204 |
[Class variables:] |
|
205 |
||
755 | 206 |
PrevClass <Class> class, of which properties are |
207 |
cached in: |
|
208 |
||
209 |
PrevInstVarNames <Collection> instance variablenames of cached class |
|
210 |
PrevClassVarNames <Collection> class variablenames of cached class |
|
211 |
PrevClassInstVarNames <Collection> class instance variablenames of cached class |
|
212 |
||
213 |
LazyCompilation <Boolean> EXPERIMENTAL: lazy compilation |
|
214 |
||
215 |
ArraysAreImmutable <Boolean> if true, create array literals |
|
216 |
as instances of ImmutableArray, |
|
217 |
which cannot be stored into. |
|
218 |
Default is false, for compatibility. |
|
219 |
Can be turned on while developping |
|
220 |
new code to make certain that side |
|
221 |
effects are avoided. |
|
222 |
||
223 |
WarnST80Directives <Boolean> if true, give warnings about |
|
224 |
ST-80 directives (resource defs) |
|
225 |
which are ignored in st/x. |
|
226 |
defaults to false. |
|
227 |
||
228 |
FoldConstants <Symbol> controls how constant folding should be |
|
229 |
done. |
|
230 |
Can be one of: |
|
231 |
nil - no constant folding |
|
232 |
#level1 - numeric optimizations only |
|
233 |
#level2 - secure optimizations only |
|
234 |
#full - full folding |
|
235 |
||
236 |
level1: arithmetic on constant numbers |
|
237 |
||
238 |
level2: above PLUS array conversions with #asFloatArray, |
|
239 |
#asDoubleArray, string concatenation |
|
240 |
||
241 |
full: constant points. |
|
260 | 242 |
|
243 |
[see also:] |
|
755 | 244 |
ByteCodeCompiler Scanner ObjectFileLoader |
245 |
Workspace |
|
246 |
SystemBrowser |
|
263 | 247 |
|
248 |
[author:] |
|
755 | 249 |
Claus Gittinger |
19 | 250 |
" |
1399
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
251 |
! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
252 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
253 |
examples |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
254 |
" |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
255 |
[exBegin] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
256 |
Parser |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
257 |
evaluate:'1+2*3' |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
258 |
in:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
259 |
receiver:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
260 |
notifying:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
261 |
logged:false |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
262 |
ifFail:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
263 |
[exEnd] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
264 |
[exBegin] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
265 |
Parser undefinedVariableNotification handle:[:ex | |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
266 |
|badName| |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
267 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
268 |
badName := ex variableName. |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
269 |
ex proceedWith:(ConstantNode value:5). |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
270 |
] do:[ |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
271 |
^ self compilerClass |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
272 |
evaluate:'foo * 3' |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
273 |
in:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
274 |
receiver:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
275 |
notifying:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
276 |
logged:false |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
277 |
ifFail:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
278 |
] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
279 |
[exEnd] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
280 |
" |
141 | 281 |
! ! |
282 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
283 |
!Parser class methodsFor:'instance creation'! |
141 | 284 |
|
285 |
for:aStringOrStream in:aClass |
|
286 |
"return a new parser, reading code for aClass from aStringOrStream" |
|
287 |
||
288 |
|parser| |
|
289 |
||
290 |
parser := self for:aStringOrStream. |
|
291 |
parser setClassToCompileFor:aClass. |
|
292 |
^ parser |
|
293 |
! ! |
|
294 |
||
1419 | 295 |
!Parser class methodsFor:'Compatibility-ST80'! |
540 | 296 |
|
297 |
parse:aString class:aClass |
|
298 |
"same as #parseMethod:in: for ST80 compatibility." |
|
299 |
||
300 |
|parser| |
|
301 |
||
302 |
parser := self parseMethod:aString in:aClass. |
|
303 |
parser notNil ifTrue:[^ parser tree]. |
|
304 |
^ nil |
|
305 |
||
306 |
"Modified: 19.6.1997 / 16:34:57 / cg" |
|
307 |
! ! |
|
308 |
||
1419 | 309 |
!Parser class methodsFor:'Compatibility-Squeak'! |
920 | 310 |
|
311 |
evaluate:someString for:aReceiver logged:logged |
|
312 |
^ self evaluate:someString receiver:aReceiver logged:logged |
|
313 |
||
314 |
||
315 |
||
316 |
! ! |
|
317 |
||
1062 | 318 |
!Parser class methodsFor:'Signal constants'! |
319 |
||
320 |
parseErrorSignal |
|
321 |
^ ParseErrorSignal |
|
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
322 |
! |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
323 |
|
1468 | 324 |
restartCompilationSignal |
325 |
^ RestartCompilationSignal |
|
326 |
||
327 |
"Created: / 15.11.2001 / 22:57:05 / cg" |
|
328 |
! |
|
329 |
||
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
330 |
undefinedVariableNotification |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
331 |
^ UndefinedVariableNotification |
1062 | 332 |
! ! |
333 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
334 |
!Parser class methodsFor:'changes'! |
141 | 335 |
|
336 |
flushNameCache |
|
337 |
"unconditional flush name caches" |
|
338 |
||
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
339 |
[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
340 |
PrevClass notNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
341 |
PrevClass removeDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
342 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
343 |
PrevClass := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
344 |
PrevInstVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
345 |
PrevClassVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
346 |
PrevClassInstVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
347 |
] valueUninterruptably |
141 | 348 |
|
349 |
"Parser flushNameCache" |
|
350 |
! |
|
351 |
||
352 |
update:something with:someArgument from:changedObject |
|
353 |
"aClass has changed its definition - flush name caches if we have to" |
|
354 |
||
355 |
(changedObject == PrevClass) ifTrue:[ |
|
1090
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
356 |
something == #definition ifTrue:[ |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
357 |
self flushNameCache |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
358 |
] |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
359 |
]. |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
360 |
(changedObject == Smalltalk) ifTrue:[ |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
361 |
something == #classDefinition ifTrue:[ |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
362 |
self flushNameCache |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
363 |
] |
141 | 364 |
] |
365 |
! ! |
|
366 |
||
717 | 367 |
!Parser class methodsFor:'class initialization'! |
368 |
||
369 |
initialize |
|
370 |
LazyCompilation := false. "/ usually set to true in your .rc file |
|
752 | 371 |
ArraysAreImmutable := false. "/ usually left false for ST-80 compatibility |
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
372 |
StringsAreImmutable := false. "/ usually left false for ST-80 compatibility |
752 | 373 |
|
717 | 374 |
ImplicitSelfSends := false. |
375 |
WarnST80Directives := false. |
|
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
376 |
WarnUnusedVars := true. |
717 | 377 |
FoldConstants := #level1. |
378 |
LineNumberInfo := false. |
|
379 |
||
1062 | 380 |
ParseErrorSignal isNil ifTrue:[ |
1380 | 381 |
ParseErrorSignal := ParseError. |
1062 | 382 |
ParseErrorSignal notifierString:'parse error'. |
1380 | 383 |
|
384 |
"/ ParseErrorSignal := Error newSignalMayProceed:true. |
|
385 |
"/ ParseErrorSignal notifierString:'parse error'. |
|
386 |
"/ ParseErrorSignal nameClass:self message:#parseErrorSignal. |
|
1062 | 387 |
]. |
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
388 |
RestartCompilationSignal := Signal new. |
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
389 |
|
1090
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
390 |
Smalltalk addDependent:self. |
1062 | 391 |
|
717 | 392 |
" |
393 |
self initialize |
|
394 |
" |
|
395 |
||
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
396 |
"Modified: / 15.11.2001 / 22:54:09 / cg" |
717 | 397 |
! ! |
398 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
399 |
!Parser class methodsFor:'controlling compilation'! |
141 | 400 |
|
401 |
arraysAreImmutable |
|
402 |
"return true if arrays are immutable literals" |
|
403 |
||
404 |
^ ArraysAreImmutable |
|
405 |
! |
|
406 |
||
407 |
arraysAreImmutable:aBoolean |
|
408 |
"turn on/off immutable array literals - default is false for ST-80 compatibilty." |
|
409 |
||
410 |
ArraysAreImmutable := aBoolean. |
|
411 |
||
412 |
" |
|
413 |
can be added to your private.rc file: |
|
414 |
||
415 |
Compiler arraysAreImmutable:true |
|
416 |
Compiler arraysAreImmutable:false |
|
417 |
" |
|
418 |
! |
|
419 |
||
420 |
compileLazy |
|
421 |
"return true if compiling lazy" |
|
422 |
||
423 |
^ LazyCompilation. |
|
424 |
! |
|
425 |
||
426 |
compileLazy:aBoolean |
|
427 |
"turn on/off lazy compilation - return previous setting. |
|
428 |
Actually this flag belongs into the ByteCodeCompiler subclass, |
|
429 |
but it also controls the reporting of some errors here; therefore |
|
430 |
its located here" |
|
431 |
||
432 |
|oldLazy| |
|
433 |
||
434 |
oldLazy := LazyCompilation. |
|
435 |
LazyCompilation := aBoolean. |
|
436 |
^ oldLazy |
|
437 |
||
438 |
" |
|
439 |
Compiler compileLazy:false |
|
440 |
Compiler compileLazy:true |
|
441 |
" |
|
442 |
! |
|
443 |
||
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
444 |
foldConstants |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
445 |
"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
|
446 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
447 |
^ FoldConstants |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
448 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
449 |
"Created: 9.2.1996 / 17:40:13 / cg" |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
450 |
! |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
451 |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
452 |
foldConstants:aSymbol |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
453 |
"set the symbol describing how constants are to be folded. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
454 |
It can be: |
619 | 455 |
nil - no constant folding |
456 |
#level1 - numeric constants only |
|
457 |
#level2 - level1 PLUS array conversions PLUS string concatenation |
|
458 |
#full - level2 PLUS constant points, constant rectangles (dangerous)" |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
459 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
460 |
FoldConstants := aSymbol |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
461 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
462 |
"Created: 9.2.1996 / 17:40:34 / cg" |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
463 |
! |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
464 |
|
141 | 465 |
implicitSelfSends |
466 |
"return true if undefined variables with |
|
467 |
lowercase first character are to be turned |
|
468 |
into implicit self sends" |
|
469 |
||
470 |
^ ImplicitSelfSends |
|
471 |
! |
|
472 |
||
473 |
implicitSelfSends:aBoolean |
|
474 |
"turn on/off implicit self sends" |
|
475 |
||
476 |
ImplicitSelfSends := aBoolean |
|
477 |
||
478 |
" |
|
479 |
Compiler implicitSelfSends:true |
|
480 |
Compiler implicitSelfSends:false |
|
481 |
" |
|
377 | 482 |
! |
483 |
||
484 |
lineNumberInfo |
|
485 |
^ LineNumberInfo |
|
486 |
! |
|
487 |
||
488 |
lineNumberInfo:aBoolean |
|
489 |
LineNumberInfo := aBoolean |
|
752 | 490 |
! |
491 |
||
492 |
stringsAreImmutable |
|
493 |
"return true if strings are immutable literals" |
|
494 |
||
495 |
^ StringsAreImmutable |
|
496 |
||
497 |
"Created: / 3.8.1998 / 14:53:25 / cg" |
|
498 |
! |
|
499 |
||
500 |
stringsAreImmutable:aBoolean |
|
501 |
"turn on/off immutable string literals - default is false for ST-80 compatibilty." |
|
502 |
||
503 |
StringsAreImmutable := aBoolean. |
|
504 |
||
505 |
" |
|
506 |
can be added to your private.rc file: |
|
507 |
||
508 |
Compiler stringsAreImmutable:true |
|
509 |
Compiler stringsAreImmutable:false |
|
510 |
" |
|
511 |
||
512 |
"Created: / 3.8.1998 / 14:53:28 / cg" |
|
1160 | 513 |
! |
514 |
||
515 |
warnUnusedVars |
|
516 |
"controls generation of warning messages about unued method variables" |
|
517 |
||
518 |
^ WarnUnusedVars |
|
519 |
! |
|
520 |
||
521 |
warnUnusedVars:aBoolean |
|
522 |
"controls generation of warning messages about unued method variables" |
|
523 |
||
524 |
WarnUnusedVars := aBoolean |
|
19 | 525 |
! ! |
0 | 526 |
|
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
527 |
!Parser class methodsFor:'defaults'! |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
528 |
|
1413 | 529 |
allowArrayIndexSyntaxExtension |
530 |
"experimental" |
|
531 |
||
532 |
^ AllowArrayIndexSyntaxExtension ? false |
|
533 |
! |
|
534 |
||
535 |
allowArrayIndexSyntaxExtension:aBoolean |
|
536 |
"experimental" |
|
537 |
||
538 |
AllowArrayIndexSyntaxExtension := aBoolean. |
|
539 |
||
540 |
" |
|
541 |
self allowArrayIndexSyntaxExtension:true |
|
542 |
self allowArrayIndexSyntaxExtension:false |
|
543 |
" |
|
544 |
! |
|
545 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
546 |
allowReservedWordsAsSelectors |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
547 |
"return true, if self, super, thisContext, nil, true and false are to be allowed |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
548 |
as unary message selectors." |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
549 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
550 |
^ AllowReservedWordsAsSelectors ? false |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
551 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
552 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
553 |
allowReservedWordsAsSelectors:aBoolean |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
554 |
"enable/disable, if self, super, thisContext, nil, true and false are to be allowed |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
555 |
as unary message selectors." |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
556 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
557 |
AllowReservedWordsAsSelectors := aBoolean. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
558 |
self setupActions |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
559 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
560 |
" |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
561 |
self allowReservedWordsAsSelectors:true |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
562 |
self allowReservedWordsAsSelectors:false |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
563 |
" |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
564 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
565 |
|
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
566 |
maxLineNumber |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
567 |
"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
|
568 |
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
|
569 |
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
|
570 |
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
|
571 |
|
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
572 |
^ 255 |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
573 |
|
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
574 |
"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
|
575 |
! ! |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
576 |
|
1187 | 577 |
!Parser class methodsFor:'error correction'! |
578 |
||
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
579 |
findBest:nMax selectorsFor:aString in:aClassOrNil |
1187 | 580 |
"collect known selectors with their spelling distances to aString; |
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
581 |
return the nMax best suggestions. If the argument, aClassOrNil is not nil, |
1187 | 582 |
the message is assumed to be sent to instances of that class (i.e. offer |
583 |
corrections from that hierarchy only)" |
|
584 |
||
1286 | 585 |
|info block lcSelector| |
1187 | 586 |
|
587 |
info := SortedCollection new. |
|
588 |
info sortBlock:[:a :b | a value > b value]. |
|
589 |
||
590 |
lcSelector := aString asLowercase. |
|
591 |
||
592 |
block := [:sym :mthd| |
|
1215 | 593 |
|dist lcSym keepThis| |
1187 | 594 |
|
595 |
lcSym := sym asLowercase. |
|
596 |
(info contains:[:i | i key == sym]) ifFalse:[ |
|
597 |
dist := lcSelector spellAgainst:lcSym. |
|
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
598 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
599 |
(lcSym startsWith:lcSelector) ifTrue:[ |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
600 |
dist := dist + (aString size * 10). |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
601 |
]. |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
602 |
|
1215 | 603 |
(dist > 20) ifTrue:[ |
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
604 |
(info contains:[:entry | entry key = sym]) ifFalse:[ |
1215 | 605 |
keepThis := true. |
606 |
info size >= nMax ifTrue:[ |
|
607 |
"will remove last entry anyway - so check if this one will remain ..." |
|
608 |
dist < info last value ifTrue:[ |
|
609 |
keepThis := false. |
|
610 |
] |
|
611 |
]. |
|
612 |
keepThis ifTrue:[ |
|
613 |
"expensive - therefore do this check at last" |
|
614 |
mthd isObsolete ifFalse:[ |
|
615 |
info add:(sym -> dist). |
|
616 |
info size > nMax ifTrue:[ |
|
617 |
info removeLast. |
|
618 |
] |
|
619 |
] |
|
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
620 |
] |
1187 | 621 |
] |
622 |
] |
|
623 |
] |
|
624 |
]. |
|
625 |
||
626 |
aClassOrNil isNil ifTrue:[ |
|
627 |
Smalltalk allClassesDo:[:cls | |
|
628 |
cls methodDictionary keysAndValuesDo:block. |
|
629 |
cls class methodDictionary keysAndValuesDo:block. |
|
630 |
] |
|
631 |
] ifFalse:[ |
|
632 |
aClassOrNil withAllSuperclassesDo:[:cls | |
|
633 |
cls methodDictionary keysAndValuesDo:block. |
|
1323 | 634 |
"/ cls class methodDictionary keysAndValuesDo:block. |
1187 | 635 |
] |
636 |
]. |
|
637 |
||
638 |
^ info asOrderedCollection collect:[:a | a key] |
|
639 |
||
640 |
"Modified: / 19.1.2000 / 16:43:37 / cg" |
|
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
641 |
! |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
642 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
643 |
findBestSelectorsFor:aString |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
644 |
"collect known selectors with their spelling distances to aString; |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
645 |
return the 10 best suggestions" |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
646 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
647 |
^ self findBestSelectorsFor:aString in:nil |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
648 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
649 |
" |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
650 |
Parser findBestSelectorsFor:'at' |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
651 |
Parser findBestSelectorsFor:'at:pu' |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
652 |
" |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
653 |
! |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
654 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
655 |
findBestSelectorsFor:aString in:aClassOrNil |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
656 |
"collect known selectors with their spelling distances to aString; |
1323 | 657 |
return the 15 best suggestions. If the argument, aClassOrNil is not nil, |
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
658 |
the message is assumed to be sent to instances of that class (i.e. offer |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
659 |
corrections from that hierarchy only)" |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
660 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
661 |
^ self |
1323 | 662 |
findBest:15 selectorsFor:aString in:aClassOrNil |
1187 | 663 |
! ! |
664 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
665 |
!Parser class methodsFor:'evaluating expressions'! |
0 | 666 |
|
19 | 667 |
evaluate:aStringOrStream |
71 | 668 |
"return the result of evaluating an expression in aStringOrStream. |
669 |
No doit-entry is added to the changeLog." |
|
0 | 670 |
|
19 | 671 |
^ self |
44 | 672 |
evaluate:aStringOrStream |
673 |
in:nil |
|
674 |
receiver:nil |
|
675 |
notifying:nil |
|
676 |
logged:false |
|
677 |
ifFail:nil |
|
71 | 678 |
compile:true |
19 | 679 |
|
680 |
" |
|
681 |
Compiler evaluate:'1 + 2' |
|
682 |
Compiler evaluate:'''hello world'' asSortedCollection displayString printNL' |
|
683 |
Compiler evaluate:'''hello world'' asSortedCollection printNL' |
|
684 |
" |
|
0 | 685 |
! |
686 |
||
71 | 687 |
evaluate:aStringOrStream compile:compile |
688 |
"return the result of evaluating aString, |
|
689 |
The compile argument specifies if the string should be compiled down to |
|
690 |
bytecode or instead be interpreted from the parseTree. |
|
691 |
The first should be done for doIts etc, where a readable walkback is |
|
692 |
required. |
|
693 |
The latter is better done for constants, styleSheet and resource |
|
694 |
reading and simple sends, where the overhead of compilation is bigger |
|
695 |
than the interpretation overhead." |
|
696 |
||
697 |
^ self |
|
698 |
evaluate:aStringOrStream |
|
699 |
in:nil |
|
700 |
receiver:nil |
|
701 |
notifying:nil |
|
702 |
logged:false |
|
703 |
ifFail:nil |
|
704 |
compile:compile |
|
705 |
! |
|
706 |
||
20 | 707 |
evaluate:aStringOrStream ifFail:failBlock |
708 |
"return the result of evaluating an expression in aStringOrStream. |
|
71 | 709 |
In case of any syntax errors, return the value of failBlock. |
710 |
No doit-entry is added to the changeLog." |
|
20 | 711 |
|
712 |
^ self |
|
44 | 713 |
evaluate:aStringOrStream |
714 |
in:nil |
|
715 |
receiver:nil |
|
716 |
notifying:nil |
|
717 |
logged:false |
|
718 |
ifFail:failBlock |
|
71 | 719 |
compile:true |
20 | 720 |
" |
721 |
Compiler evaluate:'1 +' ifFail:['oops'] |
|
722 |
" |
|
723 |
! |
|
724 |
||
71 | 725 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor ifFail:failBlock |
726 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
727 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
728 |
No doIt entry is added to the change-file. |
|
729 |
If the failBlock argument is non-nil, it is evaluated if an error occurs." |
|
730 |
||
731 |
^ self |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
732 |
evaluate:aStringOrStream |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
733 |
in:aContext |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
734 |
receiver:anObject |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
735 |
notifying:requestor |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
736 |
logged:false |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
737 |
ifFail:nil |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
738 |
compile:true |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
739 |
|
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
740 |
"Modified: / 17.1.1998 / 02:54:07 / cg" |
20 | 741 |
! |
742 |
||
743 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock |
|
744 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
745 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
746 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
747 |
is non-nil, it is evaluated if an error occurs." |
|
748 |
||
71 | 749 |
^ self |
750 |
evaluate:aStringOrStream |
|
751 |
in:aContext |
|
752 |
receiver:anObject |
|
753 |
notifying:requestor |
|
754 |
logged:logged |
|
755 |
ifFail:failBlock |
|
756 |
compile:true |
|
757 |
! |
|
758 |
||
759 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile |
|
760 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
761 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
762 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
763 |
is non-nil, it is evaluated if an error occurs. |
|
764 |
Finally, compile specifies if the string should be compiled down to |
|
765 |
bytecode or instead be interpreted from the parseTree. |
|
766 |
The first should be done for doIts etc, where a readable walkback is |
|
767 |
required. |
|
768 |
The latter is better done for constants, styleSheet and resource |
|
769 |
reading and simple sends, where the overhead of compilation is bigger |
|
770 |
than the interpretation overhead." |
|
771 |
||
1363 | 772 |
^ self new |
773 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile |
|
141 | 774 |
! |
775 |
||
776 |
evaluate:aStringOrStream logged:logged |
|
777 |
"return the result of evaluating an expression in aStringOrStream. |
|
778 |
The argument log controls if an entry is added to the changeLog." |
|
779 |
||
780 |
^ self |
|
781 |
evaluate:aStringOrStream |
|
782 |
in:nil |
|
783 |
receiver:nil |
|
784 |
notifying:nil |
|
785 |
logged:logged |
|
786 |
ifFail:nil |
|
787 |
compile:true |
|
788 |
" |
|
789 |
Compiler evaluate:'''some string''' logged:false |
|
790 |
Compiler evaluate:'''some string''' logged:true |
|
791 |
" |
|
792 |
! |
|
793 |
||
794 |
evaluate:aStringOrStream notifying:requestor |
|
795 |
"return the result of evaluating aString, |
|
796 |
errors are reported to requestor" |
|
797 |
||
798 |
^ self |
|
799 |
evaluate:aStringOrStream |
|
800 |
in:nil |
|
801 |
receiver:nil |
|
802 |
notifying:requestor |
|
803 |
logged:false |
|
804 |
ifFail:nil |
|
805 |
compile:true |
|
806 |
! |
|
807 |
||
808 |
evaluate:aStringOrStream notifying:requestor compile:compile |
|
809 |
"return the result of evaluating aString, |
|
810 |
errors are reported to requestor. |
|
811 |
The compile argument specifies if the string should be compiled down to |
|
812 |
bytecode or instead be interpreted from the parseTree. |
|
813 |
The first should be done for doIts etc, where a readable walkback is |
|
814 |
required. |
|
815 |
The latter is better done for constants, styleSheet and resource |
|
816 |
reading and simple sends, where the overhead of compilation is bigger |
|
817 |
than the interpretation overhead." |
|
818 |
||
819 |
^ self |
|
820 |
evaluate:aStringOrStream |
|
821 |
in:nil |
|
822 |
receiver:nil |
|
823 |
notifying:requestor |
|
824 |
logged:false |
|
825 |
ifFail:nil |
|
826 |
compile:compile |
|
827 |
! |
|
828 |
||
1025
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
829 |
evaluate:aStringOrStream notifying:requestor logged:logged |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
830 |
"return the result of evaluating aString, |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
831 |
errors are reported to requestor" |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
832 |
|
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
833 |
^ self |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
834 |
evaluate:aStringOrStream |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
835 |
in:nil |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
836 |
receiver:nil |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
837 |
notifying:requestor |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
838 |
logged:logged |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
839 |
ifFail:nil |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
840 |
compile:true |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
841 |
! |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
842 |
|
572 | 843 |
evaluate:aStringOrStream receiver:anObject |
844 |
"return the result of evaluating aString, |
|
845 |
errors are reported to requestor. Allow access to |
|
846 |
anObject as self and to its instVars " |
|
847 |
||
848 |
^ self |
|
619 | 849 |
evaluate:aStringOrStream |
850 |
in:nil |
|
851 |
receiver:anObject |
|
852 |
notifying:nil |
|
853 |
logged:false |
|
854 |
ifFail:nil |
|
855 |
compile:true |
|
572 | 856 |
|
857 |
" |
|
858 |
Compiler evaluate:'self x' receiver:(1 @ 2) |
|
859 |
" |
|
860 |
||
861 |
"Created: 1.7.1997 / 19:02:24 / cg" |
|
862 |
"Modified: 1.7.1997 / 19:02:33 / cg" |
|
863 |
! |
|
864 |
||
919 | 865 |
evaluate:aStringOrStream receiver:someOne logged:logged |
866 |
"return the result of evaluating an expression in aStringOrStream. |
|
867 |
The argument log controls if an entry is added to the changeLog." |
|
868 |
||
869 |
^ self |
|
870 |
evaluate:aStringOrStream |
|
871 |
in:nil |
|
872 |
receiver:someOne |
|
873 |
notifying:nil |
|
874 |
logged:logged |
|
875 |
ifFail:nil |
|
876 |
compile:true |
|
877 |
" |
|
878 |
Compiler evaluate:'''some string''' logged:false |
|
879 |
Compiler evaluate:'''some string''' logged:true |
|
880 |
Compiler evaluate:'self class' receiver:nil logged:false |
|
881 |
Compiler evaluate:'self class' receiver:1 logged:false |
|
882 |
" |
|
883 |
! |
|
884 |
||
141 | 885 |
evaluate:aStringOrStream receiver:anObject notifying:requestor |
886 |
"return the result of evaluating aString, |
|
887 |
errors are reported to requestor. Allow access to |
|
888 |
anObject as self and to its instVars (used in the inspector)" |
|
889 |
||
890 |
^ self |
|
891 |
evaluate:aStringOrStream |
|
892 |
in:nil |
|
893 |
receiver:anObject |
|
894 |
notifying:requestor |
|
895 |
logged:false |
|
896 |
ifFail:nil |
|
897 |
compile:true |
|
898 |
||
899 |
" |
|
900 |
Compiler evaluate:'self x' receiver:(1 @ 2) notifying:nil |
|
901 |
" |
|
902 |
! |
|
903 |
||
904 |
evaluate:aStringOrStream receiver:anObject notifying:requestor compile:compile |
|
905 |
"return the result of evaluating aString, |
|
906 |
errors are reported to requestor. Allow access to |
|
907 |
anObject as self and to its instVars (used in the inspector). |
|
908 |
The compile argument specifies if the string should be compiled down to |
|
909 |
bytecode or instead be interpreted from the parseTree. |
|
910 |
The first should be done for doIts etc, where a readable walkback is |
|
911 |
required. |
|
912 |
The latter is better done for constants, styleSheet and resource |
|
913 |
reading and simple sends, where the overhead of compilation is bigger |
|
914 |
than the interpretation overhead." |
|
915 |
||
916 |
^ self |
|
917 |
evaluate:aStringOrStream |
|
918 |
in:nil |
|
919 |
receiver:anObject |
|
920 |
notifying:requestor |
|
921 |
logged:false |
|
922 |
ifFail:nil |
|
923 |
compile:compile |
|
0 | 924 |
! ! |
925 |
||
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
926 |
!Parser class methodsFor:'general helpers'! |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
927 |
|
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
928 |
argAndVarNamesForContext:aContext |
1446
ac887ee4881a
** changed access to blockContexts source, args and vars -- please watch out
penk
parents:
1445
diff
changeset
|
929 |
self obsoleteMethodWarning. |
ac887ee4881a
** changed access to blockContexts source, args and vars -- please watch out
penk
parents:
1445
diff
changeset
|
930 |
^ aContext argAndVarNames. |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
931 |
! ! |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
932 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
933 |
!Parser class methodsFor:'parsing'! |
141 | 934 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
935 |
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
|
936 |
"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
|
937 |
return the containing BlockNode or nil. |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
938 |
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
|
939 |
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
|
940 |
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
|
941 |
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
|
942 |
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
|
943 |
|
429 | 944 |
|compiler tree mSource who mClass blocks |
397 | 945 |
maxSoFar innerBlock m| |
946 |
||
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
947 |
(line isNil or:[line == self maxLineNumber]) ifTrue:[ |
815 | 948 |
^ nil |
457
ad25339043ef
care for nil-lineNumber when looking for a block
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
949 |
]. |
ad25339043ef
care for nil-lineNumber when looking for a block
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
950 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
951 |
aMethod notNil ifTrue:[ |
815 | 952 |
m := aMethod. |
953 |
who := m who. |
|
954 |
who isNil ifTrue:[ |
|
955 |
m isWrapped ifTrue:[ |
|
956 |
m := m wrapper. |
|
957 |
m notNil ifTrue:[ |
|
958 |
who := m who. |
|
959 |
] |
|
960 |
] |
|
961 |
]. |
|
962 |
who notNil ifTrue:[ |
|
963 |
mClass := who methodClass. |
|
964 |
mClass isNil ifTrue:[ ^ nil]. |
|
965 |
]. |
|
966 |
||
967 |
mSource := m source. |
|
968 |
mSource isNil ifTrue:[^ nil]. |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
969 |
] ifFalse:[ |
815 | 970 |
aString notNil ifTrue:[ |
971 |
mSource := aString. |
|
972 |
mClass := UndefinedObject |
|
973 |
] ifFalse:[ |
|
974 |
^ nil |
|
975 |
] |
|
397 | 976 |
]. |
977 |
||
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
978 |
"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
|
979 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
980 |
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
|
981 |
compiler parseForCode. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
982 |
compiler notifying:nil. |
1365 | 983 |
compiler ignoreWarnings:true. |
984 |
compiler ignoreErrors:true. |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
985 |
compiler lineNumberInfo:#full. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
986 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
987 |
aMethod notNil ifTrue:[ |
815 | 988 |
(compiler parseMethodSpec == #Error) ifTrue:[ |
989 |
^ nil. |
|
990 |
]. |
|
991 |
||
992 |
who notNil ifTrue:[ |
|
993 |
compiler selector ~~ (who methodSelector) ifTrue:[ |
|
994 |
^ nil |
|
995 |
] |
|
996 |
]. |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
997 |
] ifFalse:[ |
815 | 998 |
compiler nextToken. |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
999 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1000 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1001 |
tree := compiler parseMethodBody. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1002 |
|
815 | 1003 |
(compiler errorFlag |
1004 |
or:[tree == #Error |
|
1005 |
or:[tree isNil]]) ifTrue:[ |
|
1006 |
^ nil |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1007 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1008 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1009 |
blocks := OrderedCollection new. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1010 |
tree collectBlocksInto:blocks. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1011 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1012 |
blocks := blocks select:[:aBlock | |
815 | 1013 |
line between: aBlock lineNumber and:aBlock endLineNumber |
1014 |
||
1015 |
]. |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1016 |
blocks size == 1 ifTrue:[ |
815 | 1017 |
^ 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
|
1018 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1019 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1020 |
nA notNil ifTrue:[ |
815 | 1021 |
blocks := blocks select:[:aBlock | |
1022 |
aBlock numArgs == nA |
|
1023 |
]. |
|
1024 |
blocks size == 1 ifTrue:[ |
|
1025 |
^ blocks at:1 |
|
1026 |
]. |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1027 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1028 |
nV notNil ifTrue:[ |
815 | 1029 |
blocks := blocks select:[:aBlock | |
1030 |
aBlock numVars == nV |
|
1031 |
]. |
|
1032 |
blocks size == 1 ifTrue:[ |
|
1033 |
^ blocks at:1 |
|
1034 |
]. |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1035 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1036 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1037 |
"/ 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
|
1038 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1039 |
maxSoFar := 0. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1040 |
blocks do:[:aBlock | |
815 | 1041 |
aBlock lineNumber > maxSoFar ifTrue:[ |
1042 |
innerBlock := aBlock. |
|
1043 |
maxSoFar := aBlock lineNumber |
|
1044 |
] |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1045 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1046 |
^ innerBlock. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1047 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1048 |
"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
|
1049 |
"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
|
1050 |
! |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1051 |
|
1365 | 1052 |
checkMethod:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
629 | 1053 |
"parse a method in a given class. |
1054 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1055 |
The parser can be queried for selector, receiver, args, locals, |
|
1056 |
used selectors, modified instvars, referenced classvars etc. |
|
1057 |
The noErrors and noWarnings arguments specify if error and warning |
|
1058 |
messages should be sent to the Transcript or suppressed." |
|
1059 |
||
1060 |
|parser tree| |
|
1061 |
||
1062 |
aString isNil ifTrue:[^ nil]. |
|
1063 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1365 | 1064 |
parser ignoreErrors:ignoreErrors. |
1065 |
parser ignoreWarnings:ignoreWarnings. |
|
629 | 1066 |
tree := parser parseMethod. |
1067 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ nil]. |
|
1068 |
||
1069 |
ReadBeforeWrittenTester searchForReadBeforeWrittenIn:tree |
|
1070 |
||
1071 |
" |
|
1072 |
self |
|
1073 |
checkMethod:'foo |
|
1074 |
|local1 local2 local3| |
|
1075 |
||
1076 |
local1 := local2. |
|
1077 |
^ local3 |
|
1078 |
' |
|
1079 |
in:UndefinedObject |
|
1080 |
ignoreErrors:true |
|
1081 |
ignoreWarnings:true |
|
1082 |
" |
|
1083 |
||
1084 |
"Modified: / 30.10.1997 / 16:38:31 / cg" |
|
1085 |
! |
|
1086 |
||
141 | 1087 |
parseExpression:aString |
1088 |
"parse aString as an expression; |
|
1089 |
Return the parseTree (if ok), nil (for an empty string |
|
258 | 1090 |
or comment only) or #Error (syntactic error). |
1091 |
Error and warning messages are suppressed." |
|
141 | 1092 |
|
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1093 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1094 |
withSelf:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1095 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1096 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1097 |
notifying:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1098 |
ignoreErrors:true "silence on Transcript" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1099 |
ignoreWarnings:true |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1100 |
inNameSpace:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1101 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1102 |
" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1103 |
Parser parseExpression:'self foo' |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1104 |
Parser parseExpression:'self:123' |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1105 |
Parser parseExpression:'self:123' onError:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1106 |
" |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1107 |
! |
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1108 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1109 |
parseExpression:aString inNameSpace:aNameSpaceOrNil |
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1110 |
"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
|
1111 |
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
|
1112 |
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
|
1113 |
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
|
1114 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1115 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1116 |
withSelf:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1117 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1118 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1119 |
notifying:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1120 |
ignoreErrors:true "silence on Transcript" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1121 |
ignoreWarnings:true |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1122 |
inNameSpace:aNameSpaceOrNil |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1123 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1124 |
"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
|
1125 |
"Created: 24.6.1997 / 16:44:26 / cg" |
141 | 1126 |
! |
1127 |
||
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1128 |
parseExpression:aString inNameSpace:aNameSpaceOrNil onError:errorValue |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1129 |
"parse aString as an expression; |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1130 |
Return the parseTree (if ok), nil (for an empty string |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1131 |
or comment only) or errorValue (syntactic error). |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1132 |
Error and warning messages are suppressed." |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1133 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1134 |
^ self |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1135 |
withSelf:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1136 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1137 |
onError:errorValue |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1138 |
notifying:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1139 |
ignoreErrors:true "silence on Transcript" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1140 |
ignoreWarnings:true |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1141 |
inNameSpace:aNameSpaceOrNil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1142 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1143 |
"Modified: 24.6.1997 / 16:44:00 / cg" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1144 |
"Created: 24.6.1997 / 16:44:26 / cg" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1145 |
! |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1146 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1147 |
parseExpression:aString onError:errorValue |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1148 |
"parse aString as an expression; |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1149 |
Return the parseTree (if ok), nil (for an empty string |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1150 |
or comment only) or errorValue (syntactic error). |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1151 |
Error and warning messages are suppressed." |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1152 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1153 |
^ self |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1154 |
withSelf:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1155 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1156 |
onError:errorValue |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1157 |
notifying:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1158 |
ignoreErrors:true "silence on Transcript" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1159 |
ignoreWarnings:true |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1160 |
inNameSpace:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1161 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1162 |
"Modified: 24.6.1997 / 16:44:00 / cg" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1163 |
! |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1164 |
|
141 | 1165 |
parseMethod:aString |
1166 |
"parse a method. |
|
1167 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1168 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 1169 |
used selectors etc. |
1170 |
Error and warning messages are sent to the Transcript." |
|
141 | 1171 |
|
1172 |
^ self parseMethod:aString in:nil |
|
1173 |
||
1174 |
" |
|
1175 |
|p| |
|
1176 |
||
1177 |
p := Parser |
|
619 | 1178 |
parseMethod:' |
1179 |
foo:arg1 bar:arg2 baz:arg3 |
|
1180 |
|l1 l2| |
|
1181 |
l1 := 0. |
|
1182 |
l2 := arg1. |
|
1183 |
^ self'. |
|
141 | 1184 |
|
1185 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
1186 |
'args: ' print. p methodArgs printNL. |
|
1187 |
'sel: ' print. p selector printNL. |
|
1188 |
'nLocal: ' print. p numberOfMethodVars printNL. |
|
1189 |
'locals: ' print. p methodVars printNL. |
|
1190 |
'tree: ' printNL. p tree printAllOn:Stdout. Stdout cr. |
|
1191 |
" |
|
258 | 1192 |
|
1193 |
"Modified: 24.4.1996 / 13:18:02 / cg" |
|
141 | 1194 |
! |
1195 |
||
1196 |
parseMethod:aString in:aClass |
|
1197 |
"parse a method in a given class. |
|
1198 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1199 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 1200 |
used selectors, modified instvars, referenced classvars etc. |
1201 |
Error and warning messages are sent to the Transcript." |
|
141 | 1202 |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1203 |
^ self |
619 | 1204 |
parseMethod:aString |
1205 |
in:aClass |
|
1206 |
ignoreErrors:false |
|
1207 |
ignoreWarnings:false |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1208 |
|
258 | 1209 |
"Modified: 24.4.1996 / 13:18:34 / cg" |
141 | 1210 |
! |
1211 |
||
1365 | 1212 |
parseMethod:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
141 | 1213 |
"parse a method in a given class. |
1214 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1215 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 1216 |
used selectors, modified instvars, referenced classvars etc. |
1217 |
The noErrors and noWarnings arguments specify if error and warning |
|
1218 |
messages should be sent to the Transcript or suppressed." |
|
141 | 1219 |
|
1220 |
|parser tree| |
|
1221 |
||
1222 |
aString isNil ifTrue:[^ nil]. |
|
1223 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1365 | 1224 |
parser ignoreErrors:ignoreErrors. |
1225 |
parser ignoreWarnings:ignoreWarnings. |
|
141 | 1226 |
tree := parser parseMethod. |
1227 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ nil]. |
|
1228 |
^ parser |
|
258 | 1229 |
|
1230 |
"Modified: 24.4.1996 / 13:19:23 / cg" |
|
141 | 1231 |
! |
1232 |
||
1233 |
parseMethod:aString in:aClass warnings:warnBoolean |
|
1234 |
"parse a method in a given class. |
|
1235 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1236 |
The parser can be queried for selector, receiver, args, locals, |
|
1237 |
used selectors, modified instvars, referenced classvars etc. |
|
258 | 1238 |
The warnBoolean arguments specifies if warning |
1239 |
messages should be sent to the Transcript or suppressed. |
|
1240 |
||
1241 |
This method is OBSOLETE, and left in for backward compatibility." |
|
1242 |
||
1243 |
self obsoleteMethodWarning. |
|
141 | 1244 |
^ self |
619 | 1245 |
parseMethod:aString |
1246 |
in:aClass |
|
1247 |
ignoreErrors:false |
|
1248 |
ignoreWarnings:warnBoolean not |
|
258 | 1249 |
|
1250 |
"Modified: 24.4.1996 / 13:28:05 / cg" |
|
141 | 1251 |
! |
1252 |
||
1253 |
parseMethodArgAndVarSpecification:aString |
|
1254 |
"parse a methods selector, arg and var spec (i.e. locals); |
|
1255 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
258 | 1256 |
The parser can be queried for selector, receiver etc. |
1257 |
Error and warning messages are sent to the Transcript. |
|
1258 |
This method is OBSOLETE." |
|
1259 |
||
1260 |
self obsoleteMethodWarning. |
|
141 | 1261 |
^ self parseMethodArgAndVarSpecification:aString in:nil |
1262 |
||
1263 |
" |
|
1264 |
|p| |
|
1265 |
||
1266 |
p := Parser |
|
619 | 1267 |
parseMethodArgAndVarSpecification:' |
1268 |
foo:arg1 bar:arg2 baz:arg3 |
|
1269 |
|l1 l2|'. |
|
141 | 1270 |
|
1271 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
1272 |
'args: ' print. p methodArgs printNL. |
|
1273 |
'sel: ' print. p selector printNL. |
|
1274 |
'nLocal: ' print. p numberOfMethodVars printNL. |
|
1275 |
'locals: ' print. p methodVars printNL. |
|
1276 |
" |
|
258 | 1277 |
|
1278 |
"Modified: 24.4.1996 / 13:29:43 / cg" |
|
141 | 1279 |
! |
1280 |
||
1281 |
parseMethodArgAndVarSpecification:aString in:aClass |
|
1282 |
"parse a methods selector, arg and var spec in a given class; |
|
1283 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
258 | 1284 |
The parser can be queried for selector, receiver, args and locals. |
1285 |
Error and warning messages are sent to the Transcript. |
|
1286 |
This method is OBSOLETE." |
|
1287 |
||
1288 |
self obsoleteMethodWarning. |
|
141 | 1289 |
^ self parseMethodArgAndVarSpecification:aString |
619 | 1290 |
in:aClass |
1291 |
ignoreErrors:false |
|
1292 |
ignoreWarnings:false |
|
1293 |
parseBody:false |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1294 |
|
258 | 1295 |
"Modified: 24.4.1996 / 13:30:03 / cg" |
141 | 1296 |
! |
1297 |
||
1365 | 1298 |
parseMethodArgAndVarSpecification:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings parseBody:body |
141 | 1299 |
"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
|
1300 |
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
|
1301 |
(for primitives & resourceSpecs). |
258 | 1302 |
The noErrors and noWarnings arguments specify if error and warning |
1303 |
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
|
1304 |
|
141 | 1305 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
1306 |
The parser can be queried for selector, receiver, args and locals" |
|
19 | 1307 |
|
0 | 1308 |
|parser| |
1309 |
||
141 | 1310 |
aString isNil ifTrue:[^ nil]. |
1311 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1365 | 1312 |
parser ignoreErrors:ignoreErrors. |
1313 |
parser ignoreWarnings:ignoreWarnings. |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1314 |
"/ parser nextToken. |
141 | 1315 |
(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
|
1316 |
"/ |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1317 |
"/ used to be #parseMethodBodyVarSpec |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1318 |
"/ - 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
|
1319 |
"/ |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1320 |
body ifTrue:[ |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
1321 |
parser parseMethodBodyOrEmpty |
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1322 |
] ifFalse:[ |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
1323 |
parser parseMethodBodyVarSpec |
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1324 |
]. |
141 | 1325 |
parser errorFlag ifTrue:[^ nil]. |
0 | 1326 |
^ parser |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1327 |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1328 |
"Created: 24.4.1996 / 13:13:06 / cg" |
265 | 1329 |
"Modified: 27.4.1996 / 16:58:02 / cg" |
141 | 1330 |
! |
1331 |
||
1332 |
parseMethodArgAndVarSpecificationSilent:aString |
|
1333 |
"parse a methods selector, arg and var spec (i.e. locals); |
|
1334 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1335 |
The parser can be queried for selector, receiver etc. |
|
258 | 1336 |
Like #parseMethodArgAndVarSpecification:, but does NOT |
141 | 1337 |
display error/warning messages on the transcript." |
1338 |
||
1339 |
^ self parseMethodArgAndVarSpecificationSilent:aString in:nil |
|
258 | 1340 |
|
1341 |
"Modified: 24.4.1996 / 13:30:54 / cg" |
|
141 | 1342 |
! |
1343 |
||
1344 |
parseMethodArgAndVarSpecificationSilent:aString in:aClass |
|
1345 |
"parse a methods selector, arg and var spec in a given class; |
|
1346 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1347 |
The parser can be queried for selector, receiver, args and locals. |
|
1348 |
Like #parseMethodArgAndVarSpecification:in:, but does not |
|
1349 |
display error/warning messages on the transcript." |
|
1350 |
||
1351 |
^ self parseMethodArgAndVarSpecification:aString |
|
619 | 1352 |
in:aClass |
1353 |
ignoreErrors:true |
|
1354 |
ignoreWarnings:true |
|
1355 |
parseBody:false |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1356 |
|
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1357 |
"Modified: 24.4.1996 / 13:14:27 / cg" |
141 | 1358 |
! |
1359 |
||
1360 |
parseMethodSilent:aString |
|
1361 |
"parse a method. |
|
1362 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1363 |
The parser can be queried for selector, receiver, args, locals, |
|
1364 |
used selectors etc. |
|
258 | 1365 |
Like #parseMethod:, but warning/error messages are suppressed." |
141 | 1366 |
|
1367 |
^ self parseMethodSilent:aString in:nil |
|
258 | 1368 |
|
1369 |
"Modified: 24.4.1996 / 13:32:44 / cg" |
|
141 | 1370 |
! |
1371 |
||
1372 |
parseMethodSilent:aString in:aClass |
|
1373 |
"parse a method in a given class. |
|
1374 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1375 |
The parser can be queried for selector, receiver, args, locals, |
|
1376 |
used selectors, modified instvars, referenced classvars etc. |
|
258 | 1377 |
Like #parseMethod:in:, but warning/error messages are suppressed." |
1378 |
||
1379 |
^ self |
|
619 | 1380 |
parseMethod:aString |
1381 |
in:aClass |
|
1382 |
ignoreErrors:true |
|
1383 |
ignoreWarnings:true |
|
258 | 1384 |
|
1385 |
"Modified: 24.4.1996 / 13:32:57 / cg" |
|
141 | 1386 |
! |
1387 |
||
1388 |
parseMethodSpecification:aString |
|
1389 |
"parse a methods selector & arg specification; |
|
1390 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1391 |
The parser can be queried for selector, receiver etc." |
|
1392 |
||
1393 |
^ self parseMethodSpecification:aString in:nil |
|
1394 |
||
1395 |
" |
|
1396 |
|p| |
|
1397 |
||
1398 |
p := Parser parseMethodSpecification:'foo:arg1 bar:arg2 baz:arg3'. |
|
1399 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
1400 |
'args: ' print. p methodArgs printNL. |
|
1401 |
'sel: ' print. p selector printNL |
|
1402 |
" |
|
1403 |
! |
|
1404 |
||
1405 |
parseMethodSpecification:aString in:aClass |
|
1406 |
"parse a methods selector & arg spec for a given class; |
|
1407 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1408 |
The parser can be queried for selector, receiver etc." |
|
1409 |
||
1410 |
^ self parseMethodSpecification:aString |
|
1411 |
in:aClass |
|
1412 |
ignoreErrors:false |
|
1413 |
ignoreWarnings:false |
|
1414 |
! |
|
1415 |
||
1365 | 1416 |
parseMethodSpecification:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
141 | 1417 |
"parse a methods selector & arg spec for a given class; |
1418 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1419 |
The parser can be queried for selector, receiver etc. |
|
1420 |
noErrors and noWarnings specify if error- and warningMessages are |
|
1421 |
to be output onto the Transcript." |
|
1422 |
||
1423 |
|parser tree| |
|
1424 |
||
1425 |
aString isNil ifTrue:[^ nil]. |
|
1426 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1365 | 1427 |
parser ignoreErrors:ignoreErrors. |
1428 |
parser ignoreWarnings:ignoreWarnings. |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1429 |
"/ parser nextToken. |
141 | 1430 |
tree := parser parseMethodSpec. |
1431 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ #Error]. |
|
1432 |
^ parser |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1433 |
|
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1434 |
"Modified: 20.4.1996 / 20:09:48 / cg" |
141 | 1435 |
! |
1436 |
||
1437 |
parseMethodSpecificationSilent:aString |
|
1438 |
"parse a methods selector & arg specification; |
|
1439 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1440 |
The parser can be queried for selector, receiver etc. |
|
1441 |
Like #parseMethodSpecification:, but does not display any error/warning Messages on the transcript." |
|
1442 |
||
1443 |
^ self parseMethodSpecificationSilent:aString in:nil |
|
1444 |
! |
|
1445 |
||
1446 |
parseMethodSpecificationSilent:aString in:aClass |
|
1447 |
"parse a methods selector & arg spec for a given class; |
|
1448 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1449 |
The parser can be queried for selector, receiver etc. |
|
1450 |
Like #parseMethodSpecification:in:, but does not display any error/warning Messages on the transcript." |
|
1451 |
||
1452 |
^ self parseMethodSpecification:aString |
|
1453 |
in:aClass |
|
1454 |
ignoreErrors:true |
|
1455 |
ignoreWarnings:true |
|
1456 |
||
1457 |
"Created: 31.10.1995 / 14:37:49 / cg" |
|
1458 |
! |
|
0 | 1459 |
|
7 | 1460 |
selectorInExpression:aString |
47 | 1461 |
"parse an expression - return the selector. Even malformed expressions |
1462 |
(such as missing receiver or missing arg are parsed. |
|
1463 |
Used for the SystemBrowsers implementors/senders query-box initial text. |
|
21 | 1464 |
Returns nil if unparsable." |
7 | 1465 |
|
1297
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1466 |
|tree parser sel| |
7 | 1467 |
|
813
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1468 |
(aString size == 0) ifTrue:[^ nil]. |
7 | 1469 |
|
1297
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1470 |
Error |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1471 |
handle:[:ex | ] |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1472 |
do:[ |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1473 |
tree := self withSelf:nil |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1474 |
parseExpression:aString |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1475 |
notifying:nil |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1476 |
ignoreErrors:true |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1477 |
ignoreWarnings:true. |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1478 |
]. |
21 | 1479 |
|
1480 |
" |
|
1481 |
special: take the expression of the right side, if its an |
|
1482 |
assignment or return |
|
1483 |
" |
|
7 | 1484 |
(tree notNil and:[tree ~~ #Error]) ifTrue:[ |
813
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1485 |
(tree isAssignment |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1486 |
or:[tree isReturnNode]) ifTrue:[ |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1487 |
tree expression isMessage ifTrue:[ |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1488 |
tree := tree expression |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1489 |
] |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1490 |
]. |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1491 |
|
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1492 |
tree isMessage ifTrue:[ |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1493 |
^ tree selector |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1494 |
]. |
7 | 1495 |
]. |
1496 |
||
21 | 1497 |
" |
1498 |
mhmh, try expression without receiver |
|
1499 |
" |
|
7 | 1500 |
parser := self for:(ReadStream on:aString). |
1365 | 1501 |
parser ignoreErrors:true. |
1297
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1502 |
Error |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1503 |
handle:[:ex | ] |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1504 |
do:[ |
1482
d80c83f1167a
catch twoByte string parsing in selectorInExpression
Claus Gittinger <cg@exept.de>
parents:
1471
diff
changeset
|
1505 |
parser nextToken. |
1297
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1506 |
sel := parser degeneratedKeywordExpressionForSelector |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1507 |
]. |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1508 |
^ sel |
7 | 1509 |
|
1510 |
" |
|
20 | 1511 |
Parser selectorInExpression:'foo at:1 put:(5 * bar)' |
1512 |
Parser selectorInExpression:'(foo at:1) at:1' |
|
47 | 1513 |
Parser selectorInExpression:'a + 4' |
1514 |
Parser selectorInExpression:'a negated' |
|
20 | 1515 |
Parser selectorInExpression:'at:1 put:5' |
47 | 1516 |
Parser selectorInExpression:'at:1 put:' |
1517 |
Parser selectorInExpression:'a at:1 put:5' |
|
1518 |
Parser selectorInExpression:'a at:1 put:' |
|
20 | 1519 |
Parser selectorInExpression:'a := foo at:1 put:5' |
7 | 1520 |
" |
451 | 1521 |
|
1522 |
"Modified: 17.12.1996 / 12:12:47 / cg" |
|
7 | 1523 |
! |
1524 |
||
1525 |
withSelf:anObject parseExpression:aString notifying:someOne |
|
1526 |
"parse aString as an expression with self set to anObject; |
|
21 | 1527 |
Return the parseTree (if ok), nil (for an empty string |
1528 |
or comment only ) or #Error (syntactic error). |
|
1529 |
||
1530 |
Errors and warnings are forwarded to someOne (usually some |
|
1531 |
codeView) which can highlight it and show a popup box." |
|
7 | 1532 |
|
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1533 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1534 |
withSelf:anObject |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1535 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1536 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1537 |
notifying:someOne |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1538 |
ignoreErrors:false |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1539 |
ignoreWarnings:false |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1540 |
inNameSpace:nil |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1541 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1542 |
"Modified: 24.6.1997 / 16:43:37 / cg" |
7 | 1543 |
! |
1544 |
||
1545 |
withSelf:anObject parseExpression:aString notifying:someOne ignoreErrors:ignore |
|
0 | 1546 |
"parse aString as an expression with self set to anObject; |
21 | 1547 |
Return the parseTree (if ok), nil (for an empty string |
1548 |
or comment only ) or #Error (syntactic error). |
|
1549 |
||
1550 |
Errors and warnings are forwarded to someOne (usually some |
|
1551 |
codeView) which can highlight it and show a popup box." |
|
1552 |
||
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1553 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1554 |
withSelf:anObject |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1555 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1556 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1557 |
notifying:someOne |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1558 |
ignoreErrors:ignore |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1559 |
ignoreWarnings:ignore |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1560 |
inNameSpace:nil |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1561 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1562 |
"Modified: 24.6.1997 / 16:43:26 / cg" |
21 | 1563 |
! |
1564 |
||
1565 |
withSelf:anObject parseExpression:aString notifying:someOne ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
|
1566 |
"parse aString as an expression with self set to anObject; |
|
1567 |
Return the parseTree (if ok), nil (for an empty string |
|
1568 |
or comment only ) or #Error (syntactic error). |
|
1569 |
||
1570 |
Errors and warnings are forwarded to someOne (usually some |
|
1571 |
codeView) which can highlight it and show a popup box, |
|
1572 |
iff ignoreErrors/ignoreWarnings is true respectively." |
|
0 | 1573 |
|
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1574 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1575 |
withSelf:anObject |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1576 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1577 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1578 |
notifying:someOne |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1579 |
ignoreErrors:ignoreErrors |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1580 |
ignoreWarnings:ignoreWarnings |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1581 |
inNameSpace:nil |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1582 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1583 |
"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
|
1584 |
! |
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1585 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1586 |
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
|
1587 |
"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
|
1588 |
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
|
1589 |
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
|
1590 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1591 |
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
|
1592 |
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
|
1593 |
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
|
1594 |
|
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1595 |
^ self |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1596 |
withSelf:anObject |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1597 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1598 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1599 |
notifying:someOne |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1600 |
ignoreErrors:ignoreErrors |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1601 |
ignoreWarnings:ignoreWarnings |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1602 |
inNameSpace:aNameSpaceOrNil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1603 |
! |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1604 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1605 |
withSelf:anObject parseExpression:aString onError:errorValue notifying:someOne ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings inNameSpace:aNameSpaceOrNil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1606 |
"parse aString as an expression with self set to anObject; |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1607 |
Return the parseTree (if ok), nil (for an empty string |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1608 |
or comment only ) or errorValue (syntactic error). |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1609 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1610 |
Errors and warnings are forwarded to someOne (usually some |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1611 |
codeView) which can highlight it and show a popup box, |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1612 |
iff ignoreErrors/ignoreWarnings is true respectively." |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1613 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1614 |
|parser tree| |
0 | 1615 |
|
1616 |
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
|
1617 |
|
0 | 1618 |
parser := self for:(ReadStream on:aString). |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1619 |
tree := parser |
1006 | 1620 |
parseExpressionWithSelf:anObject |
1621 |
notifying:someOne |
|
1622 |
ignoreErrors:ignoreErrors |
|
1623 |
ignoreWarnings:ignoreWarnings |
|
1624 |
inNameSpace:aNameSpaceOrNil. |
|
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1625 |
tree == #Error ifTrue:[ |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1626 |
^ errorValue value |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1627 |
]. |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1628 |
^ tree |
1006 | 1629 |
|
1630 |
"Modified: / 14.12.1999 / 15:12:16 / cg" |
|
0 | 1631 |
! ! |
1632 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
1633 |
!Parser class methodsFor:'unparsing'! |
20 | 1634 |
|
1635 |
methodSpecificationForSelector:aSelector |
|
1636 |
"given a selector such as #foo:bar:, return a string that could |
|
1637 |
serve as a methods specification source code. |
|
1638 |
To be used for code generators" |
|
1639 |
||
807 | 1640 |
|argNames n| |
1641 |
||
1642 |
n := aSelector numArgs. |
|
1643 |
n == 1 ifTrue:[ |
|
1644 |
argNames := #('arg') |
|
1645 |
] ifFalse:[ |
|
1646 |
n <= 15 ifTrue:[ |
|
1647 |
argNames := #('arg1' 'arg2' 'arg3' 'arg4' 'arg5' 'arg6' |
|
1648 |
'arg7' 'arg8' 'arg9' 'arg10' 'arg11' 'arg12' |
|
1649 |
'arg13' 'arg14' 'arg15') |
|
1650 |
] ifFalse:[ |
|
1651 |
argNames := (1 to:aSelector numArgs) collect:[:i | 'arg' , i printString]. |
|
1652 |
]. |
|
1653 |
]. |
|
1654 |
^ self methodSpecificationForSelector:aSelector argNames:argNames |
|
1655 |
||
20 | 1656 |
" |
807 | 1657 |
Parser methodSpecificationForSelector:#foo: |
20 | 1658 |
Parser methodSpecificationForSelector:#foo:bar: |
807 | 1659 |
Parser methodSpecificationForSelector:#foo:bar:baz: |
21 | 1660 |
Parser methodSpecificationForSelector:#+ |
20 | 1661 |
Parser methodSpecificationForSelector:#negated |
1662 |
" |
|
807 | 1663 |
|
1664 |
"Modified: / 12.2.1999 / 13:12:44 / cg" |
|
20 | 1665 |
! |
1666 |
||
1667 |
methodSpecificationForSelector:aSelector argNames:argNames |
|
1668 |
"given a selector such as #foo:bar:, return a string that could |
|
1669 |
serve as a methods specification source code. |
|
1670 |
To be used for code generators" |
|
1671 |
||
806 | 1672 |
|s nargs parts part| |
20 | 1673 |
|
1674 |
s := WriteStream on:String new. |
|
44 | 1675 |
nargs := aSelector numArgs. |
20 | 1676 |
nargs == 0 ifTrue:[ |
806 | 1677 |
s nextPutAll:aSelector |
20 | 1678 |
] ifFalse:[ |
806 | 1679 |
parts := aSelector partsIfSelector. |
1680 |
1 to:nargs do:[:i | |
|
1681 |
part := parts at:i. |
|
1682 |
s nextPutAll:part. |
|
1683 |
(part endsWith:$:) ifFalse:[ |
|
1684 |
s space. |
|
1685 |
]. |
|
1686 |
s nextPutAll:(argNames at:i). |
|
1687 |
i ~~ nargs ifTrue:[s space]. |
|
1688 |
] |
|
20 | 1689 |
]. |
1690 |
^ s contents |
|
1691 |
||
1692 |
" |
|
1693 |
Parser methodSpecificationForSelector:#foo:bar: argNames:#('one' 'two' 'three') |
|
1694 |
Parser methodSpecificationForSelector:#+ argNames:#('one') |
|
1695 |
Parser methodSpecificationForSelector:#negated |
|
1696 |
" |
|
806 | 1697 |
|
1698 |
"Modified: / 12.2.1999 / 12:33:50 / cg" |
|
20 | 1699 |
! ! |
1700 |
||
1417 | 1701 |
!Parser methodsFor:'Compatibility-ST80'! |
0 | 1702 |
|
918 | 1703 |
evaluate:aString in:aClassOrContext to:to notifying:aRequestor ifFail:failBlock |
35 | 1704 |
|parseTree value| |
0 | 1705 |
|
1706 |
aString isNil ifTrue:[^ nil]. |
|
1707 |
self initializeFor:(ReadStream on:aString). |
|
918 | 1708 |
|
1709 |
"/ stupid - there seem to be differences among the various |
|
1710 |
"/ ST dialects ... |
|
1711 |
aClassOrContext isBehavior ifTrue:[ |
|
1712 |
self setClassToCompileFor:aClassOrContext. |
|
1713 |
selfValue := nil. |
|
1714 |
] ifFalse:[ |
|
1715 |
self setContext:aClassOrContext. |
|
1716 |
aClassOrContext notNil ifTrue:[ |
|
1717 |
self setSelf:(aClassOrContext receiver) |
|
1718 |
]. |
|
1719 |
]. |
|
0 | 1720 |
requestor := aRequestor. |
1721 |
||
1722 |
self nextToken. |
|
1723 |
parseTree := self parseMethodBody. |
|
1724 |
(errorFlag or:[tree == #Error]) ifTrue:[^ #Error]. |
|
1725 |
parseTree notNil ifTrue:[ |
|
918 | 1726 |
self evalExitBlock:[:value | ^ failBlock value]. |
1727 |
value := parseTree evaluate |
|
0 | 1728 |
]. |
35 | 1729 |
self release. |
1730 |
^ value |
|
547
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1731 |
! |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1732 |
|
624 | 1733 |
parse:methodSource in:aClass notifying:aRequestor |
1734 |
"parse a methods source. |
|
1735 |
Return the methods parseTree" |
|
1736 |
||
1737 |
self initializeFor:methodSource. |
|
1738 |
classToCompileFor := aClass. |
|
1739 |
requestor := aRequestor. |
|
1740 |
self parseMethod. |
|
918 | 1741 |
|
624 | 1742 |
^ MethodNode new |
1743 |
selector:selector |
|
1744 |
arguments:methodArgs |
|
1745 |
locals:methodVars |
|
1207 | 1746 |
statements:tree asCollectionOfStatements |
624 | 1747 |
|
1214 | 1748 |
"Created: / 17.10.1997 / 12:35:01 / cg" |
1749 |
"Modified: / 5.11.2001 / 16:56:43 / cg" |
|
624 | 1750 |
! |
1751 |
||
547
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1752 |
parseSelector:aStringOrStream |
624 | 1753 |
"parse a methods source for the methods selector. |
1754 |
Return the selector" |
|
1755 |
||
547
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1756 |
self initializeFor:aStringOrStream. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1757 |
self parseMethodSpec. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1758 |
^ selector. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1759 |
|
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1760 |
" |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1761 |
Parser new |
624 | 1762 |
parseSelector:' |
547
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1763 |
parseSelector:aStringOrStream |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1764 |
self initializeFor:aStringOrStream. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1765 |
self parseMethodSpec. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1766 |
^ selector. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1767 |
' |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1768 |
" |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1769 |
|
624 | 1770 |
"Modified: 17.10.1997 / 12:35:46 / cg" |
0 | 1771 |
! ! |
1772 |
||
44 | 1773 |
!Parser methodsFor:'accessing'! |
1774 |
||
1775 |
correctedSource |
|
1776 |
^ correctedSource |
|
1777 |
! |
|
1778 |
||
141 | 1779 |
errorFlag |
1780 |
"return true if there where any errors (valid after parsing)" |
|
1781 |
||
1782 |
^ errorFlag |
|
1783 |
! |
|
1784 |
||
1785 |
evalExitBlock:aBlock |
|
1786 |
"when evaluating a return expression, this block is evaluated" |
|
1787 |
||
1788 |
evalExitBlock := aBlock |
|
1789 |
! |
|
1790 |
||
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1791 |
getNameSpace |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1792 |
"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
|
1793 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1794 |
^ currentNamespace |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1795 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1796 |
"Modified: 8.11.1996 / 13:45:35 / cg" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1797 |
! |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1798 |
|
19 | 1799 |
primitiveNumber |
1800 |
"return the ST-80 style primitiveNumber or nil (valid after parsing)" |
|
1801 |
||
1802 |
^ primitiveNr |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1803 |
! |
97 | 1804 |
|
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1805 |
primitiveResources |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1806 |
"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
|
1807 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1808 |
^ primitiveResource |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1809 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1810 |
"Created: 29.5.1996 / 17:28:00 / cg" |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1811 |
! |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1812 |
|
35 | 1813 |
release |
664 | 1814 |
methodArgs := methodVars := tree := selfNode := superNode := nilNode := nil. |
35 | 1815 |
super release. |
664 | 1816 |
|
1817 |
"Modified: / 31.3.1998 / 19:45:58 / cg" |
|
90 | 1818 |
! |
1819 |
||
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1820 |
setNameSpace:aNameSpaceName |
1041
98fa50f8353f
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
1821 |
currentNamespace := NameSpace fullName:aNameSpaceName |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1822 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1823 |
"Modified: 8.11.1996 / 13:43:14 / cg" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1824 |
! |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1825 |
|
1247
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
1826 |
setPackage:aPackageID |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
1827 |
currentPackage := aPackageID |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
1828 |
! |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
1829 |
|
141 | 1830 |
targetClass |
1831 |
^ classToCompileFor |
|
1832 |
! |
|
1833 |
||
90 | 1834 |
targetClass:aClass |
117 | 1835 |
classToCompileFor := aClass |
1836 |
! |
|
1837 |
||
141 | 1838 |
tree |
1839 |
"return the parsetree" |
|
1840 |
||
1841 |
^tree |
|
1842 |
! |
|
1843 |
||
1844 |
tree:aTree |
|
1845 |
"private: set the tree - for internal use only" |
|
1846 |
||
1847 |
tree := aTree |
|
1363 | 1848 |
! |
1849 |
||
1850 |
warnSTXHereExtensionUsed |
|
1851 |
"return the value of the instance variable 'warnSTXHereExtensionUsed' (automatically generated)" |
|
1852 |
||
1853 |
^ warnSTXHereExtensionUsed |
|
141 | 1854 |
! ! |
1855 |
||
1418 | 1856 |
!Parser methodsFor:'dummy-syntax detection'! |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1857 |
|
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1858 |
markArgumentIdentifierFrom:pos1 to:pos2 |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1859 |
|
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1860 |
"Created: / 31.3.1998 / 13:22:15 / cg" |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1861 |
! |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1862 |
|
883 | 1863 |
markBadIdentifierFrom:pos1 to:pos2 |
1864 |
||
1865 |
"Modified: / 31.3.1998 / 19:16:26 / cg" |
|
1866 |
"Created: / 31.3.1998 / 19:35:53 / cg" |
|
1867 |
! |
|
1868 |
||
663 | 1869 |
markBooleanConstantFrom:pos1 to:pos2 |
1870 |
||
1871 |
"Created: / 31.3.1998 / 18:06:22 / cg" |
|
1872 |
! |
|
1873 |
||
673 | 1874 |
markBracketAt:pos |
1875 |
! |
|
1876 |
||
663 | 1877 |
markConstantFrom:pos1 to:pos2 |
1878 |
||
1879 |
"Created: / 31.3.1998 / 18:06:24 / cg" |
|
1880 |
! |
|
1881 |
||
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
815
diff
changeset
|
1882 |
markGlobalClassIdentifierFrom:pos1 to:pos2 |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
815
diff
changeset
|
1883 |
|
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
815
diff
changeset
|
1884 |
"Created: / 4.3.1999 / 12:52:45 / cg" |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
815
diff
changeset
|
1885 |
! |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
815
diff
changeset
|
1886 |
|
663 | 1887 |
markGlobalIdentifierFrom:pos1 to:pos2 |
1888 |
||
1889 |
"Created: / 31.3.1998 / 15:29:39 / cg" |
|
1890 |
! |
|
1891 |
||
1892 |
markHereFrom:pos1 to:pos2 |
|
1893 |
||
1894 |
"Created: / 31.3.1998 / 17:39:01 / cg" |
|
1895 |
! |
|
1896 |
||
1897 |
markIdentifierFrom:pos1 to:pos2 |
|
1898 |
||
1899 |
"Created: / 31.3.1998 / 18:06:17 / cg" |
|
1900 |
! |
|
1901 |
||
687 | 1902 |
markInstVarIdentifierFrom:pos1 to:pos2 |
1903 |
||
1904 |
"Created: / 16.4.1998 / 18:34:10 / cg" |
|
1905 |
! |
|
1906 |
||
663 | 1907 |
markLocalIdentifierFrom:pos1 to:pos2 |
1908 |
||
1909 |
"Created: / 31.3.1998 / 15:29:35 / cg" |
|
1910 |
! |
|
1911 |
||
1912 |
markMethodSelectorFrom:pos1 to:pos2 |
|
1913 |
||
1914 |
"Modified: / 31.3.1998 / 13:30:09 / cg" |
|
1915 |
"Created: / 31.3.1998 / 16:39:44 / cg" |
|
1916 |
! |
|
1917 |
||
837 | 1918 |
markReturnAt:pos |
1919 |
||
1920 |
"Created: / 5.1.1980 / 00:48:24 / cg" |
|
1921 |
! |
|
1922 |
||
864 | 1923 |
markSelector:sel from:pos1 to:pos2 receiverNode:aNode |
1924 |
||
1925 |
"Created: / 31.3.1998 / 13:22:15 / cg" |
|
1926 |
"Modified: / 31.3.1998 / 13:30:09 / cg" |
|
1927 |
! |
|
1928 |
||
663 | 1929 |
markSelfFrom:pos1 to:pos2 |
1930 |
||
1931 |
"Created: / 31.3.1998 / 17:49:38 / cg" |
|
1932 |
! |
|
1933 |
||
1934 |
markSuperFrom:pos1 to:pos2 |
|
1935 |
||
1936 |
"Created: / 31.3.1998 / 17:40:20 / cg" |
|
664 | 1937 |
! |
1938 |
||
1939 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
1940 |
||
1941 |
"Modified: / 31.3.1998 / 19:16:26 / cg" |
|
1942 |
"Created: / 31.3.1998 / 19:35:53 / cg" |
|
687 | 1943 |
! |
1944 |
||
1945 |
markVariable:v |
|
1946 |
"support for syntaxColoring" |
|
1947 |
||
1948 |
"Modified: / 16.4.1998 / 18:47:45 / cg" |
|
1949 |
! |
|
1950 |
||
1951 |
markVariable:v from:pos1 to:pos2 |
|
1952 |
"support for syntaxColoring" |
|
1953 |
||
1954 |
"Modified: / 16.4.1998 / 18:47:45 / cg" |
|
1955 |
"Created: / 16.4.1998 / 18:50:03 / cg" |
|
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1956 |
! ! |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1957 |
|
141 | 1958 |
!Parser methodsFor:'error correction'! |
1959 |
||
1295 | 1960 |
addDoItTemporary:varName |
1961 |
|holder| |
|
1962 |
||
1963 |
doItTemporaries isNil ifTrue:[ |
|
1964 |
doItTemporaries := IdentityDictionary new. |
|
1965 |
]. |
|
1966 |
doItTemporaries at:varName asSymbol put:(holder := ValueHolder new). |
|
1967 |
^ holder |
|
1968 |
! |
|
1969 |
||
141 | 1970 |
askForCorrection:aString fromList:aList |
1971 |
"launch a selection box, which allows user to enter correction. |
|
1972 |
return newString or nil (for abort)" |
|
1973 |
||
1323 | 1974 |
|box rslt| |
141 | 1975 |
|
1976 |
"in systems without widgets ..." |
|
1977 |
ListSelectionBox isNil ifTrue:[ |
|
1285 | 1978 |
^ self confirm:aString |
141 | 1979 |
]. |
1980 |
box := ListSelectionBox title:aString. |
|
1981 |
box initialText:(aList at:1). |
|
1982 |
box list:aList. |
|
1285 | 1983 |
box okText:'Correct'. |
1323 | 1984 |
box action:[:aString | rslt := aString]. |
141 | 1985 |
box showAtPointer. |
1323 | 1986 |
box destroy. |
1987 |
^ rslt |
|
1988 |
! |
|
1989 |
||
1990 |
askForCorrection:aString fromList:aList for:originalSelector |
|
1991 |
"launch a selection box, which allows user to enter correction. |
|
1992 |
return newString or nil (for abort)" |
|
1993 |
||
1994 |
|box rslt| |
|
1995 |
||
1996 |
"in systems without widgets ..." |
|
1997 |
ListSelectionBox isNil ifTrue:[ |
|
1998 |
^ self confirm:aString |
|
1999 |
]. |
|
2000 |
box := ListSelectionBox title:aString. |
|
2001 |
box initialText:(aList at:1). |
|
2002 |
box list:aList. |
|
2003 |
box okText:'Correct'. |
|
2004 |
box action:[:aString | rslt := aString]. |
|
2005 |
box addButton:(Button label:'Keep Selector' action:[rslt := originalSelector. box hide]) after:(box okButton). |
|
2006 |
box showAtPointer. |
|
2007 |
box destroy. |
|
2008 |
^ rslt |
|
141 | 2009 |
! |
2010 |
||
1295 | 2011 |
askForVariableTypeWhenDeclaringUndefined:varName |
2012 |
|l how varNameIsLowercase choice holder newClass| |
|
2013 |
||
2014 |
l := #(). |
|
2015 |
how := #(). |
|
2016 |
||
2017 |
varNameIsLowercase := (varName at:1) isLowercase. |
|
2018 |
||
2019 |
"/ BlockVar, InstVar and classInstVar not yet implemented |
|
2020 |
varNameIsLowercase ifTrue:[ |
|
2021 |
"/ currentBlock notNil ifTrue:[ |
|
2022 |
"/ l := l , #( 'Block local' ). |
|
2023 |
"/ how := how , #( BlockVariable ). |
|
2024 |
"/ ]. |
|
2025 |
selector notNil ifTrue:[ |
|
2026 |
l := l , #( 'Method Local Variable' ). |
|
2027 |
how := how , #( MethodVariable ). |
|
2028 |
]. |
|
2029 |
(classToCompileFor notNil |
|
2030 |
and:[classToCompileFor isMeta not |
|
2031 |
and:[classToCompileFor isBuiltInClass not |
|
1440 | 2032 |
and:[(self isDoIt not)]]]) ifTrue:[ |
1295 | 2033 |
l := l copyWith:'Instance Variable'. |
2034 |
how := how copyWith: #InstanceVariable. |
|
2035 |
]. |
|
2036 |
] ifFalse:[ |
|
2037 |
l := l , #( 'New Class' 'Global' 'NameSpace' ). |
|
2038 |
how := how , #( NewClass GlobalVariable NameSpace ). |
|
2039 |
||
2040 |
(classToCompileFor notNil |
|
2041 |
and:[classToCompileFor isBuiltInClass not |
|
1440 | 2042 |
and:[self isDoIt not]]) ifTrue:[ |
1295 | 2043 |
classToCompileFor isMeta ifTrue:[ |
2044 |
l := l , #('Class Instance Variable'). |
|
2045 |
how := how , #( ClassInstanceVariable). |
|
2046 |
]. |
|
2047 |
l := l , #('Class Variable' ). |
|
2048 |
how := how , #( ClassVariable). |
|
2049 |
] |
|
2050 |
]. |
|
1440 | 2051 |
self isDoIt ifTrue:[ |
1295 | 2052 |
l size > 0 ifTrue:[ |
2053 |
l := l , #( '-' ). |
|
2054 |
how := how , #( nil ). |
|
2055 |
]. |
|
2056 |
l := l , #( 'Workspace Variable' 'DoIt Temporary'). |
|
2057 |
how := how , #( WorkspaceVariable DoItTemporary ). |
|
2058 |
]. |
|
2059 |
||
2060 |
l size > 0 ifTrue:[ |
|
2061 |
l := (Array with:('Declare ' , varName allBold , ' as:') |
|
2062 |
with:'-' |
|
2063 |
) , l. |
|
2064 |
how := #(nil nil) , how. |
|
2065 |
choice := (PopUpMenu labels:l) startUp. |
|
2066 |
(choice notNil and:[choice > 0]) ifTrue:[ |
|
2067 |
choice := how at:choice. |
|
2068 |
||
2069 |
choice == #WorkspaceVariable ifTrue:[ |
|
2070 |
holder := Workspace addWorkspaceVariable:varName. |
|
2071 |
^ VariableNode type:#WorkspaceVariable holder:holder name:varName |
|
2072 |
]. |
|
2073 |
choice == #DoItTemporary ifTrue:[ |
|
2074 |
holder := self addDoItTemporary:varName. |
|
2075 |
^ VariableNode type:#DoItTemporary holder:holder name:varName |
|
2076 |
]. |
|
2077 |
||
2078 |
choice == #GlobalVariable ifTrue:[ |
|
2079 |
Smalltalk at:varName asSymbol put:nil. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2080 |
^ VariableNode globalNamed:varName |
1295 | 2081 |
]. |
2082 |
||
2083 |
choice == #NewClass ifTrue:[ |
|
2084 |
newClass := Object subclass:varName asSymbol |
|
2085 |
instanceVariableNames:'' |
|
2086 |
classVariableNames:'' |
|
2087 |
poolDictionaries:'' |
|
2088 |
category:'* As yet uncategorized *'. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2089 |
^ VariableNode globalNamed:newClass name |
1295 | 2090 |
]. |
2091 |
||
2092 |
choice == #NameSpace ifTrue:[ |
|
2093 |
NameSpace name:varName. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2094 |
^ VariableNode globalNamed:varName |
1295 | 2095 |
]. |
2096 |
||
2097 |
choice == #ClassVariable ifTrue:[ |
|
2098 |
classToCompileFor theNonMetaclass addClassVarName:varName. |
|
2099 |
^ VariableNode type:#ClassVariable class:classToCompileFor theNonMetaclass name:varName |
|
2100 |
]. |
|
2101 |
||
2102 |
choice == #InstanceVariable ifTrue:[ |
|
2103 |
classToCompileFor theNonMetaclass addInstVarName:varName. |
|
2104 |
"/ ST/X special - classToCompileFor is obsoleted |
|
2105 |
classToCompileFor := Smalltalk classNamed:(classToCompileFor name). |
|
2106 |
RestartCompilationSignal raise. |
|
2107 |
"/ not reached - restarted compile will not arrive here again |
|
2108 |
self error:'restart compile failed'. |
|
2109 |
]. |
|
2110 |
||
2111 |
choice == #ClassInstanceVariable ifTrue:[ |
|
2112 |
classToCompileFor theMetaclass addInstVarName:varName. |
|
2113 |
"/ ST/X special - classToCompileFor is obsoleted |
|
2114 |
classToCompileFor := Smalltalk classNamed:(classToCompileFor name). |
|
2115 |
RestartCompilationSignal raise. |
|
2116 |
"/ not reached - restarted compile will not arrive here again |
|
2117 |
self error:'restart compile failed'. |
|
2118 |
]. |
|
2119 |
||
2120 |
choice == #MethodVariable ifTrue:[ |
|
2121 |
|varIndex var endLocalsPos posToInsert ins| |
|
2122 |
||
2123 |
localVarDefPosition size == 2 ifTrue:[ |
|
2124 |
endLocalsPos := posToInsert := localVarDefPosition at:2. |
|
2125 |
ins := ' ' , varName. |
|
2126 |
] ifFalse:[ |
|
2127 |
endOfSelectorPosition notNil ifTrue:[ |
|
2128 |
posToInsert := endOfSelectorPosition. |
|
2129 |
ins := '|' , varName , '|' , Character cr asString , Character cr asString. |
|
2130 |
ins := ins , (String new:(requestor colOfCharacterPosition:posToInsert)-1). |
|
2131 |
] |
|
2132 |
]. |
|
2133 |
posToInsert notNil ifTrue:[ |
|
2134 |
requestor |
|
2135 |
insertString:ins |
|
2136 |
atCharacterPosition:posToInsert. |
|
2137 |
||
2138 |
endLocalsPos notNil ifTrue:[ |
|
2139 |
localVarDefPosition at:2 put:(endLocalsPos + varName size + 1). |
|
2140 |
||
2141 |
methodVarNames := methodVarNames copyWith:varName. |
|
2142 |
methodVars := methodVars copyWith:(var := Variable new name:varName). |
|
2143 |
] ifFalse:[ |
|
2144 |
localVarDefPosition := Array with:posToInsert with:posToInsert+varName size+1. |
|
2145 |
||
2146 |
methodVarNames := Array with:varName. |
|
2147 |
methodVars := Array with:(var := Variable new name:varName). |
|
2148 |
]. |
|
2149 |
correctedSource := requestor currentSourceCode. |
|
2150 |
source := (ReadStream on:correctedSource) |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
2151 |
position:(source position1Based + ins size). |
1295 | 2152 |
|
2153 |
varIndex := methodVarNames size. |
|
2154 |
var used:true. |
|
2155 |
^ VariableNode type:#MethodVariable |
|
2156 |
name:varName |
|
2157 |
token:var |
|
2158 |
index:varIndex |
|
2159 |
]. |
|
2160 |
]. |
|
2161 |
self warning:'Sorry - unimplemented (adding ' , choice , ')'. |
|
2162 |
]. |
|
2163 |
^ #Error |
|
2164 |
]. |
|
2165 |
^ nil. |
|
2166 |
! |
|
2167 |
||
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2168 |
checkSelector:selector inClass:cls |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2169 |
"check wether a method with selector exists in class cls an |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2170 |
that the methos is not obsolete. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2171 |
Return an error string on error or nil on success" |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2172 |
|
1190
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2173 |
|err mthd implementor implementors| |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2174 |
|
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2175 |
cls isNil ifTrue:[ |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2176 |
implementors := SystemBrowser |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2177 |
findImplementorsOf:selector |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2178 |
in:(Smalltalk allClasses) |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2179 |
ignoreCase:false. |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2180 |
implementors size == 0 ifTrue:[ |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2181 |
^ 'is nowhere implemented' |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2182 |
]. |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2183 |
^ nil |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2184 |
]. |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2185 |
|
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2186 |
mthd := cls lookupMethodFor:selector. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2187 |
mthd isNil ifTrue:[ |
1327 | 2188 |
cls == Boolean ifTrue:[ |
2189 |
mthd := True lookupMethodFor:selector. |
|
2190 |
mthd isNil ifTrue:[ |
|
2191 |
mthd := False lookupMethodFor:selector. |
|
2192 |
]. |
|
2193 |
] |
|
2194 |
]. |
|
2195 |
mthd isNil ifTrue:[ |
|
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2196 |
"if it implements #doesNotUnderstand somewhere, assume it is ok" |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2197 |
implementor := cls whichClassIncludesSelector:#doesNotUnderstand:. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2198 |
(implementor isNil or:[implementor == Object]) ifTrue:[ |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2199 |
err := 'is not implemented' |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2200 |
]. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2201 |
] ifFalse:[ |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2202 |
mthd isObsolete ifTrue:[ |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2203 |
err := 'is deprecated'. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2204 |
]. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2205 |
]. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2206 |
^ err. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2207 |
! |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2208 |
|
141 | 2209 |
correctByDeleting |
2210 |
"correct (by deleting token) if user wants to; |
|
2211 |
return #Error if there was no correction; |
|
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2212 |
nil if there was one." |
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2213 |
|
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2214 |
|selectionSize| |
141 | 2215 |
|
2216 |
(self confirm:'confirm deleting') ifFalse:[^ #Error]. |
|
2217 |
||
2218 |
" |
|
2219 |
tell requestor (i.e. CodeView) about the change |
|
2220 |
this will update what the requestor shows. |
|
2221 |
" |
|
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2222 |
selectionSize := requestor selection size. |
141 | 2223 |
requestor deleteSelection. |
2224 |
||
2225 |
" |
|
2226 |
get the updated source-string |
|
2227 |
which is needed, when we eventually install the new method |
|
2228 |
" |
|
2229 |
correctedSource := requestor currentSourceCode. |
|
1167 | 2230 |
"/ update the current source position |
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2231 |
source := (ReadStream on:correctedSource) |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
2232 |
position:(source position1Based - selectionSize). |
1369
2304dd8c3173
recompilation after correct-by-deleting unused local
Claus Gittinger <cg@exept.de>
parents:
1368
diff
changeset
|
2233 |
|
141 | 2234 |
^ nil |
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2235 |
|
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2236 |
"Modified: / 22.1.1998 / 16:39:11 / stefan" |
141 | 2237 |
! |
2238 |
||
1439 | 2239 |
correctSelector:aSelectorString message:msg positions:posVector in:aClassOrNil for:receiverNode |
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2240 |
"notify error and correct if user wants to; |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2241 |
return #Error if there was no correction |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2242 |
or a ParseNode as returned by variable" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2243 |
|
1439 | 2244 |
|correctIt suggestedNames newSelector className classToGenerateCode pos1 pos2| |
2245 |
||
2246 |
pos1 := posVector first start. |
|
2247 |
pos2 := posVector last stop. |
|
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2248 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2249 |
alreadyWarnedUnimplementedSelectors isNil ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2250 |
alreadyWarnedUnimplementedSelectors := Set new |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2251 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2252 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2253 |
(alreadyWarnedUnimplementedSelectors includes:aSelectorString) ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2254 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2255 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2256 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2257 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2258 |
sorry, but I cannot handle keywords with more than one-part |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2259 |
currently (too much work - maybe Ill do it later when everything else works :-) |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2260 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2261 |
(aSelectorString occurrencesOf:$:) > 1 ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2262 |
self warning:msg position:pos1 to:pos2. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2263 |
alreadyWarnedUnimplementedSelectors add:aSelectorString. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2264 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2265 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2266 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2267 |
correctIt := self correctableSelectorWarning:msg position:pos1 to:pos2. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2268 |
correctIt == #generate ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2269 |
receiverNode isSelf ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2270 |
classToGenerateCode := classToCompileFor |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2271 |
] ifFalse:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2272 |
receiverNode isVariable ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2273 |
receiverNode isGlobal ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2274 |
classToGenerateCode := receiverNode evaluate. |
1336
67ea8b161346
Generate class methods in class.
Stefan Vogel <sv@exept.de>
parents:
1335
diff
changeset
|
2275 |
classToGenerateCode isBehavior ifTrue:[ |
67ea8b161346
Generate class methods in class.
Stefan Vogel <sv@exept.de>
parents:
1335
diff
changeset
|
2276 |
classToGenerateCode := classToGenerateCode theMetaclass. |
67ea8b161346
Generate class methods in class.
Stefan Vogel <sv@exept.de>
parents:
1335
diff
changeset
|
2277 |
] ifFalse:[ |
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2278 |
classToGenerateCode := nil |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2279 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2280 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2281 |
] |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2282 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2283 |
classToGenerateCode isNil ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2284 |
className := Dialog request:'Generate code in class:' initialAnswer:classToCompileFor name. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2285 |
className size == 0 ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2286 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2287 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2288 |
classToGenerateCode := Smalltalk at:className asSymbol. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2289 |
classToGenerateCode isNil ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2290 |
self warn:'No such class.'. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2291 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2292 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2293 |
]. |
1252
666db3206028
#implements: -> #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
2294 |
(classToGenerateCode includesSelector:aSelectorString asSymbol) ifFalse:[ |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2295 |
"do not overwrite an already existant (deprecated) method" |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2296 |
classToGenerateCode |
1336
67ea8b161346
Generate class methods in class.
Stefan Vogel <sv@exept.de>
parents:
1335
diff
changeset
|
2297 |
compile:((self class methodSpecificationForSelector:aSelectorString) , '\ self shouldImplement' withCRs) |
1323 | 2298 |
classified:(Compiler defaultMethodCategory). |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2299 |
]. |
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2300 |
correctIt := false. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2301 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2302 |
correctIt ifFalse:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2303 |
alreadyWarnedUnimplementedSelectors add:aSelectorString. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2304 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2305 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2306 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2307 |
suggestedNames := self findBestSelectorsFor:aSelectorString in:aClassOrNil. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2308 |
suggestedNames notNil ifTrue:[ |
1323 | 2309 |
newSelector := self askForCorrection:'Correct Selector to: ' fromList:suggestedNames for:aSelectorString. |
2310 |
newSelector isNil ifTrue:[AbortSignal raise "^ aSelectorString"]. |
|
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2311 |
] ifFalse:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2312 |
self information:'no good correction found'. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2313 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2314 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2315 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2316 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2317 |
tell requestor (i.e. CodeView) about the change |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2318 |
this will update what the requestor shows. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2319 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2320 |
requestor replaceSelectionBy:newSelector keepCursor:false. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2321 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2322 |
get the updated source-string |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2323 |
which is needed, when we eventually install the new method |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2324 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2325 |
correctedSource := requestor currentSourceCode. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2326 |
source := (ReadStream on:correctedSource) |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
2327 |
position:(source position1Based + 1 + (newSelector size - aSelectorString size)). |
1361 | 2328 |
"/ Parser murks. |
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2329 |
^ newSelector |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2330 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2331 |
"Modified: / 22.1.1998 / 16:36:04 / stefan" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2332 |
"Created: / 19.1.2000 / 16:34:01 / cg" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2333 |
"Modified: / 19.1.2000 / 16:34:55 / cg" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2334 |
! |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2335 |
|
1167 | 2336 |
correctSourceByDeletingFrom:start to:stop |
2337 |
"correct (by deleting token) if user wants to; |
|
2338 |
return #Error if there was no correction; |
|
2339 |
nil if there was one." |
|
2340 |
||
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2341 |
|deleteSize localDefsStart localDefsStop newPos| |
1167 | 2342 |
|
2343 |
" |
|
2344 |
tell requestor (i.e. CodeView) about the change |
|
2345 |
this will update what the requestor shows. |
|
2346 |
" |
|
2347 |
deleteSize := stop - start + 1. |
|
2348 |
requestor deleteFromCharacterPosition:start to:stop. |
|
2349 |
||
2350 |
" |
|
2351 |
get the updated source-string |
|
2352 |
which is needed, when we eventually install the new method |
|
2353 |
" |
|
2354 |
correctedSource := requestor currentSourceCode. |
|
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2355 |
|
1167 | 2356 |
"/ update the current source position |
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2357 |
source atEnd ifTrue:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2358 |
newPos := correctedSource size. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2359 |
] ifFalse:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2360 |
source position1Based >= stop ifTrue:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2361 |
newPos := source position1Based - deleteSize |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2362 |
] ifFalse:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2363 |
source position1Based < start ifTrue:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2364 |
newPos := source position1Based |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2365 |
] ifFalse:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2366 |
newPos := start |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2367 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2368 |
] |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2369 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2370 |
source := (ReadStream on:correctedSource) position1Based:newPos. |
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2371 |
|
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2372 |
localDefsStart := localVarDefPosition at:1. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2373 |
localDefsStop := localVarDefPosition at:2. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2374 |
|
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2375 |
localDefsStop <= start ifTrue:[^ self]. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2376 |
localDefsStart >= stop ifTrue:[^ self]. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2377 |
|
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2378 |
(localDefsStart >= start and:[localDefsStop <= stop]) ifTrue:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2379 |
localVarDefPosition := nil. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2380 |
^ self |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2381 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2382 |
|
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2383 |
"/ must update |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2384 |
(start > localDefsStart and:[stop < localDefsStop]) ifTrue:[ |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2385 |
localVarDefPosition at:2 put:(localDefsStop - (stop-start+1)). |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2386 |
^ self. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2387 |
]. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2388 |
self halt. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2389 |
^ self |
1167 | 2390 |
! |
2391 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2392 |
correctVariable:varName atPosition:pos1 to:pos2 |
141 | 2393 |
"notify error and correct if user wants to; |
2394 |
return #Error if there was no correction |
|
2395 |
or a ParseNode as returned by variable" |
|
2396 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2397 |
|correctIt suggestedNames newName rslt |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2398 |
varNameIsLowercase undeclared boldName| |
141 | 2399 |
|
877 | 2400 |
varNameIsLowercase := (varName at:1) isLowercase. |
2401 |
||
141 | 2402 |
correctIt := self undefError:varName position:pos1 to:pos2. |
887 | 2403 |
(correctIt == false or:[correctIt == #continue]) ifTrue:[ |
877 | 2404 |
"/ no correction wanted. |
2405 |
||
2406 |
"/ lowerCase vars are added to the Undeclared dictionary, |
|
2407 |
"/ allowing easy search for bad-spots later. |
|
1285 | 2408 |
boldName := varName allBold. |
877 | 2409 |
|
2410 |
varNameIsLowercase ifTrue:[ |
|
1205 | 2411 |
undeclared := Smalltalk at:#Undeclared. |
2412 |
((undeclared notNil) |
|
2413 |
and:[(undeclared includes:varName asSymbol)]) ifFalse:[ |
|
1285 | 2414 |
self warning:('Adding ''' , boldName , ''' as Undeclared.\\Remember to fix that later.') withCRs position:pos1 to:pos2. |
725
326f4fe4a880
only warn once for undeclared vars.
Claus Gittinger <cg@exept.de>
parents:
718
diff
changeset
|
2415 |
]. |
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2416 |
^ self defineAsUndeclaredVariable:varName |
877 | 2417 |
]. |
2418 |
||
2419 |
"/ upperCase vars are declared as global |
|
915
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
2420 |
(warnedUndefVars isNil or:[(warnedUndefVars includes:varName) not]) ifTrue:[ |
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
2421 |
(warnedUnknownNamespaces isNil or:[(warnedUnknownNamespaces includes:varName) not]) ifTrue:[ |
1285 | 2422 |
self warning:('adding ''' , boldName , ''' as Global.') withCRs position:pos1 to:pos2. |
915
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
2423 |
]. |
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
2424 |
]. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2425 |
^ VariableNode globalNamed:varName |
877 | 2426 |
]. |
2427 |
||
2428 |
correctIt == #declare ifTrue:[ |
|
2429 |
"/ declare it |
|
1295 | 2430 |
rslt := self askForVariableTypeWhenDeclaringUndefined:varName. |
2431 |
rslt notNil ifTrue:[ |
|
2432 |
^ rslt |
|
2433 |
]. |
|
141 | 2434 |
]. |
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
2435 |
(correctIt isKindOf:ParseNode) ifTrue:[ |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
2436 |
^ correctIt |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
2437 |
]. |
141 | 2438 |
|
2439 |
suggestedNames := self findBestVariablesFor:varName. |
|
877 | 2440 |
suggestedNames isNil ifTrue:[ |
1285 | 2441 |
self information:'No good correction found'. |
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2442 |
^ #Error |
141 | 2443 |
]. |
2444 |
||
1285 | 2445 |
newName := self askForCorrection:'Correct Variable to: ' fromList:suggestedNames. |
877 | 2446 |
newName isNil ifTrue:[^ #Error]. |
2447 |
" |
|
2448 |
newName := suggestedNames at:1. |
|
2449 |
(self confirm:('confirm correction to: ' , newName)) ifFalse:[^ #Error]. |
|
2450 |
" |
|
2451 |
||
141 | 2452 |
" |
2453 |
tell requestor (i.e. CodeView) about the change |
|
2454 |
this will update what the requestor shows. |
|
2455 |
" |
|
2456 |
requestor replaceSelectionBy:newName. |
|
2457 |
" |
|
2458 |
get the updated source-string |
|
2459 |
which is needed, when we eventually install the new method |
|
2460 |
" |
|
2461 |
correctedSource := requestor currentSourceCode. |
|
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2462 |
source := (ReadStream on:correctedSource) |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
2463 |
position:(source position1Based + newName size - tokenName size). |
141 | 2464 |
|
2465 |
"redo parse with new value" |
|
1103
b75a71996388
ensure that token follows tomeName & tokenValue
Claus Gittinger <cg@exept.de>
parents:
1100
diff
changeset
|
2466 |
token := 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
|
2467 |
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
|
2468 |
|
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
|
2469 |
"/ 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
|
2470 |
rslt == #Error ifTrue:[ |
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2471 |
"/ install as Undeclared:<name>, remember in #undeclared |
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2472 |
|
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2473 |
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
|
2474 |
]. |
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
|
2475 |
^ 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
|
2476 |
|
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2477 |
"Modified: / 22.1.1998 / 16:34:01 / stefan" |
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
2478 |
"Modified: / 15.11.2001 / 22:56:38 / cg" |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
2479 |
! |
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
|
2480 |
|
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
|
2481 |
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
|
2482 |
"define varName as undeclared variable |
629 | 2483 |
(actually, it will be installed as a funny global named 'Undeclared:::<name>'). |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
2484 |
You can browse for methods with undeclareds by searching for global accesses |
629 | 2485 |
to 'Undeclared:::*' (or use the search-undeclared item in the launchers menu)." |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
2486 |
|
1206 | 2487 |
|varName undeclared| |
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
|
2488 |
|
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
|
2489 |
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
|
2490 |
|
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
|
2491 |
"/ 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
|
2492 |
|
1206 | 2493 |
undeclared := Smalltalk at:#Undeclared. |
2494 |
undeclared isNil ifTrue:[ |
|
2495 |
Smalltalk at:#Undeclared put:(undeclared := IdentitySet new). |
|
2496 |
]. |
|
2497 |
undeclared add:tokenName asSymbol. |
|
1304
ade15708e7c1
undeclared variable handling was broken (to allow reference search)
penk
parents:
1301
diff
changeset
|
2498 |
varName := (Smalltalk undeclaredPrefix) , tokenName. |
603
021722b8a427
correctly scan trailing period after a number in a block (as in x := x + 1.]
Claus Gittinger <cg@exept.de>
parents:
601
diff
changeset
|
2499 |
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
|
2500 |
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
|
2501 |
|
762
66cd2b4f6689
Big BUG: remember original name in usedVars - not Undeclared::xxx
tm
parents:
755
diff
changeset
|
2502 |
parseForCode ifFalse:[self rememberGlobalUsed:aName]. |
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
|
2503 |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2504 |
^ VariableNode globalNamed: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
|
2505 |
|
629 | 2506 |
"Modified: / 31.10.1997 / 01:16:03 / cg" |
141 | 2507 |
! |
2508 |
||
1167 | 2509 |
deleteDefinitionOf:varName in:defStartPos to:defEndPos |
1393 | 2510 |
"this removes the definition of varName from the declaration part i.e. |
2511 |
if the source was '... | foo bar baz |...' |
|
2512 |
deleting the var 'bar' changes the source to '... | foo baz |...'. |
|
2513 |
The code below tries to be somewhat smart w.r.t. spaces by |
|
2514 |
trying to remove the whiteSpace around the removed variable also. |
|
2515 |
However, this seems to not always work correctly" |
|
2516 |
||
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2517 |
|source startSearch pos pos2 nextChar varSlot p p2| |
1172 | 2518 |
|
2519 |
varSlot := methodVars detect:[:var | var name = varName]. |
|
2520 |
methodVars removeIdentical:varSlot. |
|
1167 | 2521 |
|
2522 |
source := requestor currentSourceCode. |
|
2523 |
startSearch := defStartPos+1. |
|
2524 |
||
2525 |
[ |
|
1393 | 2526 |
|prevChar isFirstVar didPassEndOfLine| |
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2527 |
|
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2528 |
"/ search this name's position in the declaration part ... |
1167 | 2529 |
pos := source indexOfSubCollection:varName startingAt:startSearch ifAbsent:0. |
1326 | 2530 |
(pos == 0 or:[pos >= defEndPos]) ifTrue:[ |
2531 |
self error:'should not happen' mayProceed:true. |
|
1167 | 2532 |
^ self. |
2533 |
]. |
|
2534 |
||
2535 |
pos2 := pos + varName size - 1. |
|
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2536 |
pos > 1 ifTrue:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2537 |
prevChar := source at:pos-1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2538 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2539 |
(prevChar isNil or:[prevChar isLetterOrDigit not]) ifTrue:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2540 |
nextChar := source at:pos2+1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2541 |
nextChar isLetterOrDigit ifFalse:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2542 |
"/ halfway intuitive space-removal behavior; |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2543 |
"/ if there was a space after/before the |-char, |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2544 |
"/ leave it; otherwise remove it. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2545 |
isFirstVar := pos == (defStartPos+1). |
1393 | 2546 |
(source at:pos-1) isSeparator ifTrue:[ |
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2547 |
pos := pos - 1. |
1393 | 2548 |
[ (source at:pos-1) isSeparator] whileTrue:[ |
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2549 |
pos := pos - 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2550 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2551 |
(source at:pos-1) == $| ifTrue:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2552 |
"/ there was a space before - leave it |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2553 |
pos := pos + 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2554 |
isFirstVar := true. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2555 |
] |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2556 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2557 |
|
1393 | 2558 |
(source at:pos2+1) isSeparator ifTrue:[ |
2559 |
didPassEndOfLine := (source at:pos2+1) == Character cr. |
|
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2560 |
pos2 := pos2 + 1. |
1393 | 2561 |
[ (source at:pos2+1) isSeparator] whileTrue:[ |
2562 |
(source at:pos2+1) == Character cr ifTrue:[ didPassEndOfLine := true ]. |
|
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2563 |
pos2 := pos2 + 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2564 |
]. |
1393 | 2565 |
|
2566 |
didPassEndOfLine ifFalse:[ |
|
2567 |
(source at:pos2+1) == $" ifTrue:[ |
|
2568 |
"/ comment follows - assume it belongs to the removed variable |
|
2569 |
pos2 := pos2 + 1. |
|
2570 |
(source at:pos2+1) == $/ ifTrue:[ |
|
2571 |
"/ EOL comment |
|
2572 |
[ (source at:pos2+1) == Character cr ] whileFalse:[ |
|
2573 |
pos2 := pos2 + 1. |
|
2574 |
]. |
|
2575 |
pos2 := pos2 + 1. |
|
2576 |
] ifFalse:[ |
|
2577 |
"/ regular comment |
|
2578 |
[ (source at:pos2+1) == $" ] whileFalse:[ |
|
2579 |
pos2 := pos2 + 1. |
|
2580 |
]. |
|
2581 |
pos2 := pos2 + 1. |
|
2582 |
]. |
|
2583 |
[ (source at:pos2+1) isSeparator] whileTrue:[ |
|
2584 |
(source at:pos2+1) == Character cr ifTrue:[ didPassEndOfLine := true ]. |
|
2585 |
pos2 := pos2 + 1. |
|
2586 |
]. |
|
2587 |
] |
|
2588 |
]. |
|
2589 |
||
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2590 |
(source at:pos2+1) == $| ifTrue:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2591 |
"/ there was a space after - leave it |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2592 |
pos2 := pos2 - 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2593 |
] ifFalse:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2594 |
isFirstVar ifFalse:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2595 |
pos2 := pos2 - 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2596 |
] |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2597 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2598 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2599 |
|
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2600 |
"/ if this was the last, remove empty var-declaration completely |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2601 |
((source at:pos-1) == $| |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2602 |
and:[ (source at:pos2+1) == $| ]) ifTrue:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2603 |
pos := pos - 1. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2604 |
pos2 := pos2 + 1. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2605 |
"/ see if that gives us an empty line |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2606 |
p := pos. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2607 |
p2 := pos2. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2608 |
|
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2609 |
[(source at:p-1) == Character space] whileTrue:[ p := p - 1 ]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2610 |
[(source at:p2+1) == Character space] whileTrue:[ p2 := p2 + 1 ]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2611 |
((source at:p-1) == Character cr and:[ (source at:p2+1) == Character cr]) ifTrue:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2612 |
pos := p-1. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2613 |
pos2 := p2. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2614 |
(((source at:pos-1) == Character cr) and:[((source at:pos-2) == Character cr)]) |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2615 |
ifTrue:[ pos := pos - 1 ] |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2616 |
ifFalse:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2617 |
(((source at:pos2+1) == Character cr) and:[((source at:pos2+2) == Character cr)]) ifTrue:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2618 |
pos2 := pos2 + 1 ]]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2619 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2620 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2621 |
|
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2622 |
self correctSourceByDeletingFrom:pos to:pos2. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2623 |
^ self. |
1167 | 2624 |
]. |
2625 |
]. |
|
2626 |
startSearch := pos2 + 1. |
|
2627 |
] loop |
|
2628 |
! |
|
2629 |
||
141 | 2630 |
findBestSelectorsFor:aString |
2631 |
"collect known selectors with their spelling distances to aString; |
|
2632 |
return the 10 best suggestions" |
|
2633 |
||
1187 | 2634 |
^ self class findBestSelectorsFor:aString |
141 | 2635 |
|
2636 |
"Time millisecondsToRun:[Parser new findBestSelectorsFor:'foo']" |
|
2637 |
"Parser new findBestSelectorsFor:'findBestSel'" |
|
2638 |
"Parser new findBestSelectorsFor:'fildBestSelectrFr'" |
|
2639 |
! |
|
2640 |
||
1022 | 2641 |
findBestSelectorsFor:aString in:aClassOrNil |
2642 |
"collect known selectors with their spelling distances to aString; |
|
2643 |
return the 10 best suggestions. If the argument, aClassOrNil is not nil, |
|
2644 |
the message is assumed to be sent to instances of that class (i.e. offer |
|
2645 |
corrections from that hierarchy only)" |
|
2646 |
||
1187 | 2647 |
^ self class findBestSelectorsFor:aString in:aClassOrNil |
1022 | 2648 |
! |
2649 |
||
141 | 2650 |
findBestVariablesFor:aString |
2651 |
"collect known variables with their spelling distances to aString; |
|
2652 |
return the 10 best suggestions" |
|
2653 |
||
1200 | 2654 |
|names dists searchBlock args vars "aClass className baseClass" |
2655 |
n instVarNames classVarNames spellAgainstAction| |
|
141 | 2656 |
|
2657 |
names := OrderedCollection new. |
|
2658 |
dists := OrderedCollection new. |
|
2659 |
||
1200 | 2660 |
spellAgainstAction := |
2661 |
[:aVarNode | |
|
2662 |
|varName dist| |
|
2663 |
||
2664 |
varName := aVarNode name. |
|
2665 |
names add:varName. |
|
2666 |
||
2667 |
dist := aString spellAgainst:varName. |
|
2668 |
(aString startsWith:varName) ifTrue:[ |
|
2669 |
dist := dist + (aString size * 10). |
|
2670 |
]. |
|
2671 |
dists add:dist |
|
2672 |
]. |
|
2673 |
||
141 | 2674 |
"block arguments" |
2675 |
searchBlock := currentBlock. |
|
2676 |
[searchBlock notNil] whileTrue:[ |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2677 |
args := searchBlock arguments. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2678 |
args notNil ifTrue:[ |
1200 | 2679 |
args do:spellAgainstAction |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2680 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2681 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2682 |
vars := searchBlock variables. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2683 |
vars notNil ifTrue:[ |
1200 | 2684 |
vars do:spellAgainstAction |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2685 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2686 |
searchBlock := searchBlock home |
141 | 2687 |
]. |
2688 |
||
1200 | 2689 |
spellAgainstAction := |
2690 |
[:givenName | |
|
2691 |
|dist| |
|
2692 |
||
2693 |
names add:givenName. |
|
2694 |
dist := aString spellAgainst:givenName. |
|
2695 |
(aString startsWith:givenName) ifTrue:[ |
|
2696 |
dist := dist + (aString size * 10). |
|
2697 |
]. |
|
2698 |
dists add:dist |
|
2699 |
]. |
|
2700 |
||
141 | 2701 |
"method-variables" |
2702 |
methodVars notNil ifTrue:[ |
|
1200 | 2703 |
methodVarNames do:spellAgainstAction |
141 | 2704 |
]. |
2705 |
||
2706 |
"method-arguments" |
|
2707 |
methodArgs notNil ifTrue:[ |
|
1200 | 2708 |
methodArgNames do:spellAgainstAction |
141 | 2709 |
]. |
2710 |
||
2711 |
"instance-variables" |
|
2712 |
classToCompileFor notNil ifTrue:[ |
|
1200 | 2713 |
self classesInstVarNames do:spellAgainstAction |
141 | 2714 |
]. |
2715 |
||
2716 |
"class-variables" |
|
2717 |
classToCompileFor notNil ifTrue:[ |
|
1200 | 2718 |
self classesClassVarNames do:spellAgainstAction. |
141 | 2719 |
|
2720 |
"/ aClass := classToCompileFor. |
|
2721 |
"/ aClass isMeta ifTrue:[ |
|
2722 |
"/ className := aClass name. |
|
2723 |
"/ className := className copyWithoutLast:5. |
|
2724 |
"/ baseClass := Smalltalk at:(className asSymbol). |
|
2725 |
"/ baseClass notNil ifTrue:[ |
|
2726 |
"/ aClass := baseClass |
|
2727 |
"/ ] |
|
2728 |
"/ ]. |
|
2729 |
"/ [aClass notNil] whileTrue:[ |
|
2730 |
"/ (aClass classVarNames) do:[:classVarName | |
|
2731 |
"/ names add:classVarName. |
|
2732 |
"/ dists add:(aString spellAgainst: "levenshteinTo:"classVarName) |
|
2733 |
"/ ]. |
|
2734 |
"/ aClass := aClass superclass |
|
2735 |
"/ ] |
|
2736 |
||
2737 |
]. |
|
2738 |
||
2739 |
"globals" |
|
2740 |
Smalltalk keysDo:[:aKey | |
|
1200 | 2741 |
|globalVarName| |
2742 |
||
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2743 |
globalVarName := aKey asString. |
1200 | 2744 |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2745 |
"only compare strings where length is about right" |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2746 |
((globalVarName size - aString size) abs < 3) ifTrue:[ |
1200 | 2747 |
spellAgainstAction value:globalVarName. |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2748 |
] |
141 | 2749 |
]. |
2750 |
||
2751 |
"misc" |
|
1200 | 2752 |
#('self' 'super' 'nil' 'thisContext') do:spellAgainstAction. |
141 | 2753 |
|
2754 |
(dists size ~~ 0) ifTrue:[ |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2755 |
dists sortWith:names. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2756 |
dists := dists reverse. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2757 |
names := names reverse. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2758 |
n := names size min:10. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2759 |
names := names copyTo:n. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2760 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2761 |
"if it starts with a lower case character, add all local & instvar names" |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2762 |
(aString at:1) isLowercase ifTrue:[ |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2763 |
methodVarNames size > 0 ifTrue:[ |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2764 |
names add:'---- method locals ----'. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2765 |
methodVarNames asSortedCollection do:[:methodVarName | |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2766 |
names add:methodVarName. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2767 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2768 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2769 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2770 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2771 |
methodArgs size > 0 ifTrue:[ |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2772 |
names add:'---- method arguments ----'. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2773 |
methodArgNames asSortedCollection do:[:methodArgName | |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2774 |
names add:methodArgName. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2775 |
] |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2776 |
]. |
1078 | 2777 |
classToCompileFor notNil ifTrue:[ |
2778 |
instVarNames := OrderedCollection new. |
|
2779 |
self classesInstVarNames asSortedCollection do:[:instVarName | |
|
2780 |
(instVarNames includes:instVarName) ifFalse:[ |
|
2781 |
instVarNames add:instVarName. |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2782 |
] |
1078 | 2783 |
]. |
2784 |
||
2785 |
instVarNames size > 0 ifTrue:[ |
|
2786 |
(classToCompileFor notNil and:[classToCompileFor isMeta]) ifTrue:[ |
|
2787 |
names add:'---- class instance variables ----'. |
|
2788 |
] ifFalse:[ |
|
2789 |
names add:'---- instance variables ----'. |
|
2790 |
]. |
|
2791 |
instVarNames do:[:instVarName | |
|
2792 |
(names includes:instVarName) ifFalse:[ |
|
2793 |
names add:instVarName. |
|
2794 |
] |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2795 |
] |
1078 | 2796 |
]. |
2797 |
||
2798 |
classVarNames := OrderedCollection new. |
|
2799 |
self classesClassVarNames asSortedCollection do:[:classVarName | |
|
2800 |
(classVarNames includes:classVarName) ifFalse:[ |
|
2801 |
classVarNames add:classVarName. |
|
2802 |
] |
|
2803 |
]. |
|
2804 |
||
2805 |
classVarNames size > 0 ifTrue:[ |
|
2806 |
names add:'---- class variables ----'. |
|
2807 |
classVarNames do:[:classVarName | |
|
2808 |
(names includes:classVarName) ifFalse:[ |
|
2809 |
names add:classVarName. |
|
2810 |
] |
|
2811 |
] |
|
2812 |
]. |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2813 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2814 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2815 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2816 |
^ names |
141 | 2817 |
]. |
2818 |
^ nil |
|
450 | 2819 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
2820 |
"Modified: 11.1.1997 / 21:28:28 / cg" |
141 | 2821 |
! |
2822 |
||
2823 |
selectorCheck:aSelectorString for:receiver position:pos1 to:pos2 |
|
1439 | 2824 |
^ self selectorCheck:aSelectorString for:receiver positions:(Array with:(pos1 to:pos2)). |
2825 |
! |
|
2826 |
||
2827 |
selectorCheck:aSelectorString for:receiver positions:posVector |
|
141 | 2828 |
"just a quick check: if a selector is totally unknown as a symbol, |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2829 |
has the same name as a variable, cannot be understood or is obsolete. |
141 | 2830 |
Simple, but catches many typos" |
2831 |
||
1440 | 2832 |
|err sym rec names recType selClass newSelector nm nowhereImplemented pos1 pos2 canDefine| |
2833 |
||
2834 |
canDefine := false. |
|
1439 | 2835 |
|
2836 |
pos1 := posVector first start. |
|
2837 |
pos2 := posVector last stop. |
|
141 | 2838 |
|
2839 |
" |
|
2840 |
if compiling lazy, or errors are to be ignored, or there |
|
2841 |
is no requestor, do not check |
|
2842 |
" |
|
1022 | 2843 |
(LazyCompilation == true) ifTrue:[^ aSelectorString]. |
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
2844 |
self isSyntaxHighlighter ifFalse:[ |
1022 | 2845 |
(ignoreErrors or:[ignoreWarnings]) ifTrue:[^ aSelectorString]. |
2846 |
(requestor isNil or:[requestor isStream]) ifTrue:[^ aSelectorString]. |
|
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
2847 |
]. |
141 | 2848 |
|
1301
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
2849 |
aSelectorString = '#' ifTrue:[ |
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
2850 |
self warnPossibleIncompatibility:'''#'' might not be a valid selector in other smalltalk systems' position:pos1 to:pos2. |
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
2851 |
]. |
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
2852 |
|
141 | 2853 |
" |
2854 |
check if the selector is known at all |
|
2855 |
- if not, it cannot be understood |
|
2856 |
" |
|
1327 | 2857 |
nowhereImplemented := false. |
2858 |
||
141 | 2859 |
sym := aSelectorString asSymbolIfInterned. |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2860 |
sym isNil ifTrue:[ |
1327 | 2861 |
nowhereImplemented := true. |
2862 |
"/ ] ifFalse:[ |
|
2863 |
"/ nowhereImplemented := (self implementedInAnyClass:sym) not. |
|
2864 |
]. |
|
2865 |
||
2866 |
nowhereImplemented ifTrue:[ |
|
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2867 |
err := ' is currently nowhere implemented'. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2868 |
|
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2869 |
" |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2870 |
if the selector has the name of a variable, use another message |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2871 |
" |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2872 |
((methodVarNames notNil and:[methodVarNames includes:aSelectorString]) |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2873 |
or:[(methodArgNames notNil and:[methodArgNames includes:aSelectorString]) |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2874 |
or:[(classToCompileFor notNil |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2875 |
and:[((names := self classesInstVarNames) notNil and:[names includes:aSelectorString])]) |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2876 |
or:[(classToCompileFor notNil |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2877 |
and:[((names := self classesClassInstVarNames) notNil and:[names includes:aSelectorString])]) |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2878 |
or:[classToCompileFor notNil |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2879 |
and:[((names := self classesClassVarNames) notNil and:[names includes:aSelectorString])]]]]]) ifTrue:[ |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2880 |
err := ' is currently nowhere implemented .. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2881 |
.. but a variable with that name is defined. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2882 |
|
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2883 |
Missing ''.'' after the previous expression |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2884 |
or missing keyword/receiver before that word ?'. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2885 |
]. |
1327 | 2886 |
] ifFalse:[ |
2887 |
receiver notNil ifTrue:[ |
|
2888 |
selClass := self typeOfNode:receiver. |
|
2889 |
selClass notNil ifTrue:[ |
|
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2890 |
err := self checkSelector:sym inClass:selClass. |
1327 | 2891 |
]. |
2892 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2893 |
(receiver isConstant or:[receiver isBlock]) ifTrue:[ |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2894 |
err notNil ifTrue:[ |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2895 |
err := err, ' in ' , selClass name , ' or any of its superclasses'. |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2896 |
]. |
1327 | 2897 |
] ifFalse:[(((recType := receiver type) == #GlobalVariable) |
2898 |
or:[recType == #PrivateClass]) ifTrue:[ |
|
2899 |
rec := receiver evaluate. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2900 |
"/ dont check autoloaded classes - it may work after loading |
1327 | 2901 |
(rec isNil |
2902 |
or:[rec isBehavior and:[rec isLoaded not]]) ifTrue:[ |
|
2903 |
^ aSelectorString |
|
2904 |
]. |
|
2905 |
||
2906 |
err notNil ifTrue:[ |
|
2907 |
(rec isBehavior |
|
2908 |
and:[rec theNonMetaclass name = receiver name]) ifTrue:[ |
|
2909 |
err := err, ' in ' , rec theNonMetaclass name. |
|
2910 |
] ifFalse:[ |
|
2911 |
err := err, ' in currently assigned value (is currently ' , rec classNameWithArticle , ')'. |
|
2912 |
] |
|
2913 |
]. |
|
2914 |
] ifFalse:[receiver isSuper ifTrue:[ |
|
2915 |
receiver isHere ifFalse:[ |
|
2916 |
err notNil ifTrue:[ |
|
2917 |
err := err, ' in superclass chain'. |
|
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2918 |
]. |
1327 | 2919 |
] ifTrue:[ |
2920 |
err notNil ifTrue:[ |
|
2921 |
err := err, ' in this class or superclass chain'. |
|
1203
2bd6633eced0
better error message for 'class foo', where foo is implemented in the instance.
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
2922 |
]. |
1327 | 2923 |
] |
2924 |
] ifFalse:[receiver isSelf ifTrue:[ |
|
2925 |
err notNil ifTrue:[ |
|
2926 |
|subErr| |
|
2927 |
||
2928 |
"/ understood by all subclasses ? |
|
2929 |
classToCompileFor allSubclassesDo:[:eachSubclass | |
|
2930 |
subErr isNil ifTrue:[ |
|
2931 |
selClass := eachSubclass. |
|
2932 |
subErr := self checkSelector:sym inClass:selClass. |
|
2933 |
]. |
|
2934 |
]. |
|
2935 |
subErr notNil ifTrue:[ |
|
2936 |
err := subErr, ' in this class, superclass chain or all subclasses' |
|
2937 |
] ifFalse:[ |
|
2938 |
err := err, ' in this class or superclass chain'. |
|
1440 | 2939 |
]. |
2940 |
canDefine := true. |
|
1327 | 2941 |
]. |
2942 |
] ifFalse:[(receiver isUnaryMessage |
|
2943 |
and:[receiver selector == #class |
|
2944 |
and:[receiver receiver isSelf]]) ifTrue:[ |
|
2945 |
"its a message to self class - can check this too ..." |
|
2946 |
err notNil ifTrue:[ |
|
2947 |
classToCompileFor isMeta ifTrue:[ |
|
2948 |
err := err, ' for the classes class'. |
|
2949 |
(self checkSelector:sym inClass:classToCompileFor) isNil ifTrue:[ |
|
2950 |
err := err, '...\\...but its implemented for the class itself. You probably do not want the #class message here.'. |
|
2951 |
err := err withCRs. |
|
2952 |
]. |
|
2953 |
] ifFalse:[ |
|
2954 |
err := err, ' for my class'. |
|
2955 |
(self checkSelector:sym inClass:classToCompileFor) isNil ifTrue:[ |
|
2956 |
err := err, '...\\...but its implemented for instances. You may want to remove the #class message.'. |
|
2957 |
err := err withCRs. |
|
2958 |
]. |
|
1203
2bd6633eced0
better error message for 'class foo', where foo is implemented in the instance.
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
2959 |
]. |
2bd6633eced0
better error message for 'class foo', where foo is implemented in the instance.
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
2960 |
]. |
1327 | 2961 |
] ifFalse:[(receiver isMethodVariable and:[receiver token type isNil]) ifTrue:[ |
2962 |
"if it is an uninitialized variable ..." |
|
2963 |
((modifiedLocalVars isNil or:[(modifiedLocalVars includes:receiver name) not]) |
|
1441 | 2964 |
and:[hasPrimitiveCode not |
1442 | 2965 |
and:[ currentBlock isNil |
1327 | 2966 |
and:[alreadyWarnedUninitializedVars isNil |
1442 | 2967 |
or:[(alreadyWarnedUninitializedVars includes:receiver name) not]]]]) |
1327 | 2968 |
ifTrue:[ |
2969 |
((#(at: at:put: basicAt: basicAt:put:) includes:sym) |
|
2970 |
or:[(nil respondsTo:sym) not])ifTrue:[ |
|
2971 |
"/ avoid trouble in miniTalk |
|
2972 |
"/ during bootstrap |
|
2973 |
nm := receiver name. |
|
2974 |
Text notNil ifTrue:[ |
|
2975 |
nm := nm allItalic |
|
2976 |
]. |
|
2977 |
err := 'sent to possibly uninitialized variable ''' , nm , ''' here (?)'. |
|
2978 |
alreadyWarnedUninitializedVars isNil ifTrue:[ |
|
2979 |
alreadyWarnedUninitializedVars := Set new |
|
2980 |
]. |
|
2981 |
alreadyWarnedUninitializedVars add:receiver name |
|
2982 |
] |
|
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
2983 |
] |
1327 | 2984 |
] ifFalse:[ |
2985 |
err notNil ifTrue:[ |
|
2986 |
err := err, ' (message to ' , selClass nameWithArticle , ')'. |
|
2987 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2988 |
]]]]]]. |
1327 | 2989 |
] |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2990 |
]. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2991 |
|
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2992 |
err notNil ifTrue:[ |
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
2993 |
(receiver notNil |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
2994 |
and:[((recType := receiver type) == #GlobalVariable) |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
2995 |
or:[recType == #PrivateClass]]) ifTrue:[ |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
2996 |
"/ dont check autoloaded classes |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
2997 |
"/ - it may work after loading |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
2998 |
|
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
2999 |
rec := receiver evaluate. |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3000 |
(rec notNil |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3001 |
and:[rec isBehavior |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3002 |
and:[rec isLoaded not]]) ifTrue:[ |
1022 | 3003 |
^ aSelectorString |
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3004 |
]. |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3005 |
rec class == UndefinedVariable ifTrue:[ |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3006 |
"/ dont check undefined vars; |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3007 |
"/ it may work after loading/defining |
1022 | 3008 |
^ aSelectorString |
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3009 |
]. |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3010 |
]. |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3011 |
Text notNil ifTrue:[ |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
3012 |
err := '"' , aSelectorString allBold "allItalic" , '" ', err |
1052
0a1e613468f5
avoid trouble if Text class is not present (in mini-image)
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
3013 |
] ifFalse:[ |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3014 |
err := aSelectorString , ' ', err |
1052
0a1e613468f5
avoid trouble if Text class is not present (in mini-image)
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
3015 |
]. |
1157
122be9201878
selectorCheck (do not complain for new selector being recursively invoked)
Claus Gittinger <cg@exept.de>
parents:
1156
diff
changeset
|
3016 |
"/ if its a recursive invocation of just that selector, do not complain |
122be9201878
selectorCheck (do not complain for new selector being recursively invoked)
Claus Gittinger <cg@exept.de>
parents:
1156
diff
changeset
|
3017 |
(selector = aSelectorString and:[ receiver isSelf]) ifTrue:[ |
122be9201878
selectorCheck (do not complain for new selector being recursively invoked)
Claus Gittinger <cg@exept.de>
parents:
1156
diff
changeset
|
3018 |
^ aSelectorString |
122be9201878
selectorCheck (do not complain for new selector being recursively invoked)
Claus Gittinger <cg@exept.de>
parents:
1156
diff
changeset
|
3019 |
]. |
1439 | 3020 |
self isSyntaxHighlighter ifTrue:[ |
3021 |
posVector do:[:p | |
|
3022 |
self markUnknownIdentifierFrom:(p start) to:(p stop). |
|
3023 |
]. |
|
3024 |
]. |
|
1440 | 3025 |
err := err , '\\This is a warning from the compiler - the code has not yet been executed/compiled.'. |
1022 | 3026 |
newSelector := self correctSelector:aSelectorString |
1439 | 3027 |
message:err withCRs positions:posVector in:selClass for:receiver. |
1022 | 3028 |
"/ self warning:('#' , aSelectorString , '\\' , err) withCRs position:pos1 to:pos2. |
3029 |
^ newSelector. |
|
141 | 3030 |
]. |
1022 | 3031 |
^ aSelectorString |
141 | 3032 |
|
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3033 |
"Modified: / 5.9.1995 / 17:02:11 / claus" |
1022 | 3034 |
"Modified: / 19.1.2000 / 16:34:03 / cg" |
1327 | 3035 |
! |
3036 |
||
3037 |
typeOfNode:aNode |
|
3038 |
|nodeVal nodeType| |
|
3039 |
||
3040 |
aNode isConstant ifTrue:[ |
|
3041 |
" |
|
3042 |
if the receiver is a constant, we can check if it responds |
|
3043 |
to this selector |
|
3044 |
" |
|
3045 |
nodeVal := aNode evaluate. |
|
3046 |
^ nodeVal class. |
|
3047 |
]. |
|
3048 |
||
3049 |
"/ this should help with typos, sending #ifTrue to blocks ... |
|
3050 |
aNode isBlock ifTrue:[ |
|
3051 |
^ Block |
|
3052 |
]. |
|
3053 |
||
3054 |
(((nodeType := aNode type) == #GlobalVariable) |
|
3055 |
or:[nodeType == #PrivateClass]) ifTrue:[ |
|
3056 |
"if the receiver is a global, we check it too ..." |
|
3057 |
||
3058 |
nodeVal := aNode evaluate. |
|
3059 |
"/ dont check autoloaded classes |
|
3060 |
"/ - it may work after loading |
|
3061 |
(nodeVal isNil |
|
3062 |
or:[nodeVal isBehavior and:[nodeVal isLoaded not]]) ifTrue:[ |
|
3063 |
^ nil |
|
3064 |
]. |
|
3065 |
||
3066 |
^ nodeVal class. |
|
3067 |
]. |
|
3068 |
||
3069 |
aNode isSuper ifTrue:[ |
|
3070 |
"if its a super- or here-send, we can do more checking" |
|
3071 |
aNode isHere ifFalse:[ |
|
3072 |
^ classToCompileFor superclass ? UndefinedObject. |
|
3073 |
]. |
|
3074 |
^ classToCompileFor. |
|
3075 |
]. |
|
3076 |
aNode isSelf ifTrue:[ |
|
3077 |
^ classToCompileFor. |
|
3078 |
]. |
|
3079 |
||
3080 |
(aNode isUnaryMessage) ifTrue:[ |
|
3081 |
(aNode selector == #class) ifTrue:[ |
|
3082 |
aNode receiver isSelf ifTrue:[ |
|
3083 |
"its a message to self class - can check this too ..." |
|
3084 |
^ classToCompileFor class. |
|
3085 |
]. |
|
3086 |
]. |
|
3087 |
( #(#'isNil' #'notNil') includes:aNode selector) ifTrue:[ |
|
3088 |
^ Boolean. |
|
3089 |
] |
|
3090 |
]. |
|
3091 |
aNode isBinaryMessage ifTrue:[ |
|
3092 |
( #(#'<' #'>' #'>=' #'<=' #'=' #'==' #'~=' #'~~') includes:aNode selector) ifTrue:[ |
|
3093 |
^ Boolean. |
|
3094 |
] |
|
3095 |
]. |
|
3096 |
||
3097 |
^ nil |
|
0 | 3098 |
! ! |
3099 |
||
3100 |
!Parser methodsFor:'error handling'! |
|
3101 |
||
1259 | 3102 |
blockArgRedefined:tokenName from:pos1 to:pos2 |
3103 |
"argname reuse" |
|
3104 |
||
3105 |
self isSyntaxHighlighter ifTrue:[ |
|
3106 |
self markBadIdentifierFrom:pos1 to:pos2. |
|
3107 |
] ifFalse:[ |
|
3108 |
self |
|
3109 |
syntaxError:'redefinition of ''' , tokenName , ''' in argument list.' |
|
3110 |
position:pos1 to:pos2 |
|
3111 |
]. |
|
3112 |
! |
|
3113 |
||
141 | 3114 |
exitWith:something |
3115 |
"this is the longjump out of evaluation via a return expression" |
|
3116 |
||
3117 |
evalExitBlock value:something |
|
3118 |
! |
|
3119 |
||
3120 |
identifierExpectedIn:what |
|
3121 |
|msg| |
|
3122 |
||
3123 |
(#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[ |
|
1260
50e4668049aa
identifier expected - better error message
Claus Gittinger <cg@exept.de>
parents:
1259
diff
changeset
|
3124 |
msg := 'Reserved keyword in ' |
141 | 3125 |
] ifFalse:[ |
1260
50e4668049aa
identifier expected - better error message
Claus Gittinger <cg@exept.de>
parents:
1259
diff
changeset
|
3126 |
msg := 'Identifier expected in ' |
50e4668049aa
identifier expected - better error message
Claus Gittinger <cg@exept.de>
parents:
1259
diff
changeset
|
3127 |
]. |
50e4668049aa
identifier expected - better error message
Claus Gittinger <cg@exept.de>
parents:
1259
diff
changeset
|
3128 |
self syntaxError:(msg , what , ' (got ''' , tokenType printString, ''')') |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
3129 |
position:tokenPosition to:source position1Based - 1. |
141 | 3130 |
^ #Error |
3131 |
! |
|
3132 |
||
1259 | 3133 |
methodArgRedefined:tokenName from:pos1 to:pos2 |
3134 |
"argname reuse" |
|
3135 |
||
3136 |
self isSyntaxHighlighter ifTrue:[ |
|
3137 |
self markBadIdentifierFrom:pos1 to:pos2. |
|
3138 |
] ifFalse:[ |
|
3139 |
self |
|
3140 |
syntaxError:'redefinition of ''' , tokenName , ''' in argument list.' |
|
3141 |
position:pos1 to:pos2 |
|
3142 |
]. |
|
3143 |
! |
|
3144 |
||
0 | 3145 |
showErrorMessage:aMessage position:pos |
19 | 3146 |
"redefined since parser can give more detailed info about |
3147 |
the class & selector where the error occured." |
|
3148 |
||
71 | 3149 |
|text| |
3150 |
||
19 | 3151 |
ignoreErrors ifFalse:[ |
1160 | 3152 |
Smalltalk silentLoading == true ifFalse:[ |
3153 |
pos notNil ifTrue:[ |
|
3154 |
Transcript show:(pos printString). |
|
3155 |
Transcript show:' '. |
|
3156 |
]. |
|
3157 |
selector notNil ifTrue:[ |
|
3158 |
Transcript show:aMessage. |
|
3159 |
classToCompileFor notNil ifTrue:[ |
|
3160 |
text := ' in ' , classToCompileFor name , '>>' , selector |
|
3161 |
] ifFalse:[ |
|
3162 |
text := ' in ' , selector |
|
3163 |
] |
|
3164 |
] ifFalse:[ |
|
3165 |
classToCompileFor notNil ifTrue:[ |
|
3166 |
text := aMessage , ' (' , classToCompileFor name , ')' |
|
3167 |
] ifFalse:[ |
|
3168 |
text := aMessage |
|
3169 |
] |
|
3170 |
]. |
|
3171 |
Transcript showCR:text. |
|
3172 |
] |
|
0 | 3173 |
] |
273 | 3174 |
|
3175 |
"Modified: 18.5.1996 / 15:44:15 / cg" |
|
0 | 3176 |
! |
3177 |
||
171 | 3178 |
showErrorMessageForClass:aClass |
3179 |
"/ compiler parseError:'syntax error'. |
|
3180 |
Transcript show:' '. |
|
3181 |
aClass notNil ifTrue:[ |
|
619 | 3182 |
Transcript show:aClass name , '>>' |
171 | 3183 |
]. |
3184 |
selector notNil ifTrue:[ |
|
619 | 3185 |
Transcript show:(selector) |
171 | 3186 |
]. |
273 | 3187 |
Transcript showCR:' -> Error'. |
171 | 3188 |
|
3189 |
"Created: 13.12.1995 / 20:24:34 / cg" |
|
273 | 3190 |
"Modified: 18.5.1996 / 15:44:17 / cg" |
171 | 3191 |
! |
3192 |
||
0 | 3193 |
undefError:aName position:pos1 to:pos2 |
3 | 3194 |
"report an undefined variable error - return true, if it should be |
86 | 3195 |
corrected. If not corrected, only one warning is made per undefined |
3196 |
variable." |
|
3197 |
||
1400 | 3198 |
|ex doCorrect msg idx boldName| |
3199 |
||
3200 |
ex := UndefinedVariableNotification newException. |
|
3201 |
ex parser:self. |
|
3202 |
ex parameter:aName. |
|
3203 |
ex suspendedContext:thisContext. |
|
3204 |
doCorrect := ex raiseRequest. |
|
1399
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
3205 |
doCorrect notNil ifTrue:[ |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
3206 |
^ doCorrect |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
3207 |
]. |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
3208 |
|
607 | 3209 |
warnUndeclared ifFalse:[^ false]. |
915
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
3210 |
ignoreWarnings ifTrue:[^ false]. |
607 | 3211 |
|
86 | 3212 |
" |
3213 |
alredy warned about this one ? |
|
3214 |
" |
|
3215 |
warnedUndefVars notNil ifTrue:[ |
|
877 | 3216 |
(warnedUndefVars includes:aName) ifTrue:[ |
3217 |
"already warned about this one" |
|
3218 |
^ false |
|
3219 |
]. |
|
86 | 3220 |
]. |
3221 |
||
131 | 3222 |
"/ (classToCompileFor notNil |
3223 |
"/ and:[classToCompileFor superclass notNil |
|
3224 |
"/ and:[classToCompileFor superclass instanceVariableString isNil]]) ifTrue:[ |
|
132
5be56a5e90b7
added methods for silent parsing (parseMethod / parseMethodSpec)
Claus Gittinger <cg@exept.de>
parents:
131
diff
changeset
|
3225 |
"/ 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
|
3226 |
"/ ^ false |
131 | 3227 |
"/ ]. |
3228 |
||
1285 | 3229 |
boldName := aName allBold. |
3230 |
||
131 | 3231 |
(requestor isNil or:[requestor isStream]) ifTrue:[ |
877 | 3232 |
aName first isUppercase ifFalse:[ |
1285 | 3233 |
self showErrorMessage:('Error: ''' , boldName , ''' is undefined') position:pos1. |
877 | 3234 |
]. |
3235 |
doCorrect := false. |
|
86 | 3236 |
] ifFalse:[ |
877 | 3237 |
" |
3238 |
ask requestor for correct/continue/abort ... |
|
3239 |
it is supposed to raise abort or return true/false. |
|
3240 |
True return means that correction is wanted. |
|
3241 |
" |
|
1285 | 3242 |
msg := 'Warning: ''' , boldName , ''' is undefined'. |
877 | 3243 |
classToCompileFor notNil ifTrue:[ |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
3244 |
"/ is it an instance-variable marked inaccessable ? |
877 | 3245 |
|
3246 |
idx := (self classesInstVarNames) indexOf:(aName , '*') startingAt:1. |
|
3247 |
idx ~~ 0 ifTrue:[ |
|
1285 | 3248 |
msg := 'Warning: ''' , boldName , ''' is a hidden instvar (not accessable from ST-code)'. |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
3249 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
3250 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
3251 |
"/ is it an instance variable, while evaluateing for the class ? |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
3252 |
classToCompileFor isMeta ifTrue:[ |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
3253 |
(classToCompileFor soleInstance allInstVarNames includes:aName) ifTrue:[ |
1285 | 3254 |
msg := 'Warning: ''' , boldName , ''' is an instvar\(hint: you are evaluating/compiling in the classes context)' withCRs. |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
3255 |
] |
877 | 3256 |
] |
3257 |
]. |
|
3258 |
||
3259 |
doCorrect := self correctableError:msg position:pos1 to:pos2 |
|
86 | 3260 |
]. |
3261 |
||
877 | 3262 |
doCorrect == false ifTrue:[ |
3263 |
warnedUndefVars isNil ifTrue:[ |
|
3264 |
warnedUndefVars := Set new. |
|
3265 |
]. |
|
3266 |
warnedUndefVars add:aName. |
|
3 | 3267 |
]. |
0 | 3268 |
|
86 | 3269 |
^ doCorrect |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3270 |
|
607 | 3271 |
"Modified: 7.9.1997 / 02:14:36 / cg" |
1160 | 3272 |
! |
3273 |
||
3274 |
warnUnused:aNameCollection |
|
3275 |
"report an unused method variable" |
|
3276 |
||
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
3277 |
|s msg answer| |
1160 | 3278 |
|
3279 |
(ignoreErrors not and:[ignoreWarnings not and:[warnUnusedVars]]) ifTrue:[ |
|
3280 |
s := '' writeStream. |
|
1167 | 3281 |
s nextPutAll:'Unused method variable(s): '. |
1160 | 3282 |
aNameCollection asSortedCollection do:[:name| |
1427
ec344fd520ba
no need for asText when sending allBold
Claus Gittinger <cg@exept.de>
parents:
1423
diff
changeset
|
3283 |
s nextPutAll:' '; nextPutAll:name allBold. |
1160 | 3284 |
]. |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3285 |
msg := s contents. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3286 |
|
1160 | 3287 |
(requestor isNil or:[requestor isStream]) ifTrue:[ |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3288 |
self showErrorMessage:('Warning: ', msg) position:nil. |
1160 | 3289 |
] ifFalse:[ |
1167 | 3290 |
answer := requestor |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3291 |
unusedVariableWarning:msg |
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
3292 |
position:(localVarDefPosition first) to:(localVarDefPosition last) from:self. |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3293 |
|
1167 | 3294 |
answer == true ifTrue:[ |
3295 |
"/ delete the definitions ... |
|
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
3296 |
aNameCollection do:[:eachName | |
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
3297 |
self deleteDefinitionOf:eachName in:(localVarDefPosition first) to:(localVarDefPosition last). |
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
3298 |
]. |
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
3299 |
RestartCompilationSignal raise |
1167 | 3300 |
]. |
1160 | 3301 |
]. |
3302 |
]. |
|
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
3303 |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3304 |
"Modified: / 17.11.2001 / 10:30:47 / cg" |
0 | 3305 |
! ! |
3306 |
||
1363 | 3307 |
!Parser methodsFor:'evaluating expressions'! |
3308 |
||
3309 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile |
|
3310 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
3311 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
3312 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
3313 |
is non-nil, it is evaluated if an error occurs. |
|
3314 |
Finally, compile specifies if the string should be compiled down to |
|
3315 |
bytecode or instead be interpreted from the parseTree. |
|
3316 |
The first should be done for doIts etc, where a readable walkback is |
|
3317 |
required. |
|
3318 |
The latter is better done for constants, styleSheet and resource |
|
3319 |
reading and simple sends, where the overhead of compilation is bigger |
|
3320 |
than the interpretation overhead." |
|
3321 |
||
3322 |
|tree mustBackup loggedString chgStream value s sReal spc |
|
3323 |
nameSpaceQuerySignal compiler| |
|
3324 |
||
3325 |
aStringOrStream isNil ifTrue:[ |
|
3326 |
EmptySourceNotificationSignal raiseRequest. |
|
3327 |
^ nil |
|
3328 |
]. |
|
3329 |
(mustBackup := aStringOrStream isStream) ifTrue:[ |
|
3330 |
s := aStringOrStream. |
|
3331 |
] ifFalse:[ |
|
3332 |
loggedString := aStringOrStream. |
|
3333 |
s := ReadStream on:aStringOrStream. |
|
3334 |
]. |
|
3335 |
||
3336 |
self source:s. |
|
3337 |
||
3338 |
self parseForCode. |
|
3339 |
self foldConstants:nil. |
|
3340 |
self setSelf:anObject. |
|
3341 |
self setContext:aContext. |
|
3342 |
aContext notNil ifTrue:[ |
|
3343 |
self setSelf:(aContext receiver). |
|
3344 |
"/ aContext method notNil ifTrue:[ |
|
3345 |
"/ cls := aContext method mclass |
|
3346 |
"/ ]. |
|
3347 |
"/ self setClassToCompileFor:(cls ? aContext receiver class). |
|
3348 |
self setClassToCompileFor:(aContext receiver class). |
|
3349 |
]. |
|
3350 |
self notifying:requestor. |
|
3351 |
self nextToken. |
|
3352 |
self evalExitBlock:[:value | self release. ^ value]. |
|
3353 |
tree := self parseMethodBodyOrEmpty. |
|
3354 |
||
3355 |
self checkForEndOfInput. |
|
3356 |
||
3357 |
"if reading from a stream, backup for next expression" |
|
3358 |
mustBackup ifTrue:[ |
|
3359 |
self backupPosition |
|
3360 |
]. |
|
3361 |
||
3362 |
(self errorFlag or:[tree == #Error]) ifTrue:[ |
|
3363 |
failBlock notNil ifTrue:[ |
|
3364 |
^ failBlock value |
|
3365 |
]. |
|
3366 |
^ #Error |
|
3367 |
]. |
|
3368 |
||
3369 |
tree isNil ifTrue:[ |
|
3370 |
EmptySourceNotificationSignal raiseRequest. |
|
3371 |
^ nil |
|
3372 |
]. |
|
3373 |
||
3374 |
(logged |
|
3375 |
and:[loggedString notNil |
|
3376 |
and:[Smalltalk logDoits]]) ifTrue:[ |
|
3377 |
Class updateChangeFileQuerySignal query ifTrue:[ |
|
3378 |
chgStream := Class changesStream. |
|
3379 |
chgStream notNil ifTrue:[ |
|
3380 |
chgStream nextChunkPut:loggedString. |
|
3381 |
chgStream cr. |
|
3382 |
chgStream close |
|
3383 |
] |
|
3384 |
]. |
|
3385 |
Project notNil ifTrue:[ |
|
3386 |
Class updateChangeListQuerySignal query ifTrue:[ |
|
3387 |
Project addDoIt:loggedString |
|
3388 |
] |
|
3389 |
] |
|
3390 |
]. |
|
3391 |
||
3392 |
" |
|
3393 |
during the evaluation, handle nameSpace queries |
|
3394 |
from the value as defined by any namespace directive. |
|
3395 |
This, if its a class definition expression, the class will |
|
3396 |
be installed there. |
|
3397 |
" |
|
3398 |
nameSpaceQuerySignal := Class nameSpaceQuerySignal. |
|
3399 |
||
3400 |
spc := self getNameSpace. |
|
3401 |
spc isNil ifTrue:[ |
|
3402 |
(requestor respondsTo:#currentNameSpace) ifTrue:[ |
|
3403 |
spc := requestor currentNameSpace |
|
3404 |
] ifFalse:[ |
|
3405 |
spc := nameSpaceQuerySignal query. |
|
3406 |
] |
|
3407 |
]. |
|
3408 |
||
3409 |
nameSpaceQuerySignal answer:spc |
|
3410 |
do:[ |
|
3411 |
|method| |
|
3412 |
||
3413 |
" |
|
3414 |
if compile is false, or the parse tree is that of a constant, |
|
3415 |
or a variable, quickly return its value. |
|
3416 |
This is used for example, when reading simple objects |
|
3417 |
via #readFrom:. |
|
3418 |
The overhead of compiling a method is avoided in this case. |
|
3419 |
" |
|
3420 |
((SuppressDoItCompilation == true) |
|
3421 |
or:[compile not |
|
3422 |
or:[tree isConstant |
|
3423 |
or:[tree isVariable |
|
3424 |
or:[aStringOrStream isStream |
|
3425 |
or:[aContext notNil]]]]]) ifTrue:[ |
|
3426 |
^ tree evaluate |
|
3427 |
]. |
|
3428 |
||
3429 |
" |
|
3430 |
if I am the ByteCodeCompiler, |
|
3431 |
generate a dummy method, execute it and return the value. |
|
3432 |
otherwise, just evaluate the tree; slower, but not too bad ... |
|
3433 |
||
3434 |
This allows systems to be delivered without the ByteCodeCompiler, |
|
3435 |
and still evaluate expressions |
|
3436 |
(needed to read resource files or to process .rc files). |
|
3437 |
" |
|
3438 |
self == Parser ifTrue:[ |
|
3439 |
self evalExitBlock:[:value | self release. ^ value]. |
|
3440 |
value := tree evaluate. |
|
3441 |
self evalExitBlock:nil. |
|
3442 |
] ifFalse:[ |
|
3443 |
s := self correctedSource. |
|
3444 |
s isNil ifTrue:[ |
|
3445 |
aStringOrStream isStream ifTrue:[ |
|
3446 |
s := self collectedSource. "/ does not work yet ... |
|
3447 |
] ifFalse:[ |
|
3448 |
s := aStringOrStream |
|
3449 |
]. |
|
3450 |
]. |
|
3451 |
||
3452 |
"/ actually, its a block, to allow |
|
3453 |
"/ easy return ... |
|
3454 |
||
1421
dcdc178254f0
preserve lineNumbers in compiled code (evaluate)
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
3455 |
sReal := 'doIt ^[ ' , s , '\] value' withCRs. |
1363 | 3456 |
|
1366
f91f6a0a56d5
when required to compile, use Compiler instead of self class.
Claus Gittinger <cg@exept.de>
parents:
1365
diff
changeset
|
3457 |
compiler := ByteCodeCompiler new. |
1363 | 3458 |
compiler initializeFlagsFrom:self. |
3459 |
method := compiler |
|
3460 |
compile:sReal |
|
3461 |
forClass:anObject class |
|
3462 |
inCategory:'_temporary_' |
|
3463 |
notifying:requestor |
|
3464 |
install:false |
|
3465 |
skipIfSame:false |
|
3466 |
silent:true |
|
3467 |
foldConstants:false. |
|
3468 |
||
3469 |
method notNil ifTrue:[ |
|
3470 |
method ~~ #Error ifTrue:[ |
|
3471 |
" |
|
3472 |
fake: patch the source string, to what the user expects |
|
3473 |
in the browser |
|
3474 |
" |
|
1421
dcdc178254f0
preserve lineNumbers in compiled code (evaluate)
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
3475 |
method source:"' ' , "s string. |
1363 | 3476 |
" |
3477 |
dont do any just-in-time compilation on it. |
|
3478 |
" |
|
3479 |
method checked:true. |
|
3480 |
||
3481 |
value := method |
|
3482 |
valueWithReceiver:anObject |
|
3483 |
arguments:nil "/ (Array with:m) |
|
1440 | 3484 |
selector:(requestor isNil ifTrue:#'doItX' ifFalse:#'doIt') "/ #doIt: |
1363 | 3485 |
search:nil |
3486 |
sender:nil. |
|
3487 |
] ifFalse:[ |
|
3488 |
self evalExitBlock:[:value | self release. ^ value]. |
|
3489 |
value := tree evaluate. |
|
3490 |
self evalExitBlock:nil. |
|
3491 |
] |
|
3492 |
]. |
|
3493 |
] |
|
3494 |
]. |
|
3495 |
self release. |
|
3496 |
^ value |
|
3497 |
||
3498 |
"Created: / 8.2.1997 / 19:34:44 / cg" |
|
3499 |
"Modified: / 18.3.1999 / 18:25:40 / stefan" |
|
3500 |
"Modified: / 6.2.2000 / 15:01:57 / cg" |
|
3501 |
! ! |
|
3502 |
||
0 | 3503 |
!Parser methodsFor:'parsing'! |
3504 |
||
141 | 3505 |
block |
3506 |
"parse a block; return a node-tree, nil or #Error" |
|
3507 |
||
883 | 3508 |
|node args argNames arg pos pos2 lno| |
141 | 3509 |
|
3510 |
lno := tokenLineNr. |
|
3511 |
self nextToken. |
|
3512 |
(tokenType == $: ) ifTrue:[ |
|
663 | 3513 |
[tokenType == $:] whileTrue:[ |
3514 |
pos := tokenPosition. |
|
3515 |
self nextToken. |
|
1394
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3516 |
|
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3517 |
(pos == (tokenPosition - 1)) ifFalse:[ |
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3518 |
self warnPossibleIncompatibility:'space(s) between colon and identifier may be non-portable' position:pos to:tokenPosition. |
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3519 |
]. |
883 | 3520 |
(tokenType ~~ #Identifier) ifTrue:[ |
663 | 3521 |
^ self identifierExpectedIn:'block-arg declaration' |
3522 |
]. |
|
883 | 3523 |
|
3524 |
pos2 := tokenPosition + tokenName size - 1. |
|
3525 |
self markArgumentIdentifierFrom:tokenPosition to:pos2. |
|
663 | 3526 |
arg := Variable name:tokenName. |
3527 |
args isNil ifTrue:[ |
|
3528 |
args := Array with:arg. |
|
3529 |
argNames := Array with:tokenName. |
|
3530 |
] ifFalse:[ |
|
3531 |
(argNames includes:tokenName) ifTrue:[ |
|
1259 | 3532 |
self blockArgRedefined:tokenName from:tokenPosition to:pos2 |
663 | 3533 |
]. |
3534 |
args := args copyWith:arg. |
|
3535 |
argNames := argNames copyWith:tokenName. |
|
3536 |
]. |
|
1394
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3537 |
self nextToken. |
663 | 3538 |
]. |
3539 |
(tokenType ~~ $| ) ifTrue:[ |
|
3540 |
"ST-80 allows [:arg ]" |
|
3541 |
(tokenType == $] ) ifTrue:[ |
|
3542 |
node := BlockNode arguments:args home:currentBlock variables:nil. |
|
3543 |
node lineNumber:lno. |
|
3544 |
^ node |
|
3545 |
]. |
|
3546 |
self syntaxError:'| expected after block-arg declaration'. |
|
3547 |
^ #Error |
|
3548 |
]. |
|
3549 |
self nextToken |
|
141 | 3550 |
]. |
3551 |
node := self blockBody:args. |
|
3552 |
(node notNil and:[node ~~ #Error]) ifTrue:[ |
|
663 | 3553 |
node lineNumber:lno. |
141 | 3554 |
]. |
3555 |
^ node |
|
663 | 3556 |
|
3557 |
"Modified: / 31.3.1998 / 17:31:34 / cg" |
|
141 | 3558 |
! |
3559 |
||
3560 |
blockBody:args |
|
3561 |
"parse a blocks body; return a node-tree, nil or #Error" |
|
3562 |
||
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
3563 |
|stats node var vars lno pos2| |
141 | 3564 |
|
3565 |
lno := tokenLineNr. |
|
3566 |
(tokenType == $| ) ifTrue:[ |
|
668 | 3567 |
self nextToken. |
3568 |
[tokenType == $|] whileFalse:[ |
|
3569 |
(tokenType == #Identifier) ifFalse:[ |
|
3570 |
^ self identifierExpectedIn:'block-var declaration' |
|
3571 |
]. |
|
883 | 3572 |
pos2 := tokenPosition + tokenName size - 1. |
3573 |
self markLocalIdentifierFrom:tokenPosition to:pos2. |
|
668 | 3574 |
var := Variable name:tokenName. |
3575 |
vars isNil ifTrue:[ |
|
3576 |
vars := Array with:var. |
|
3577 |
] ifFalse:[ |
|
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
3578 |
(vars contains:[:var | var name = tokenName]) ifTrue:[ |
883 | 3579 |
"/ varname reuse |
3580 |
self isSyntaxHighlighter ifTrue:[ |
|
3581 |
self markBadIdentifierFrom:tokenPosition to:pos2. |
|
3582 |
] ifFalse:[ |
|
3583 |
self |
|
3584 |
parseError:'redefinition of ''' , tokenName , ''' in local variables' |
|
3585 |
position:tokenPosition to:pos2. |
|
3586 |
] |
|
668 | 3587 |
] ifFalse:[ |
3588 |
vars := vars copyWith:var. |
|
3589 |
] |
|
3590 |
]. |
|
3591 |
self nextToken. |
|
1471 | 3592 |
|
3593 |
AllowLocalVariableDeclarationWithInitializerExpression == true ifTrue:[ |
|
3594 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3595 |
self nextToken. |
|
3596 |
"/ Q: should we allow literals only, or arbitrary expressions ? |
|
3597 |
self halt:'unimplemented feature'. |
|
3598 |
] |
|
3599 |
]. |
|
3600 |
AllowDomainVariables == true ifTrue:[ |
|
3601 |
(tokenType == $() ifTrue:[ |
|
3602 |
self variableTypeDeclarationFor:var. |
|
3603 |
]. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3604 |
]. |
668 | 3605 |
]. |
3606 |
self nextToken |
|
141 | 3607 |
]. |
382 | 3608 |
|
141 | 3609 |
node := BlockNode arguments:args home:currentBlock variables:vars. |
3610 |
node lineNumber:lno. |
|
3611 |
currentBlock := node. |
|
3612 |
stats := self blockStatementList. |
|
1169
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3613 |
(stats == #Error) ifTrue:[^ #Error]. |
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3614 |
|
382 | 3615 |
lineNumberInfo == #full ifTrue:[ |
668 | 3616 |
node endLineNumber:tokenLineNr |
382 | 3617 |
]. |
141 | 3618 |
node statements:stats. |
3619 |
currentBlock := node home. |
|
3620 |
^ node |
|
382 | 3621 |
|
668 | 3622 |
"Modified: / 31.3.1998 / 22:46:09 / cg" |
141 | 3623 |
! |
3624 |
||
3625 |
blockExpression |
|
3626 |
"parse a blockExpression; return a node-tree, nil or #Error. |
|
3627 |
Not used by ST/X's parser, but added for ST-80 compatibility." |
|
3628 |
||
3629 |
tokenType ~~ $[ ifTrue:[ |
|
3630 |
self syntaxError:'[ expected'. |
|
3631 |
^ #Error. |
|
3632 |
]. |
|
3633 |
^ self block |
|
3634 |
! |
|
3635 |
||
3636 |
blockStatementList |
|
3637 |
"parse a blocks statementlist; return a node-tree, nil or #Error" |
|
3638 |
||
743
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
3639 |
|thisStatement prevStatement firstStatement eMsg| |
141 | 3640 |
|
3641 |
(tokenType == $] ) ifTrue:[^ nil]. |
|
3642 |
thisStatement := self statement. |
|
3643 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
3644 |
firstStatement := thisStatement. |
|
3645 |
[tokenType == $] ] whileFalse:[ |
|
673 | 3646 |
(tokenType == $.) ifFalse:[ |
1169
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3647 |
(tokenType == #EOF) ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
3648 |
self syntaxError:'missing '']'' in block' position:(source position1Based) to:(source position1Based). |
1169
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3649 |
^ #Error. |
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3650 |
]. |
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3651 |
|
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3652 |
(tokenType == $) ) ifTrue:[ |
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3653 |
eMsg := 'missing '']'' or bad '')'' in block' |
673 | 3654 |
] ifFalse:[ |
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3655 |
eMsg := 'missing ''.'' between statements (i.e. ''' , tokenType printString , '''-token unexpected)' |
673 | 3656 |
]. |
1169
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3657 |
self syntaxError:eMsg position:tokenPosition to:tokenPosition. |
673 | 3658 |
^ #Error |
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3659 |
]. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3660 |
prevStatement := thisStatement. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3661 |
self nextToken. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3662 |
|
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3663 |
tokenType == $] ifTrue:[ |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3664 |
" |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3665 |
*** I had a warning here (since it was not defined |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3666 |
*** in the blue-book; but PD-code contains a lot of |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3667 |
*** code with periods at the end so that the warnings |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3668 |
*** became annoying |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3669 |
|
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3670 |
self warning:'period after last statement in block'. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3671 |
" |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3672 |
self markBracketAt:tokenPosition. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3673 |
^ firstStatement |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3674 |
]. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3675 |
thisStatement := self statement. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3676 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3677 |
prevStatement nextStatement:thisStatement |
141 | 3678 |
]. |
673 | 3679 |
self markBracketAt:tokenPosition. |
141 | 3680 |
^ firstStatement |
743
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
3681 |
|
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
3682 |
"Modified: / 16.7.1998 / 20:38:25 / cg" |
141 | 3683 |
! |
3684 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3685 |
checkForEndOfInput |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3686 |
|what| |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3687 |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3688 |
(tokenType ~~ #EOF) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3689 |
"/ just for the nicer error message |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3690 |
(#(Self Nil True False Super Here) includes:tokenType) ifTrue:[ |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3691 |
self parseError:tokenName , ' unexpected (missing ''.'' or '':'' before ' , tokenName , ' ?)' |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3692 |
position:tokenPosition to:(tokenPosition + tokenName size - 1) |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3693 |
] ifFalse:[ |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3694 |
tokenType isCharacter ifTrue:[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3695 |
what := '''' , tokenType , ''''. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3696 |
] ifFalse:[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3697 |
what := tokenType printString. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3698 |
]. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3699 |
self parseError:(what , ' unexpected (missing ''.'', '':'' or selector before it ?)') |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
3700 |
position:tokenPosition to:source position1Based-1. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3701 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3702 |
^#Error |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3703 |
] |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3704 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3705 |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3706 |
checkReturnedValues |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3707 |
| returnsSelf returnsBoolean returnsNonBooleanLiteral| |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3708 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3709 |
ignoreWarnings ifTrue:[^ self]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3710 |
returnedValues isNil ifTrue:[^ self]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3711 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3712 |
returnsBoolean := returnedValues contains:[:node | node isConstant and:[node value isBoolean]]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3713 |
returnsNonBooleanLiteral := returnedValues contains:[:node | node isConstant and:[node value isBoolean not]]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3714 |
returnsSelf := returnedValues contains:[:node | node isSelf]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3715 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3716 |
returnsBoolean ifTrue:[ |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3717 |
(returnsNonBooleanLiteral or:[returnsSelf]) ifTrue:[ |
1455 | 3718 |
self |
3719 |
warning:'Possible Error Warning:\\Method returns both boolean and non-boolean values.' withCRs |
|
3720 |
position:1 to:tokenPosition |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3721 |
] |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3722 |
]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3723 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3724 |
"Created: / 17.11.2001 / 10:31:03 / cg" |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3725 |
"Modified: / 17.11.2001 / 10:34:16 / cg" |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3726 |
! |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3727 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3728 |
checkUnusedMethodVars |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3729 |
| unused| |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3730 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3731 |
ignoreWarnings ifFalse:[ |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3732 |
methodVars notNil ifTrue:[ |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3733 |
unused := methodVars select:[:var| var used ~~ true] thenCollect:[:var| var name]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3734 |
]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3735 |
unused size > 0 ifTrue:[ |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3736 |
self warnUnused:unused. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3737 |
]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3738 |
]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3739 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3740 |
"Created: / 17.11.2001 / 10:23:47 / cg" |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3741 |
! |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3742 |
|
1224
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3743 |
parseExceptionOrContextPragma |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3744 |
|pragmaType| |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3745 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3746 |
"/ < resource: has already been parsed. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3747 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3748 |
pragmaType := tokenName. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3749 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3750 |
self nextToken. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3751 |
(tokenType ~~ #Symbol) ifTrue:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3752 |
self parseError:'symbol expected'. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3753 |
^ #Error |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3754 |
]. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3755 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3756 |
((pragmaType = 'exception:' |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3757 |
and:[tokenValue == #'handle' |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3758 |
or:[tokenValue == #'raise' |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3759 |
or:[tokenValue == #'unwind']]]) |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3760 |
or:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3761 |
pragmaType = 'context:' |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3762 |
and:[(tokenValue == #'return')]]) |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3763 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3764 |
ifTrue:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3765 |
primitiveContextInfo isNil ifTrue:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3766 |
primitiveContextInfo := Set new. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3767 |
]. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3768 |
primitiveContextInfo add:(pragmaType->tokenValue). |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3769 |
] ifFalse:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3770 |
self parseError:'unrecognized exception pragma: ' , tokenValue. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3771 |
]. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3772 |
self nextToken. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3773 |
! |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3774 |
|
1006 | 3775 |
parseExpressionWithSelf:anObject notifying:someOne ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings inNameSpace:aNameSpaceOrNil |
3776 |
"parse aString as an expression with self set to anObject; |
|
3777 |
Return the parseTree (if ok), nil (for an empty string |
|
3778 |
or comment only ) or #Error (syntactic error). |
|
3779 |
||
3780 |
Errors and warnings are forwarded to someOne (usually some |
|
3781 |
codeView) which can highlight it and show a popup box, |
|
3782 |
iff ignoreErrors/ignoreWarnings is true respectively." |
|
3783 |
||
3784 |
|tree token| |
|
3785 |
||
3786 |
aNameSpaceOrNil notNil ifTrue:[ |
|
3787 |
self currentNameSpace:aNameSpaceOrNil |
|
3788 |
]. |
|
3789 |
self setSelf:anObject. |
|
3790 |
self notifying:someOne. |
|
1365 | 3791 |
self ignoreErrors:ignoreErrors. |
3792 |
self ignoreWarnings:ignoreWarnings. |
|
1006 | 3793 |
token := self nextToken. |
3794 |
(token == $^) ifTrue:[ |
|
3795 |
self nextToken. |
|
3796 |
]. |
|
3797 |
tree := self expression. |
|
3798 |
(self errorFlag or:[tree == #Error]) ifTrue:[^ #Error]. |
|
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3799 |
"/ tokenType ~~ #EOF ifTrue:[ |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3800 |
"/ self parseError:'nothing more expected' position:tokenPosition |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3801 |
"/ ]. |
1006 | 3802 |
^ tree |
3803 |
||
3804 |
"Created: / 14.12.1999 / 15:11:37 / cg" |
|
3805 |
! |
|
3806 |
||
1259 | 3807 |
parseExtendedMethodSpec |
3808 |
|pos1 pos2 var| |
|
3809 |
||
3810 |
"/ EXPERIMENTAL |
|
3811 |
false ifTrue:[ |
|
3812 |
(tokenType == #Symbol) ifTrue:[ |
|
3813 |
pos1 := tokenPosition. |
|
3814 |
selector := token asSymbol. |
|
3815 |
self nextToken. |
|
3816 |
self markMethodSelectorFrom:pos1 to:(tokenPosition-1). |
|
3817 |
endOfSelectorPosition := tokenPosition. |
|
3818 |
||
3819 |
tokenType == $( ifTrue:[ |
|
3820 |
self nextToken. |
|
3821 |
[ tokenType ~~ $) ] whileTrue:[ |
|
3822 |
||
3823 |
(tokenType ~~ #Identifier) ifTrue:[^ #Error]. |
|
3824 |
pos2 := tokenPosition+tokenName size-1. |
|
3825 |
self markArgumentIdentifierFrom:tokenPosition to:pos2. |
|
3826 |
var := Variable name:tokenName. |
|
3827 |
methodArgs isNil ifTrue:[ |
|
3828 |
methodArgs := Array with:var. |
|
3829 |
methodArgNames := Array with:tokenName |
|
3830 |
] ifFalse:[ |
|
3831 |
(methodArgNames includes:tokenName) ifTrue:[ |
|
3832 |
self methodArgRedefined:tokenName from:tokenPosition to:pos2 |
|
3833 |
]. |
|
3834 |
methodArgs := methodArgs copyWith:var. |
|
3835 |
methodArgNames := methodArgNames copyWith:tokenName |
|
3836 |
]. |
|
3837 |
self nextToken. |
|
3838 |
]. |
|
3839 |
self nextToken. |
|
3840 |
]. |
|
3841 |
||
3842 |
^ self |
|
3843 |
]. |
|
3844 |
]. |
|
3845 |
^ #Error |
|
3846 |
! |
|
3847 |
||
0 | 3848 |
parseMethod |
19 | 3849 |
"parse a method. |
3850 |
Return the parseTree or #Error. |
|
3851 |
||
3852 |
method ::= methodSpec methodBody |
|
3853 |
" |
|
0 | 3854 |
|
3855 |
|parseTree| |
|
3856 |
||
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
3857 |
"/ self nextToken. |
0 | 3858 |
(self parseMethodSpec == #Error) ifTrue:[^ #Error]. |
3859 |
parseTree := self parseMethodBody. |
|
3860 |
(parseTree == #Error) ifFalse:[ |
|
1171
0c43ce981f1b
oops - remove unused vars does not work (yet)
Claus Gittinger <cg@exept.de>
parents:
1169
diff
changeset
|
3861 |
self tree:parseTree |
0 | 3862 |
]. |
1186
014c3db76517
oops - end of input check should not be done when simply evaluating
Claus Gittinger <cg@exept.de>
parents:
1182
diff
changeset
|
3863 |
self checkForEndOfInput. |
0 | 3864 |
^ parseTree |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
3865 |
|
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
3866 |
"Modified: 20.4.1996 / 20:09:26 / cg" |
0 | 3867 |
! |
3868 |
||
19 | 3869 |
parseMethodBody |
3870 |
"parse a methods body (locals & statements). |
|
3871 |
No more tokens may follow. |
|
3872 |
Return a node-tree, or #Error |
|
3873 |
||
3874 |
methodBody ::= '<' st80Primitive '>' #EOF |
|
883 | 3875 |
| '<' st80Primitive '>' methodBodyVarSpec statementList #EOF |
19 | 3876 |
|
3877 |
" |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3878 |
|stats| |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3879 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3880 |
stats := self parseMethodBodyOrEmpty. |
19 | 3881 |
(stats == #Error) ifFalse:[ |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3882 |
self checkForEndOfInput. |
19 | 3883 |
]. |
1160 | 3884 |
ignoreWarnings ifFalse:[ |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3885 |
self checkUnusedMethodVars. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3886 |
self checkReturnedValues. |
1160 | 3887 |
]. |
19 | 3888 |
^ stats |
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
3889 |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3890 |
"Modified: / 17.11.2001 / 10:31:12 / cg" |
19 | 3891 |
! |
3892 |
||
79 | 3893 |
parseMethodBodyOrEmpty |
0 | 3894 |
"parse a methods body (locals & statements); |
19 | 3895 |
return a node-tree, nil or #Error. |
3896 |
empty (or comment only) input is accepted and returns nil. |
|
3897 |
||
3898 |
methodBodyOrNil ::= '<' st80Primitive '>' |
|
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3899 |
| '<' st80Primitive '>' methodBodyVarSpec statementList |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3900 |
| <empty> |
19 | 3901 |
" |
0 | 3902 |
|
265 | 3903 |
|stats| |
0 | 3904 |
|
3905 |
(self parseMethodBodyVarSpec == #Error) ifTrue:[^ #Error]. |
|
3906 |
||
3907 |
(tokenType ~~ #EOF) ifTrue:[ |
|
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3908 |
stats := self statementList |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3909 |
]. |
1186
014c3db76517
oops - end of input check should not be done when simply evaluating
Claus Gittinger <cg@exept.de>
parents:
1182
diff
changeset
|
3910 |
"/ (tokenType ~~ #EOF) ifTrue:[ |
014c3db76517
oops - end of input check should not be done when simply evaluating
Claus Gittinger <cg@exept.de>
parents:
1182
diff
changeset
|
3911 |
"/ self parseError:'nothing more expected here' position:tokenPosition to:tokenPosition. |
014c3db76517
oops - end of input check should not be done when simply evaluating
Claus Gittinger <cg@exept.de>
parents:
1182
diff
changeset
|
3912 |
"/ ^ #Error |
014c3db76517
oops - end of input check should not be done when simply evaluating
Claus Gittinger <cg@exept.de>
parents:
1182
diff
changeset
|
3913 |
"/ ]. |
1231 | 3914 |
(stats notNil |
3915 |
and:[stats ~~ #Error]) ifTrue:[ |
|
3916 |
stats last isReturnNode ifFalse:[ |
|
3917 |
"/ remember a returned self here. |
|
1262 | 3918 |
self rememberReturnedValue:(self selfNode) |
1231 | 3919 |
]. |
3920 |
]. |
|
0 | 3921 |
^ stats |
265 | 3922 |
|
3923 |
"Modified: 27.4.1996 / 16:57:56 / cg" |
|
0 | 3924 |
! |
3925 |
||
19 | 3926 |
parseMethodBodyVarSpec |
265 | 3927 |
"parse a methods local variable specification, handling |
3928 |
possible primitive or resourceSpecs. |
|
3929 |
. |
|
19 | 3930 |
Leave spec of locals in methodLocals as a side effect. |
3931 |
Return #Error or nil. |
|
0 | 3932 |
|
19 | 3933 |
methodBodyVarSpec ::= '|' { IDENTIFIER } '|' |
663 | 3934 |
| <empty> |
19 | 3935 |
" |
0 | 3936 |
|
883 | 3937 |
|var pos pos2 msg| |
0 | 3938 |
|
265 | 3939 |
((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[ |
663 | 3940 |
self parsePrimitiveOrResourceSpecOrEmpty. |
265 | 3941 |
]. |
3942 |
||
0 | 3943 |
(tokenType == $|) ifTrue:[ |
663 | 3944 |
"memorize position for declaration in correction" |
883 | 3945 |
|
663 | 3946 |
localVarDefPosition := tokenPosition. |
3947 |
self nextToken. |
|
3948 |
pos := tokenPosition. |
|
3949 |
[tokenType == #Identifier] whileTrue:[ |
|
883 | 3950 |
pos2 := tokenPosition + tokenName size - 1. |
3951 |
self markLocalIdentifierFrom:tokenPosition to:pos2. |
|
663 | 3952 |
var := Variable name:tokenName. |
883 | 3953 |
|
663 | 3954 |
methodVars isNil ifTrue:[ |
3955 |
methodVars := OrderedCollection with:var. |
|
3956 |
methodVarNames := OrderedCollection with:tokenName |
|
3957 |
] ifFalse:[ |
|
3958 |
(methodVarNames includes:tokenName) ifTrue:[ |
|
883 | 3959 |
"/ redefinition |
3960 |
self isSyntaxHighlighter ifTrue:[ |
|
3961 |
self markBadIdentifierFrom:tokenPosition to:pos2. |
|
3962 |
] ifFalse:[ |
|
3963 |
self |
|
3964 |
parseError:'redefinition of ''' , tokenName , ''' in local variables' |
|
3965 |
position:tokenPosition to:pos2. |
|
3966 |
] |
|
663 | 3967 |
] ifFalse:[ |
3968 |
methodVars add:var. |
|
3969 |
methodVarNames add:tokenName |
|
3970 |
] |
|
3971 |
]. |
|
883 | 3972 |
|
663 | 3973 |
methodArgNames notNil ifTrue:[ |
3974 |
(methodArgNames includes:tokenName) ifTrue:[ |
|
883 | 3975 |
self |
3976 |
warning:'local variable ''' , tokenName , ''' hides argument.' |
|
3977 |
position:tokenPosition to:pos2 |
|
663 | 3978 |
] |
3979 |
]. |
|
3980 |
self nextToken. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3981 |
|
1471 | 3982 |
AllowLocalVariableDeclarationWithInitializerExpression == true ifTrue:[ |
3983 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3984 |
self nextToken. |
|
3985 |
"/ Q: should we allow literals only, or arbitrary expressions ? |
|
3986 |
self halt:'unimplemented feature'. |
|
3987 |
] |
|
3988 |
]. |
|
3989 |
AllowDomainVariables == true ifTrue:[ |
|
3990 |
(tokenType == $() ifTrue:[ |
|
3991 |
self variableTypeDeclarationFor:var. |
|
3992 |
]. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3993 |
]. |
663 | 3994 |
pos := tokenPosition |
3995 |
]. |
|
883 | 3996 |
|
663 | 3997 |
(tokenType ~~ $|) ifTrue:[ |
3998 |
(#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[ |
|
883 | 3999 |
msg := 'Reserved keyword in local var declaration'. |
4000 |
pos2 := tokenPosition + tokenName size - 1. |
|
4001 |
self markBadIdentifierFrom:tokenPosition to:pos2. |
|
663 | 4002 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
4003 |
pos2 := source position1Based-1. |
663 | 4004 |
msg := 'Identifier or | expected in local var declaration' |
4005 |
]. |
|
883 | 4006 |
self syntaxError:msg position:tokenPosition to:pos2. |
663 | 4007 |
^ #Error |
4008 |
]. |
|
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
4009 |
localVarDefPosition := Array with:localVarDefPosition with:tokenPosition. |
663 | 4010 |
self nextToken |
0 | 4011 |
]. |
984 | 4012 |
|
1363 | 4013 |
allowSqueakExtensions ifTrue:[ |
984 | 4014 |
"/ allow for primitiveSpec after local-var decl. |
4015 |
||
4016 |
((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[ |
|
4017 |
self parsePrimitiveOrResourceSpecOrEmpty. |
|
4018 |
] |
|
4019 |
]. |
|
4020 |
||
0 | 4021 |
^ nil |
139
65eaf1a009f5
warn if method local hides method arg
Claus Gittinger <cg@exept.de>
parents:
135
diff
changeset
|
4022 |
|
663 | 4023 |
"Modified: / 31.3.1998 / 17:30:33 / cg" |
0 | 4024 |
! |
4025 |
||
141 | 4026 |
parseMethodSpec |
4027 |
"parse a methods selector & arg specification; |
|
4028 |
Set selector and methodArgs in the receiver as a side effect. |
|
4029 |
Return the receiver or #Error. |
|
4030 |
||
4031 |
methodSpec ::= { KEYWORD IDENTIFIER } |
|
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4032 |
| binaryOperator IDENTIFIER |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4033 |
| IDENTIFIER |
141 | 4034 |
" |
4035 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4036 |
|arg pos2| |
141 | 4037 |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4038 |
tokenType isNil ifTrue:[ |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4039 |
self nextToken. |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4040 |
]. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4041 |
|
141 | 4042 |
(tokenType == #Keyword) ifTrue:[ |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4043 |
selector := ''. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4044 |
[tokenType == #Keyword] whileTrue:[ |
663 | 4045 |
self markMethodSelectorFrom:tokenPosition to:(tokenPosition+tokenName size-1). |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4046 |
selector := selector , tokenName. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4047 |
self nextToken. |
883 | 4048 |
|
1259 | 4049 |
(tokenType ~~ #Identifier) ifTrue:[ |
4050 |
"/ ^ #Error]. |
|
4051 |
^ self identifierExpectedIn:'method-arg declaration' |
|
4052 |
]. |
|
4053 |
||
883 | 4054 |
pos2 := tokenPosition+tokenName size-1. |
4055 |
self markArgumentIdentifierFrom:tokenPosition to:pos2. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4056 |
arg := Variable name:tokenName. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4057 |
methodArgs isNil ifTrue:[ |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4058 |
methodArgs := Array with:arg. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4059 |
methodArgNames := Array with:tokenName |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4060 |
] ifFalse:[ |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4061 |
(methodArgNames includes:tokenName) ifTrue:[ |
1259 | 4062 |
self methodArgRedefined:tokenName from:tokenPosition to:pos2 |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4063 |
]. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4064 |
methodArgs := methodArgs copyWith:arg. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4065 |
methodArgNames := methodArgNames copyWith:tokenName |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4066 |
]. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4067 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4068 |
"/ ((tokenType == #BinaryOperator) and:[token = '#']) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4069 |
"/ self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4070 |
"/ arg domain:nil. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4071 |
"/ ]. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4072 |
]. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4073 |
selector := selector asSymbol. |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
4074 |
endOfSelectorPosition := tokenPosition. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4075 |
^ self |
141 | 4076 |
]. |
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
4077 |
|
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
4078 |
(self isValidUnarySelector:tokenType) ifTrue:[ |
663 | 4079 |
self markMethodSelectorFrom:tokenPosition to:(tokenPosition+tokenName size-1). |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4080 |
selector := tokenName asSymbol. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4081 |
self nextToken. |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
4082 |
endOfSelectorPosition := tokenPosition. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4083 |
^ self |
141 | 4084 |
]. |
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
4085 |
|
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
4086 |
"/ 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
|
4087 |
tokenType == $| ifTrue:[ |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4088 |
tokenType := #BinaryOperator. |
1103
b75a71996388
ensure that token follows tomeName & tokenValue
Claus Gittinger <cg@exept.de>
parents:
1100
diff
changeset
|
4089 |
token := tokenName := '|' |
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
4090 |
]. |
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
4091 |
|
141 | 4092 |
(tokenType == #BinaryOperator) ifTrue:[ |
663 | 4093 |
self markMethodSelectorFrom:tokenPosition to:(tokenPosition+tokenName size-1). |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4094 |
selector := tokenName asSymbol. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4095 |
self nextToken. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4096 |
(tokenType ~~ #Identifier) ifTrue:[^ #Error]. |
663 | 4097 |
self markArgumentIdentifierFrom:tokenPosition to:(tokenPosition+tokenName size-1). |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4098 |
arg := Variable name:tokenName. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4099 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4100 |
methodArgs := Array with:arg. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4101 |
methodArgNames := Array with:tokenName. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4102 |
|
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4103 |
self nextToken. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4104 |
"/ ((tokenType == #BinaryOperator) and:[token = '#']) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4105 |
"/ self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4106 |
"/ arg domain:nil. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4107 |
"/ ]. |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
4108 |
endOfSelectorPosition := tokenPosition. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4109 |
^ self |
141 | 4110 |
]. |
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
4111 |
|
1259 | 4112 |
^ self parseExtendedMethodSpec |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4113 |
|
663 | 4114 |
"Modified: / 31.3.1998 / 17:31:59 / cg" |
141 | 4115 |
! |
4116 |
||
713 | 4117 |
statement |
4118 |
"parse a statement; return a node-tree or #Error. |
|
4119 |
||
4120 |
statement ::= '^' expression |
|
4121 |
| PRIMITIVECODE |
|
4122 |
| expression |
|
4123 |
" |
|
4124 |
||
1276
f7f6e0c1aff9
code could be wrong in a primitive node
Claus Gittinger <cg@exept.de>
parents:
1275
diff
changeset
|
4125 |
|expr node lnr code| |
713 | 4126 |
|
4127 |
(tokenType == $^) ifTrue:[ |
|
837 | 4128 |
self markReturnAt:tokenPosition. |
713 | 4129 |
lnr := tokenLineNr. |
4130 |
self nextToken. |
|
4131 |
expr := self expression. |
|
4132 |
(expr == #Error) ifTrue:[^ #Error]. |
|
4133 |
node := ReturnNode expression:expr. |
|
4134 |
node home:self blockHome:currentBlock. |
|
4135 |
(lineNumberInfo == #full) ifTrue:[node lineNumber:lnr]. |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4136 |
|
1231 | 4137 |
self rememberReturnedValue:expr. |
713 | 4138 |
^ node |
4139 |
]. |
|
4140 |
||
4141 |
(tokenType == #Primitive) ifTrue:[ |
|
1276
f7f6e0c1aff9
code could be wrong in a primitive node
Claus Gittinger <cg@exept.de>
parents:
1275
diff
changeset
|
4142 |
code := tokenValue. |
713 | 4143 |
self nextToken. |
1276
f7f6e0c1aff9
code could be wrong in a primitive node
Claus Gittinger <cg@exept.de>
parents:
1275
diff
changeset
|
4144 |
node := PrimitiveNode code:code. |
713 | 4145 |
node isOptional ifFalse:[ |
4146 |
hasNonOptionalPrimitiveCode := true |
|
4147 |
]. |
|
4148 |
hasPrimitiveCode := true. |
|
4149 |
^ node |
|
4150 |
]. |
|
4151 |
||
4152 |
(tokenType == #EOF) ifTrue:[ |
|
733
6859b56d5bd2
better error message for missing ']' at end of block.
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
4153 |
currentBlock notNil ifTrue:[ |
6859b56d5bd2
better error message for missing ']' at end of block.
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
4154 |
self syntaxError:'missing '']'' at end of block'. |
6859b56d5bd2
better error message for missing ']' at end of block.
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
4155 |
] ifFalse:[ |
6859b56d5bd2
better error message for missing ']' at end of block.
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
4156 |
self syntaxError:'period after last statement'. |
6859b56d5bd2
better error message for missing ']' at end of block.
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
4157 |
]. |
713 | 4158 |
^ #Error |
4159 |
]. |
|
4160 |
||
984 | 4161 |
(tokenType == $.) ifTrue:[ |
1363 | 4162 |
allowSqueakExtensions == true ifTrue:[ |
984 | 4163 |
"/ allow empty statement |
4164 |
^ StatementNode expression:nil. |
|
4165 |
]. |
|
4166 |
]. |
|
4167 |
||
713 | 4168 |
expr := self expression. |
4169 |
(expr == #Error) ifTrue:[^ #Error]. |
|
4170 |
||
4171 |
"/ classToCompileFor notNil ifTrue:[ |
|
4172 |
"/ currentBlock isNil ifTrue:[ |
|
4173 |
"/ expr isPrimary ifTrue:[ |
|
4174 |
"/ self warning:'useless computation - missing ^ ?' |
|
4175 |
"/ ] |
|
4176 |
"/ ] |
|
4177 |
"/ ]. |
|
4178 |
||
4179 |
node := StatementNode expression:expr. |
|
4180 |
(lineNumberInfo == #full) ifTrue:[node lineNumber:lnr]. |
|
4181 |
^ node |
|
4182 |
||
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4183 |
"Modified: / 17.11.2001 / 10:22:33 / cg" |
713 | 4184 |
! |
4185 |
||
4186 |
statementList |
|
4187 |
"parse a statementlist; return a node-tree, nil or #Error. |
|
4188 |
Statements must be separated by periods. |
|
4189 |
||
4190 |
statementList ::= <statement> |
|
988 | 4191 |
| <statementList> . <statement> |
713 | 4192 |
" |
4193 |
||
4194 |
|thisStatement prevStatement firstStatement correctIt periodPos |
|
4195 |
prevExpr| |
|
4196 |
||
4197 |
thisStatement := self statement. |
|
4198 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
4199 |
firstStatement := thisStatement. |
|
4200 |
[tokenType == $.] whileTrue:[ |
|
988 | 4201 |
prevExpr := thisStatement expression. |
4202 |
(prevExpr notNil |
|
4203 |
and:[prevExpr isMessage |
|
4204 |
and:[thisStatement isReturnNode not]]) ifTrue:[ |
|
4205 |
(#(#'=' #'==') includes:prevExpr selector) ifTrue:[ |
|
4206 |
self warning:'useless computation - mistyped assignment ?' |
|
4207 |
]. |
|
4208 |
]. |
|
4209 |
||
4210 |
periodPos := tokenPosition. |
|
4211 |
self nextToken. |
|
4212 |
(tokenType == $]) ifTrue:[ |
|
4213 |
currentBlock isNil ifTrue:[ |
|
4214 |
self parseError:'block nesting error'. |
|
4215 |
errorFlag := true |
|
713 | 4216 |
" |
988 | 4217 |
*** I had a warning here (since it was not defined |
4218 |
*** in the blue-book; but PD-code contains a lot of |
|
4219 |
*** code with periods at the end so that the warnings |
|
4220 |
*** became annoying |
|
4221 |
||
4222 |
] ifFalse:[ |
|
4223 |
self warning:'period after last statement' position:periodPos |
|
713 | 4224 |
" |
988 | 4225 |
]. |
4226 |
^ firstStatement |
|
4227 |
]. |
|
4228 |
(tokenType == #EOF) ifTrue:[ |
|
4229 |
currentBlock notNil ifTrue:[ |
|
4230 |
self parseError:'block nesting error (expected '']'')'. |
|
4231 |
errorFlag := true |
|
713 | 4232 |
" |
988 | 4233 |
*** I had a warning here (since it was not defined |
4234 |
*** in the blue-book; but PD-code contains a lot of |
|
4235 |
*** code with periods at the end so that the warnings |
|
4236 |
*** became annoying |
|
4237 |
||
4238 |
] ifFalse:[ |
|
4239 |
self warning:'period after last statement' position:periodPos |
|
713 | 4240 |
" |
988 | 4241 |
]. |
4242 |
^ firstStatement |
|
4243 |
]. |
|
4244 |
||
4245 |
prevStatement := thisStatement. |
|
4246 |
prevStatement isReturnNode ifTrue:[ |
|
4247 |
self warning:'statements after return' position:tokenPosition |
|
4248 |
]. |
|
713 | 4249 |
" |
988 | 4250 |
periodPos := tokenPosition. |
4251 |
self nextToken. |
|
713 | 4252 |
" |
4253 |
||
988 | 4254 |
((tokenType == $]) or:[tokenType == #EOF]) ifTrue:[ |
4255 |
(currentBlock isNil and:[tokenType == $]]) ifTrue:[ |
|
4256 |
self parseError:'block nesting error'. |
|
4257 |
errorFlag := true |
|
4258 |
] ifFalse:[ |
|
4259 |
correctIt := self correctableError:'period after last statement in block' |
|
4260 |
position:periodPos to:(periodPos + 1). |
|
4261 |
correctIt ifTrue:[ |
|
4262 |
(self correctByDeleting == #Error) ifTrue:[ |
|
4263 |
errorFlag := true |
|
4264 |
] |
|
4265 |
] |
|
4266 |
]. |
|
4267 |
^ firstStatement |
|
4268 |
]. |
|
4269 |
thisStatement := self statement. |
|
4270 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
4271 |
prevStatement nextStatement:thisStatement |
|
713 | 4272 |
]. |
4273 |
^ firstStatement |
|
4274 |
||
4275 |
"Modified: 14.4.1997 / 20:46:46 / cg" |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4276 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4277 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4278 |
variableTypeDeclarationFor:aVariable |
1471 | 4279 |
"experimental support for Domain variables (constraint programming support): |
4280 |
a variable-declaration of the form |
|
4281 |
|var (domain) ... | |
|
4282 |
declares var as a domainVariable. |
|
4283 |
Valid domains are: |
|
4284 |
min %% max - integer range domain |
|
4285 |
Bool - boolean domain |
|
4286 |
Nat - positive integer domain |
|
4287 |
Int - integer domain |
|
4288 |
#sym1 ... #sym2 - enumerated symbolic domain |
|
4289 |
" |
|
4290 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4291 |
|min max domain enumValues| |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4292 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4293 |
(tokenType == $() ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4294 |
self syntaxError:'''('' expected' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4295 |
^ #Error |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4296 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4297 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4298 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4299 |
(tokenType == #Integer) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4300 |
min := token. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4301 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4302 |
((tokenType == #BinaryOperator) and:[token = '%%']) ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4303 |
self syntaxError:'''%%'' expected' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4304 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4305 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4306 |
(tokenType == #Integer) ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4307 |
self syntaxError:'Integer (upper bound) expected' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4308 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4309 |
max := token. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4310 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4311 |
domain := IntegerDomain min:min max:max. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4312 |
] ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4313 |
((tokenType == #Identifier) and:[token first isUppercase]) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4314 |
token = 'Bool' ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4315 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4316 |
domain := BooleanDomain new. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4317 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4318 |
token = 'Nat' ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4319 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4320 |
domain := IntegerDomain min:0 max:(SmallInteger maxVal). |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4321 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4322 |
token = 'Int' ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4323 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4324 |
domain := IntegerDomain min:(SmallInteger minVal) max:(SmallInteger maxVal). |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4325 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4326 |
] ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4327 |
((tokenType == #Symbol) or:[(tokenType == #Identifier)]) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4328 |
enumValues := OrderedCollection new. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4329 |
[((tokenType == #Symbol) or:[(tokenType == #Identifier)])] whileTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4330 |
enumValues add:token. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4331 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4332 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4333 |
domain := EnumeratedDomain new values:enumValues. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4334 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4335 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4336 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4337 |
domain isNil ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4338 |
self syntaxError:'invalid domain' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4339 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4340 |
aVariable domain:domain. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4341 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4342 |
(tokenType == $)) ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4343 |
self syntaxError:''')'' expected' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4344 |
^ #Error |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4345 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4346 |
self nextToken. |
713 | 4347 |
! ! |
4348 |
||
4349 |
!Parser methodsFor:'parsing-expressions'! |
|
4350 |
||
4351 |
array |
|
4352 |
|arr elements elem pos1| |
|
4353 |
||
4354 |
pos1 := tokenPosition. |
|
4355 |
elements := OrderedCollection new:20. |
|
4356 |
[tokenType ~~ $) ] whileTrue:[ |
|
1165
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
4357 |
elem := self arrayConstant. |
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
4358 |
|
1062 | 4359 |
"/ (elem == #Error) ifTrue:[ |
4360 |
"/ (tokenType == #EOF) ifTrue:[ |
|
4361 |
"/ self syntaxError:'unterminated array-constant; '')'' expected' |
|
4362 |
"/ position:pos1 to:tokenPosition |
|
4363 |
"/ ]. |
|
4364 |
"/ ^ #Error |
|
4365 |
"/ ]. |
|
713 | 4366 |
elem isSymbol ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
4367 |
self markSymbolFrom:tokenPosition to:(source position1Based-1). |
713 | 4368 |
]. |
4369 |
elements add:elem. |
|
4370 |
self nextToken |
|
4371 |
]. |
|
4372 |
arr := Array withAll:elements. |
|
4373 |
||
4374 |
(ArraysAreImmutable and:[ImmutableArray notNil]) ifTrue:[ |
|
4375 |
arr changeClassTo:ImmutableArray. |
|
4376 |
]. |
|
4377 |
^ arr |
|
4378 |
||
4379 |
"Modified: / 14.4.1998 / 17:03:29 / cg" |
|
4380 |
! |
|
4381 |
||
4382 |
arrayConstant |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4383 |
|val| |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4384 |
|
713 | 4385 |
(tokenType == #Nil) ifTrue:[ |
4386 |
^ nil |
|
4387 |
]. |
|
4388 |
((tokenType == #Integer) |
|
4389 |
or:[tokenType == #Float]) ifTrue:[ |
|
4390 |
^ tokenValue |
|
4391 |
]. |
|
4392 |
((tokenType == #String) |
|
4393 |
or:[tokenType == #Character]) ifTrue:[ |
|
4394 |
^ tokenValue |
|
4395 |
]. |
|
4396 |
(tokenType == #True) ifTrue:[ |
|
4397 |
^ true |
|
4398 |
]. |
|
4399 |
(tokenType == #False) ifTrue:[ |
|
4400 |
^ false |
|
4401 |
]. |
|
4402 |
(tokenType == #Error) ifTrue:[ |
|
1062 | 4403 |
^ ParseErrorSignal raise. |
713 | 4404 |
]. |
4405 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
4406 |
^ tokenName asSymbol |
|
4407 |
]. |
|
4408 |
||
4409 |
"/ some more special symbol consts ... |
|
4410 |
(tokenType == $| ) ifTrue:[ |
|
4411 |
^ #| |
|
4412 |
]. |
|
4413 |
(tokenType == #Self ) ifTrue:[ |
|
4414 |
^ #'self' |
|
4415 |
]. |
|
4416 |
(tokenType == #Super ) ifTrue:[ |
|
4417 |
^ #'super' |
|
4418 |
]. |
|
4419 |
(tokenType == #Here ) ifTrue:[ |
|
4420 |
^ #'here' |
|
4421 |
]. |
|
4422 |
(tokenType == #ThisContext ) ifTrue:[ |
|
4423 |
^ #'thisContext' |
|
4424 |
]. |
|
4425 |
||
4426 |
((tokenType == #Keyword) |
|
4427 |
or:[tokenType == #Identifier]) ifTrue:[ |
|
4428 |
^ tokenName asSymbol |
|
4429 |
]. |
|
4430 |
((tokenType == $() |
|
4431 |
or:[tokenType == #HashLeftParen]) ifTrue:[ |
|
4432 |
self nextToken. |
|
4433 |
^ self array |
|
4434 |
]. |
|
4435 |
((tokenType == $[) |
|
4436 |
or:[tokenType == #HashLeftBrack]) ifTrue:[ |
|
4437 |
self nextToken. |
|
4438 |
^ self byteArray |
|
4439 |
]. |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4440 |
(tokenType == #HashLeftBrace) ifTrue:[ |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4441 |
val := self qualifiedName. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4442 |
val := QualifiedName for:val name. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4443 |
^ val |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4444 |
]. |
713 | 4445 |
(tokenType == #Symbol) ifTrue:[ |
1066
ba626f00f709
remember symbols used in arrayConstant
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
4446 |
parseForCode ifFalse:[ |
ba626f00f709
remember symbols used in arrayConstant
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
4447 |
self rememberSymbolUsed:tokenValue. |
ba626f00f709
remember symbols used in arrayConstant
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
4448 |
]. |
713 | 4449 |
^ tokenValue |
4450 |
]. |
|
4451 |
(tokenType == #EOF) ifTrue:[ |
|
4452 |
"just for the better error-hilight; let caller handle error" |
|
1165
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
4453 |
self syntaxError:'error in array-constant; EOF unexpected'. |
1062 | 4454 |
^ ParseErrorSignal raise. |
713 | 4455 |
]. |
4456 |
self syntaxError:('error in array-constant; ' |
|
4457 |
, tokenType printString |
|
4458 |
, ' unexpected'). |
|
1062 | 4459 |
^ ParseErrorSignal raise. |
713 | 4460 |
|
4461 |
"Modified: / 14.4.1998 / 18:22:54 / cg" |
|
4462 |
! |
|
4463 |
||
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4464 |
arrayIndexingExpression |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4465 |
"parse an array index expression; this is a squeak/stx extension. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4466 |
foo[idx] is syntactic sugar for foo matrixAt:x |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4467 |
and foo[idx] := expr is syntactic sugar for foo matrixAt:x put:expr" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4468 |
|
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4469 |
|receiver argList selectorStream valNode| |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4470 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4471 |
receiver := self functionCallExpression. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4472 |
tokenType == $[ ifFalse:[^ receiver]. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4473 |
AllowArrayIndexSyntaxExtension == true ifFalse:[^ receiver.]. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4474 |
(receiver == #Error) ifTrue:[^ #Error]. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4475 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4476 |
selectorStream := WriteStream on: (String new: 32). |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4477 |
argList := OrderedCollection new. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4478 |
|
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4479 |
[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4480 |
[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4481 |
|indexNode| |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4482 |
|
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4483 |
self nextToken. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4484 |
indexNode := self primary. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4485 |
argList isEmpty ifTrue:[selectorStream nextPutAll:'_']. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4486 |
selectorStream nextPutAll:'at:'. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4487 |
argList add: indexNode. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4488 |
(tokenType == #BinaryOperator ) and:[ token = ','] |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4489 |
] whileTrue. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4490 |
|
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4491 |
tokenType == $] ifFalse:[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4492 |
self parseError:''']'' expected'. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4493 |
^ #Error |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4494 |
]. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4495 |
self nextToken. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4496 |
|
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4497 |
tokenType == $[ ifTrue:[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4498 |
receiver := MessageNode |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4499 |
receiver:receiver |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4500 |
selector:(selectorStream contents) |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4501 |
args:argList. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4502 |
selectorStream := WriteStream on: (String new: 32). |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4503 |
]. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4504 |
tokenType == $[ |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4505 |
] whileTrue. |
1411 | 4506 |
|
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4507 |
tokenType == #':=' ifTrue:[ |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4508 |
self nextToken. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4509 |
selectorStream nextPutAll:'put:'. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4510 |
valNode := self expression. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4511 |
valNode == #Error ifTrue:[ |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4512 |
^ valNode |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4513 |
]. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4514 |
"/ this was found in squeak - why make it a block ? |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4515 |
"/ (valNode isKindOf: BlockNode) ifFalse:[ |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4516 |
"/ valNode _ BlockNode new |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4517 |
"/ arguments: #() |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4518 |
"/ statements: (OrderedCollection with: valNode) |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4519 |
"/ returns: false |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4520 |
"/ from: encoder. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4521 |
"/ ]. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4522 |
argList add: valNode |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4523 |
]. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4524 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4525 |
^ MessageNode |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4526 |
receiver:receiver |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4527 |
selector:selectorStream contents |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4528 |
args:argList. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4529 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4530 |
" |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4531 |
AllowArrayIndexSyntaxExtension := true. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4532 |
AllowArrayIndexSyntaxExtension := false. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4533 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4534 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4535 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4536 |
|foo| |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4537 |
|
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4538 |
foo := Array new:10 withAll:2. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4539 |
1 + foo[1]. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4540 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4541 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4542 |
|foo| |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4543 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4544 |
foo := Array new:10. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4545 |
foo[1] := 'hello'. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4546 |
foo[2]. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4547 |
foo[1]. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4548 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4549 |
! |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4550 |
|
713 | 4551 |
binaryExpression |
4552 |
"parse a binary-expression; return a node-tree, nil or #Error" |
|
4553 |
||
1328 | 4554 |
|receiver| |
713 | 4555 |
|
4556 |
receiver := self unaryExpression. |
|
4557 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
1328 | 4558 |
^ self binaryExpressionFor:receiver |
4559 |
! |
|
4560 |
||
4561 |
binaryExpressionFor:receiverArg |
|
4562 |
"parse a binary-expression; return a node-tree, nil or #Error" |
|
4563 |
||
4564 |
|receiver theReceiver arg sel pos try lno note| |
|
4565 |
||
4566 |
receiver := receiverArg. |
|
4567 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
713 | 4568 |
|
4569 |
"special kludge: since Scanner cannot know if -digit is a binary |
|
4570 |
expression or a negative constant, handle cases here" |
|
4571 |
||
4572 |
[(tokenType == #BinaryOperator) |
|
4573 |
or:[(tokenType == $|) |
|
4574 |
or:[((tokenType == #Integer) or:[tokenType == #Float]) |
|
4575 |
and:[tokenValue < 0]]] |
|
4576 |
] whileTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4577 |
"/ kludge alarm: in a function-call argList, #, is not a binarySelector |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4578 |
inFunctionCallArgument == true ifTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4579 |
((tokenType == #BinaryOperator) and:[tokenName = ',']) ifTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4580 |
^ receiver |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4581 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4582 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4583 |
|
713 | 4584 |
pos := tokenPosition. |
4585 |
lno := tokenLineNr. |
|
4586 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4587 |
"/ kludge alarm: bar and minus are not scanned as binop |
713 | 4588 |
(tokenType == $|) ifTrue:[ |
4589 |
sel := '|'. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4590 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition. |
713 | 4591 |
self nextToken |
4592 |
] ifFalse:[ |
|
4593 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
4594 |
sel := tokenName. |
1022 | 4595 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1). |
713 | 4596 |
self nextToken |
4597 |
] ifFalse:[ |
|
4598 |
sel := '-'. |
|
1103
b75a71996388
ensure that token follows tomeName & tokenValue
Claus Gittinger <cg@exept.de>
parents:
1100
diff
changeset
|
4599 |
token := tokenValue := tokenValue negated |
713 | 4600 |
] |
4601 |
]. |
|
864 | 4602 |
self markSelector:sel from:pos to:(pos + sel size - 1) receiverNode:receiver. |
713 | 4603 |
|
4604 |
arg := self unaryExpression. |
|
4605 |
(arg == #Error) ifTrue:[^ #Error]. |
|
1061 | 4606 |
theReceiver := receiver. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4607 |
|
713 | 4608 |
try := BinaryNode receiver:receiver selector:sel arg:arg fold:foldConstants. |
4609 |
(try isMemberOf:String) ifTrue:[ |
|
4610 |
self parseError:try position:pos to:tokenPosition. |
|
4611 |
errorFlag := false. "ok, user wants it - so he'll get it" |
|
4612 |
receiver := BinaryNode receiver:receiver selector:sel arg:arg fold:nil. |
|
4613 |
] ifFalse:[ |
|
4614 |
receiver := try |
|
4615 |
]. |
|
903
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
4616 |
note := self plausibilityCheck:receiver. |
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
4617 |
note notNil ifTrue:[ |
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
4618 |
self warning:note position:pos to:tokenPosition |
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
4619 |
]. |
713 | 4620 |
receiver lineNumber:lno. |
4621 |
receiver selectorPosition:pos. |
|
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4622 |
parseForCode ifFalse:[ |
1061 | 4623 |
self rememberSelectorUsed:sel receiver:theReceiver |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4624 |
]. |
713 | 4625 |
]. |
4626 |
^ receiver |
|
4627 |
||
4628 |
"Modified: / 9.1.1998 / 19:05:18 / stefan" |
|
1022 | 4629 |
"Modified: / 19.1.2000 / 16:22:04 / cg" |
713 | 4630 |
! |
4631 |
||
4632 |
byteArray |
|
4633 |
"started with ST-80 R4 - allow byteArray constants as #[ ... ]" |
|
4634 |
||
4635 |
|bytes index limit newArray elem pos1 pos2| |
|
4636 |
||
4637 |
pos1 := tokenPosition. |
|
4638 |
bytes := ByteArray uninitializedNew:5000. |
|
4639 |
index := 0. limit := 5000. |
|
4640 |
[tokenType ~~ $] ] whileTrue:[ |
|
4641 |
pos2 := tokenPosition. |
|
4642 |
" |
|
4643 |
this is not good programming style, but speeds up |
|
4644 |
reading of huge byte arrays (i.e. stored Images ...) |
|
4645 |
" |
|
4646 |
(tokenType == #Integer) ifTrue:[ |
|
4647 |
elem := tokenValue |
|
4648 |
] ifFalse:[ |
|
4649 |
elem := self arrayConstant. |
|
4650 |
(elem == #Error) ifTrue:[ |
|
4651 |
(tokenType == #EOF) ifTrue:[ |
|
4652 |
self syntaxError:'unterminated bytearray-constant; '']'' expected' |
|
4653 |
position:pos1 to:tokenPosition |
|
4654 |
]. |
|
4655 |
^ #Error |
|
4656 |
]. |
|
4657 |
]. |
|
4658 |
((elem isMemberOf:SmallInteger) and:[elem between:0 and:255]) ifTrue:[ |
|
4659 |
index := index + 1. |
|
4660 |
bytes at:index put:elem. |
|
4661 |
index == limit ifTrue:[ |
|
4662 |
newArray := ByteArray uninitializedNew:(limit * 2). |
|
4663 |
newArray replaceFrom:1 to:limit with:bytes startingAt:1. |
|
4664 |
limit := limit * 2. |
|
4665 |
bytes := newArray |
|
4666 |
]. |
|
4667 |
] ifFalse:[ |
|
4668 |
self parseError:'invalid ByteArray element' position:pos2 to:tokenPosition - 1 |
|
4669 |
]. |
|
4670 |
self nextToken. |
|
4671 |
]. |
|
4672 |
newArray := ByteArray uninitializedNew:index. |
|
4673 |
newArray replaceFrom:1 to:index with:bytes startingAt:1. |
|
4674 |
^ newArray |
|
4675 |
! |
|
4676 |
||
4677 |
degeneratedKeywordExpressionForSelector |
|
1406 | 4678 |
"parse a keyword-expression without receiver - for the selector only. |
4679 |
Return the selector or nil (if it cannot be determined). |
|
4680 |
This is not used in normal parsing, but instead to extract the selector from a code fragment. |
|
4681 |
(for example, the system browsers 'implementors'-function uses this to extract a selector from |
|
4682 |
the selection)" |
|
713 | 4683 |
|
4684 |
|sel arg rec| |
|
4685 |
||
4686 |
(tokenType == #Keyword) ifTrue:[ |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4687 |
sel := tokenName. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4688 |
self nextToken. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4689 |
arg := self binaryExpression. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4690 |
(arg == #Error) ifTrue:[^ sel]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4691 |
[tokenType == #Keyword] whileTrue:[ |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4692 |
sel := sel , tokenName. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4693 |
self nextToken. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4694 |
arg := self binaryExpression. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4695 |
(arg == #Error) ifTrue:[^ sel]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4696 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4697 |
^ sel |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4698 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4699 |
|
1406 | 4700 |
(rec := self arrayIndexingExpression) == #Error ifTrue:[ ^ nil]. |
4701 |
sel := self degeneratedKeywordExpressionForSelector. |
|
4702 |
sel notNil ifTrue:[ ^ sel]. |
|
4703 |
||
1407 | 4704 |
rec isAssignment ifTrue:[ |
4705 |
rec := rec expression |
|
4706 |
]. |
|
1406 | 4707 |
rec isMessage ifTrue:[ |
4708 |
^ rec selector |
|
4709 |
]. |
|
4710 |
^ nil |
|
713 | 4711 |
! |
4712 |
||
4713 |
expression |
|
4714 |
"parse a cascade-expression; return a node-tree, nil or #Error. |
|
4715 |
||
4716 |
expression ::= keywordExpression |
|
4717 |
| keywordExpression cascade |
|
4718 |
||
4719 |
cascade ::= ';' expressionSendPart |
|
4720 |
| cascade ';' expressionSendPart |
|
4721 |
||
4722 |
expressionSendPart ::= { KEYWORD binaryExpression } |
|
4723 |
| BINARYOPERATOR unaryExpression |
|
4724 |
| IDENTIFIER |
|
4725 |
" |
|
4726 |
||
864 | 4727 |
|receiver arg sel args pos pos2 lno tokenEnd realReceiver positions| |
713 | 4728 |
|
4729 |
pos := tokenPosition. |
|
4730 |
receiver := self keywordExpression. |
|
4731 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
4732 |
(tokenType == $;) ifTrue:[ |
|
743
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4733 |
receiver isMessage ifFalse:[ |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4734 |
self syntaxError:'left side of cascade must be a message expression' |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4735 |
position:pos to:tokenPosition. |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4736 |
realReceiver := receiver. "/ only to allow continuing. |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4737 |
] ifTrue:[ |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4738 |
realReceiver := receiver receiver. |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4739 |
]. |
713 | 4740 |
[tokenType == $;] whileTrue:[ |
4741 |
self nextToken. |
|
4742 |
(tokenType == #Identifier) ifTrue:[ |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4743 |
tokenEnd := tokenPosition + tokenName size - 1. |
864 | 4744 |
self markSelector:tokenName from:tokenPosition to:tokenEnd receiverNode:realReceiver. |
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
4745 |
sel := tokenName. |
1022 | 4746 |
sel := self selectorCheck:tokenName for:realReceiver position:tokenPosition to:tokenEnd. |
713 | 4747 |
receiver := CascadeNode receiver:receiver selector:sel. |
4748 |
receiver lineNumber:tokenLineNr. |
|
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4749 |
parseForCode ifFalse:[ |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4750 |
self rememberSelectorUsed:sel |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4751 |
]. |
713 | 4752 |
self nextToken. |
4753 |
] ifFalse:[ |
|
4754 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4755 |
tokenEnd := tokenPosition + tokenName size - 1. |
864 | 4756 |
self markSelector:tokenName from:tokenPosition to:tokenEnd receiverNode:realReceiver. |
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
4757 |
sel := tokenName. |
1022 | 4758 |
sel := self selectorCheck:tokenName for:realReceiver position:tokenPosition to:tokenEnd. |
713 | 4759 |
lno := tokenLineNr. |
4760 |
self nextToken. |
|
4761 |
arg := self unaryExpression. |
|
4762 |
(arg == #Error) ifTrue:[^ #Error]. |
|
4763 |
receiver := CascadeNode receiver:receiver selector:sel arg:arg. |
|
4764 |
receiver lineNumber:lno. |
|
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4765 |
parseForCode ifFalse:[ |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4766 |
self rememberSelectorUsed:sel |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4767 |
]. |
713 | 4768 |
] ifFalse:[ |
4769 |
(tokenType == #Keyword) ifTrue:[ |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4770 |
tokenEnd := tokenPosition + tokenName size - 1. |
864 | 4771 |
positions := OrderedCollection with:(tokenPosition to:tokenEnd). |
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4772 |
pos := tokenPosition. |
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4773 |
pos2 := tokenEnd. |
713 | 4774 |
lno := tokenLineNr. |
4775 |
sel := tokenName. |
|
4776 |
self nextToken. |
|
4777 |
arg := self binaryExpression. |
|
4778 |
(arg == #Error) ifTrue:[^ #Error]. |
|
4779 |
args := Array with:arg. |
|
4780 |
[tokenType == #Keyword] whileTrue:[ |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4781 |
tokenEnd := tokenPosition + tokenName size - 1. |
864 | 4782 |
positions add:(tokenPosition to:tokenEnd). |
713 | 4783 |
sel := sel , tokenName. |
4784 |
self nextToken. |
|
4785 |
arg := self binaryExpression. |
|
4786 |
(arg == #Error) ifTrue:[^ #Error]. |
|
4787 |
args := args copyWith:arg. |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4788 |
pos2 := tokenEnd |
713 | 4789 |
]. |
1022 | 4790 |
sel := self selectorCheck:sel for:realReceiver position:pos to:pos2. |
864 | 4791 |
|
4792 |
positions do:[:p | |
|
4793 |
self markSelector:sel from:p start to:p stop receiverNode:realReceiver. |
|
4794 |
]. |
|
713 | 4795 |
receiver := CascadeNode receiver:receiver selector:sel args:args. |
4796 |
receiver lineNumber:lno. |
|
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4797 |
parseForCode ifFalse:[ |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4798 |
self rememberSelectorUsed:sel |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4799 |
]. |
713 | 4800 |
] ifFalse:[ |
4801 |
(tokenType == #Error) ifTrue:[^ #Error]. |
|
4802 |
self syntaxError:('invalid cascade; ' , tokenType printString , ' unexpected') |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
4803 |
position:tokenPosition to:source position1Based - 1. |
713 | 4804 |
^ #Error |
4805 |
] |
|
4806 |
] |
|
4807 |
] |
|
4808 |
]. |
|
4809 |
||
4810 |
"obscure (unspecified ?) if selector follows; Question: |
|
4811 |
||
4812 |
is |
|
4813 |
'expr sel1; sel2 sel3' |
|
4814 |
||
4815 |
to be parsed as: |
|
4816 |
(t := expr. |
|
4817 |
t sel1. |
|
4818 |
t sel2) sel3 |
|
4819 |
||
4820 |
or: |
|
4821 |
(t := expr. |
|
4822 |
t sel1. |
|
4823 |
t sel2 sel3) |
|
4824 |
" |
|
4825 |
((tokenType == #Identifier) |
|
4826 |
or:[(tokenType == #BinaryOperator) |
|
4827 |
or:[tokenType == #Keyword]]) ifTrue:[ |
|
1328 | 4828 |
self syntaxError:'ambigous cascade - please group using (...)' |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
4829 |
position:tokenPosition to:source position1Based - 1. |
713 | 4830 |
^ #Error |
1328 | 4831 |
"/ self warning: "syntaxError:" 'possibly ambigous cascade - please group using (...)' |
4832 |
"/ position:tokenPosition to:source position - 1. |
|
4833 |
"/ tokenType == #Identifier ifTrue:[ |
|
4834 |
"/ ^ self unaryExpressionFor:receiver |
|
4835 |
"/ ]. |
|
4836 |
"/ tokenType == #BinaryOperator ifTrue:[ |
|
4837 |
"/ ^ self binaryExpressionFor:receiver |
|
4838 |
"/ ]. |
|
4839 |
"/ ^ self keywordExpressionFor:receiver |
|
713 | 4840 |
] |
4841 |
]. |
|
4842 |
^ receiver |
|
4843 |
||
1022 | 4844 |
"Modified: / 19.1.2000 / 16:22:16 / cg" |
713 | 4845 |
! |
4846 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4847 |
functionCallArgList |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4848 |
|argList arg prevInFunctionCallArgument| |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4849 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4850 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4851 |
tokenType == $) ifTrue:[ self nextToken. ^ #() ]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4852 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4853 |
argList := OrderedCollection new. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4854 |
[ true ] whileTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4855 |
prevInFunctionCallArgument := inFunctionCallArgument. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4856 |
inFunctionCallArgument := true. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4857 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4858 |
arg := self expression. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4859 |
argList add:arg. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4860 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4861 |
inFunctionCallArgument := prevInFunctionCallArgument. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4862 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4863 |
tokenType == $) ifTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4864 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4865 |
^ argList |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4866 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4867 |
((tokenType == #BinaryOperator) and:[tokenName = ',']) ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4868 |
self parseError:'"," or ")" expected'. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4869 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4870 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4871 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4872 |
! |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4873 |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4874 |
functionCallExpression |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4875 |
"parse a functionCall; this is an st/x extension. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4876 |
foo(x) is syntactic sugar for foo value:x" |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4877 |
|
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
4878 |
|receiver numArgs argList evalSelectors evalSelector| |
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4879 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4880 |
receiver := self primary. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4881 |
tokenType == $( ifFalse:[^ receiver]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4882 |
AllowFunctionCallSyntaxForBlockEvaluation == true ifFalse:[^ receiver.]. |
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4883 |
(receiver == #Error) ifTrue:[^ #Error]. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4884 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4885 |
receiver isVariable ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4886 |
((receiver isMessage or:[receiver isAssignment]) and:[receiver parenthized]) ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4887 |
receiver isBlock ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4888 |
^ receiver |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4889 |
] |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4890 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4891 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4892 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4893 |
argList := self functionCallArgList. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4894 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4895 |
"/ make it a block evaluation |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4896 |
numArgs := argList size. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4897 |
numArgs == 0 ifTrue:[ |
1341 | 4898 |
^ UnaryNode receiver:receiver selector:#value |
4899 |
]. |
|
4900 |
evalSelectors := #( #'value:' |
|
4901 |
#'value:value:' |
|
4902 |
#'value:value:value:' |
|
4903 |
#'value:value:value:value:' |
|
4904 |
#'value:value:value:value:value:' |
|
4905 |
#'value:value:value:value:value:value:' |
|
4906 |
#'value:value:value:value:value:value:value:' |
|
4907 |
#'value:value:value:value:value:value:value:value:' |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4908 |
). |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4909 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4910 |
numArgs <= evalSelectors size ifTrue:[ |
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
4911 |
evalSelector := evalSelectors at:numArgs. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4912 |
^ MessageNode |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4913 |
receiver:receiver |
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
4914 |
selector:evalSelector |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4915 |
args:argList. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4916 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4917 |
"/ gen argument vector |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4918 |
^ MessageNode |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4919 |
receiver:receiver |
1341 | 4920 |
selector:#valueWithArguments: |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4921 |
args:(self genMakeArrayWith:argList). |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4922 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4923 |
" |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4924 |
AllowFunctionCallSyntaxForBlockEvaluation := true. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4925 |
" |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4926 |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4927 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4928 |
|foo| |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4929 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4930 |
foo := [:x | x + 1]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4931 |
1 + foo(1). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4932 |
foo(1). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4933 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4934 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4935 |
|addN add1| |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4936 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4937 |
addN := [:n | [:x | x + n]]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4938 |
add1 := addN(1). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4939 |
add1(10). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4940 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4941 |
"AllowFunctionCallSyntaxForBlockEvaluation := false." |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4942 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4943 |
|addN add1| |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4944 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4945 |
addN := [:n | [:x | x + n]]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4946 |
add1 := addN value:1. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4947 |
add1 value:10 |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4948 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4949 |
! |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4950 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4951 |
genMakeArrayWith:elementExpressions |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4952 |
"return a node to generate an array at runtime. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4953 |
Will generate: |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4954 |
Array with:el1 ... with:elN (if N <= 5) |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4955 |
or: |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4956 |
(Array new at:1 put:el1; ... at:N put:elN; yourself) (otherwise) |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4957 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4958 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4959 |
|numEl arrRec sel expr| |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4960 |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4961 |
arrRec := VariableNode globalNamed:#Array. |
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4962 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4963 |
numEl := elementExpressions size. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4964 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4965 |
(numEl between:1 and:8) ifTrue:[ |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4966 |
sel := #( |
1275
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
4967 |
#'with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
4968 |
#'with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
4969 |
#'with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
4970 |
#'with:with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
4971 |
#'with:with:with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
4972 |
#'with:with:with:with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
4973 |
#'with:with:with:with:with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
4974 |
#'with:with:with:with:with:with:with:with:' |
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4975 |
) at:numEl. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4976 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4977 |
^ MessageNode |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4978 |
receiver:arrRec |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4979 |
selector:sel |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4980 |
args:elementExpressions. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4981 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4982 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4983 |
"/ array creation expression ... |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4984 |
expr := MessageNode |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4985 |
receiver:arrRec |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4986 |
selector:#new: |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4987 |
arg:(ConstantNode type:#Integer value:numEl). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4988 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4989 |
numEl == 0 ifTrue:[ |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4990 |
^ expr. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4991 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4992 |
"/ followed by a bunch of #at:put: messages... |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4993 |
elementExpressions keysAndValuesDo:[:idx :e | |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4994 |
expr := (idx == 1 ifTrue:[MessageNode] ifFalse:[CascadeNode]) |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4995 |
receiver:expr |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4996 |
selector:#at:put: |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4997 |
arg1:(ConstantNode type:#Integer value:idx) |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4998 |
arg2:e |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4999 |
fold:false. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5000 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5001 |
"/ followed by a #yourself: message... |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5002 |
expr := CascadeNode |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5003 |
receiver:expr |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5004 |
selector:#yourself. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5005 |
^ expr |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5006 |
! |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5007 |
|
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5008 |
isValidUnarySelector:tokenType |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5009 |
tokenType == #Identifier ifTrue:[^true]. |
1373 | 5010 |
tokenType == #Here ifTrue:[^true]. |
5011 |
||
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5012 |
AllowReservedWordsAsSelectors == true ifTrue:[ |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5013 |
tokenType == #Self ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5014 |
tokenType == #Nil ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5015 |
tokenType == #True ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5016 |
tokenType == #False ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5017 |
tokenType == #Super ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5018 |
tokenType == #ThisContext ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5019 |
]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5020 |
^ false |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5021 |
|
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5022 |
" |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5023 |
AllowReservedWordsAsSelectors := true |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5024 |
AllowReservedWordsAsSelectors := false |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5025 |
" |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5026 |
|
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5027 |
" |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5028 |
1234 self |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5029 |
1234 nil |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5030 |
1234 true |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5031 |
1234 false |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5032 |
1234 here |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5033 |
1234 super |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5034 |
1234 thisContext |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5035 |
" |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5036 |
! |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5037 |
|
713 | 5038 |
keywordExpression |
5039 |
"parse a keyword-expression; return a node-tree, nil or #Error. |
|
5040 |
||
5041 |
keywordExpression ::= binaryexpression |
|
5042 |
| { KEYWORD-PART binaryExpression } |
|
5043 |
" |
|
5044 |
||
1328 | 5045 |
|receiver| |
5046 |
||
713 | 5047 |
receiver := self binaryExpression. |
5048 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
1328 | 5049 |
^ self keywordExpressionFor:receiver |
5050 |
! |
|
5051 |
||
5052 |
keywordExpressionFor:receiverArg |
|
5053 |
"parse a keyword-expression; return a node-tree, nil or #Error. |
|
5054 |
||
5055 |
keywordExpression ::= binaryexpression |
|
5056 |
| { KEYWORD-PART binaryExpression } |
|
5057 |
" |
|
5058 |
||
5059 |
|lastReceiver receiver sel arg args posR1 posR2 pos1 pos2 try lno note positions| |
|
5060 |
||
5061 |
receiver := receiverArg. |
|
5062 |
posR1 := tokenPosition. |
|
713 | 5063 |
(tokenType == #Keyword) ifTrue:[ |
5064 |
pos1 := posR2 := tokenPosition. |
|
5065 |
pos2 := tokenPosition + tokenName size - 1. |
|
864 | 5066 |
positions := OrderedCollection with:(pos1 to:pos2). |
713 | 5067 |
sel := tokenName. |
5068 |
lno := tokenLineNr. |
|
5069 |
self nextToken. |
|
5070 |
arg := self binaryExpression. |
|
5071 |
(arg == #Error) ifTrue:[^ #Error]. |
|
5072 |
args := Array with:arg. |
|
5073 |
[tokenType == #Keyword] whileTrue:[ |
|
5074 |
sel := sel , tokenName. |
|
5075 |
pos2 := tokenPosition + tokenName size - 1. |
|
864 | 5076 |
positions add:(tokenPosition to:pos2). |
713 | 5077 |
self nextToken. |
5078 |
arg := self binaryExpression. |
|
5079 |
(arg == #Error) ifTrue:[^ #Error]. |
|
5080 |
args := args copyWith:arg. |
|
5081 |
]. |
|
864 | 5082 |
|
5083 |
positions do:[:p | |
|
5084 |
self markSelector:sel from:p start to:p stop receiverNode:receiver. |
|
5085 |
]. |
|
1439 | 5086 |
sel := self selectorCheck:sel for:receiver positions:positions. |
864 | 5087 |
|
1149 | 5088 |
ignoreErrors ifFalse:[ |
5089 |
(Class definitionSelectors includes:sel) ifTrue:[ |
|
5090 |
receiver isVariable ifTrue:[ |
|
5091 |
receiver isUndeclared ifTrue:[ |
|
5092 |
self parseError:('undefined superclass: ' , receiver name) position:pos1 to:pos2. |
|
5093 |
]. |
|
5094 |
] |
|
5095 |
]. |
|
964
5fa44b4ff2cb
check for undeclared class when evaluating subclass
Claus Gittinger <cg@exept.de>
parents:
944
diff
changeset
|
5096 |
]. |
5fa44b4ff2cb
check for undeclared class when evaluating subclass
Claus Gittinger <cg@exept.de>
parents:
944
diff
changeset
|
5097 |
|
1065 | 5098 |
lastReceiver := receiver. |
713 | 5099 |
try := MessageNode receiver:receiver selector:sel args:args fold:foldConstants. |
5100 |
(try isMemberOf:String) ifTrue:[ |
|
5101 |
self parseError:try position:pos1 to:pos2. |
|
5102 |
errorFlag := false. "ok, user wants it - so he'll get it" |
|
5103 |
receiver := MessageNode receiver:receiver selector:sel args:args fold:nil. |
|
5104 |
] ifFalse:[ |
|
5105 |
receiver := try |
|
5106 |
]. |
|
903
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
5107 |
note := self plausibilityCheck:receiver. |
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
5108 |
note notNil ifTrue:[ |
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
5109 |
self warning:note position:pos1 to:pos2 |
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
5110 |
]. |
713 | 5111 |
receiver lineNumber:lno. |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
5112 |
parseForCode ifFalse:[ |
1065 | 5113 |
self rememberSelectorUsed:sel receiver:lastReceiver |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
5114 |
]. |
713 | 5115 |
|
1193 | 5116 |
"/ (contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[ "/ do not check this for doits |
5117 |
"/ receiver isSuper ifTrue:[ |
|
5118 |
"/ sel ~= selector ifTrue:[ |
|
5119 |
"/ self warnCommonMistake:'possible bad super message (selector should be same as in current method) ?' |
|
5120 |
"/ position:posR1 to:posR2-1 |
|
5121 |
"/ ]. |
|
5122 |
"/ ]. |
|
5123 |
"/ ]. |
|
5124 |
"/ |
|
5125 |
(sel = #and: or:[sel = #or:]) ifTrue:[ |
|
713 | 5126 |
receiver arg1 isBlock ifFalse:[ |
5127 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
|
5128 |
position:pos2+1 to:tokenPosition-1 |
|
5129 |
] |
|
5130 |
]. |
|
1193 | 5131 |
(sel = #whileTrue: or:[sel = #whileFalse:]) ifTrue:[ |
713 | 5132 |
receiver receiver isBlock ifFalse:[ |
5133 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
|
5134 |
position:posR1 to:posR2-1 |
|
5135 |
] |
|
5136 |
]. |
|
5137 |
]. |
|
5138 |
^ receiver |
|
5139 |
||
1022 | 5140 |
"Modified: / 19.1.2000 / 16:22:22 / cg" |
713 | 5141 |
! |
5142 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5143 |
nodeForMethodArg:varName |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5144 |
|varIndex var| |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5145 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5146 |
methodArgNames isNil ifTrue:[^ nil]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5147 |
varIndex := methodArgNames indexOf:varName. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5148 |
varIndex == 0 ifTrue:[^ nil]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5149 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5150 |
var := methodArgs at:varIndex. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5151 |
"/ var used:true. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5152 |
^ VariableNode type:#MethodArg |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5153 |
name:varName |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5154 |
token:var |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5155 |
index:varIndex |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5156 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5157 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5158 |
nodeForMethodVariable:varName |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5159 |
|varIndex var| |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5160 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5161 |
methodVarNames isNil ifTrue:[^ nil]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5162 |
varIndex := methodVarNames indexOf:varName. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5163 |
varIndex == 0 ifTrue:[^ nil]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5164 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5165 |
var := methodVars at:varIndex. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5166 |
var used:true. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5167 |
parseForCode ifFalse:[self rememberLocalUsed:varName]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5168 |
^ VariableNode type:#MethodVariable |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5169 |
name:varName |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5170 |
token:var |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5171 |
index:varIndex |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5172 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5173 |
|
0 | 5174 |
primary |
1028 | 5175 |
"parse a primary-expression; return a node-tree, nil or #Error. |
5176 |
This also cares for namespace-access-pathes." |
|
0 | 5177 |
|
1227 | 5178 |
|val pos node eMsg| |
924 | 5179 |
|
44 | 5180 |
(tokenType == #Self) ifTrue:[ |
1227 | 5181 |
^ self primary_self. |
5182 |
]. |
|
5183 |
||
5184 |
pos := tokenPosition. |
|
0 | 5185 |
(tokenType == #Identifier) ifTrue:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5186 |
" |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5187 |
must check for variable first, to be backward compatible |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5188 |
with other smalltalks. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5189 |
" |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5190 |
tokenName = 'here' ifTrue:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5191 |
(self variableOrError:tokenName) == #Error ifTrue:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5192 |
tokenType := #Here. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5193 |
warnSTXHereExtensionUsed ifTrue:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5194 |
self warning:'here-sends are a nonstandard feature of ST/X' |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5195 |
position:pos to:pos+3. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5196 |
" |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5197 |
only warn once |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5198 |
" |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5199 |
warnSTXHereExtensionUsed := false |
663 | 5200 |
]. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5201 |
^ self primary_here. |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5202 |
] |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5203 |
]. |
1227 | 5204 |
^ self primary_identifier |
0 | 5205 |
]. |
49 | 5206 |
|
44 | 5207 |
((tokenType == #Integer) |
120 | 5208 |
or:[(tokenType == #String) |
44 | 5209 |
or:[(tokenType == #Character) |
5210 |
or:[(tokenType == #Float) |
|
5211 |
or:[(tokenType == #Symbol)]]]]) ifTrue:[ |
|
1227 | 5212 |
^ self primary_simpleLiteral. |
0 | 5213 |
]. |
924 | 5214 |
|
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5215 |
(tokenType == #FixedPoint) ifTrue:[ |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5216 |
AllowFixedPointLiterals == true ifFalse:[ |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5217 |
self parseError:'non-Standard literal: FixedPoint. Please enable in settings.' position:pos to:tokenPosition. |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5218 |
^ #Error |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5219 |
]. |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5220 |
^ self primary_simpleLiteral. |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5221 |
]. |
0 | 5222 |
(tokenType == #Nil) ifTrue:[ |
1227 | 5223 |
^ self primary_nil. |
5224 |
]. |
|
0 | 5225 |
(tokenType == #True) ifTrue:[ |
1227 | 5226 |
^ self primary_true |
0 | 5227 |
]. |
5228 |
(tokenType == #False) ifTrue:[ |
|
1227 | 5229 |
^ self primary_false |
5230 |
]. |
|
0 | 5231 |
(tokenType == #Super) ifTrue:[ |
1227 | 5232 |
^ self primary_super. |
5233 |
]. |
|
924 | 5234 |
|
0 | 5235 |
(tokenType == #ThisContext) ifTrue:[ |
1262 | 5236 |
^ self primary_thisContext |
0 | 5237 |
]. |
924 | 5238 |
|
0 | 5239 |
(tokenType == #HashLeftParen) ifTrue:[ |
1202
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
5240 |
self inArrayLiteral:true. |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5241 |
self nextToken. |
1165
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5242 |
ParseErrorSignal handle:[:ex | |
1202
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
5243 |
self inArrayLiteral:false. |
1165
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5244 |
^ #Error |
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5245 |
] do:[ |
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5246 |
val := self array. |
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5247 |
]. |
1202
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
5248 |
self inArrayLiteral:false. |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5249 |
self nextToken. |
1003
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5250 |
(self noAssignmentAllowed:'assignment to a constant' at:pos) ifFalse:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5251 |
^ #Error |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5252 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5253 |
^ ConstantNode type:#Array value:val |
0 | 5254 |
]. |
924 | 5255 |
|
5256 |
(tokenType == #HashLeftBrace) ifTrue:[ |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
5257 |
val := self qualifiedName. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
5258 |
self nextToken. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
5259 |
^ val. |
924 | 5260 |
]. |
5261 |
||
0 | 5262 |
(tokenType == #HashLeftBrack) ifTrue:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5263 |
self nextToken. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5264 |
val := self byteArray. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5265 |
self nextToken. |
1003
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5266 |
(self noAssignmentAllowed:'assignment to a constant' at:pos) ifFalse:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5267 |
^ #Error |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5268 |
]. |
924 | 5269 |
^ ConstantNode type:#ByteArray value:val |
0 | 5270 |
]. |
432 | 5271 |
|
0 | 5272 |
(tokenType == $() ifTrue:[ |
1227 | 5273 |
^ self primary_expression. |
0 | 5274 |
]. |
924 | 5275 |
|
0 | 5276 |
(tokenType == $[ ) ifTrue:[ |
673 | 5277 |
self markBracketAt:tokenPosition. |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5278 |
val := self block. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5279 |
self nextToken. |
1003
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5280 |
(self noAssignmentAllowed:'invalid assignment' at:pos) ifFalse:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5281 |
^ #Error |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5282 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5283 |
^ val |
0 | 5284 |
]. |
19 | 5285 |
|
1262 | 5286 |
"/ EXPERIMENTAL - may be in next release |
1295 | 5287 |
AllowVariableReferences == true ifTrue:[ |
5288 |
((tokenType == #BinaryOperator) and:[token = '&']) ifTrue:[ |
|
5289 |
self nextToken. |
|
5290 |
node := self primary_identifier. |
|
5291 |
"/ generate a Reference |
|
5292 |
^ self makeReferenceFor:node |
|
5293 |
]. |
|
5294 |
]. |
|
5295 |
||
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5296 |
(tokenType == ${ ) ifTrue:[ |
1363 | 5297 |
allowSqueakExtensions == true ifFalse:[ |
1335 | 5298 |
self parseError:'non-Standard Squeak extension: Brace Computed Array. Enable in settings.' position:pos to:tokenPosition. |
1453
205e70e12abe
squeak-brace extension error is now proceedable
Claus Gittinger <cg@exept.de>
parents:
1446
diff
changeset
|
5299 |
errorFlag := false. |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5300 |
]. |
1227 | 5301 |
^ self primary_squeakComputedArray. |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5302 |
]. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5303 |
|
502
410af1c0df1d
parse primitive-primary expression
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
5304 |
(tokenType == #Primitive) ifTrue:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5305 |
self nextToken. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5306 |
node := PrimitiveNode code:tokenValue. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5307 |
hasNonOptionalPrimitiveCode := true. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5308 |
hasPrimitiveCode := true. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5309 |
^ node |
502
410af1c0df1d
parse primitive-primary expression
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
5310 |
]. |
410af1c0df1d
parse primitive-primary expression
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
5311 |
|
1227 | 5312 |
tokenType == #HashHashLeftParen ifTrue:[ |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5313 |
self halt. |
1295 | 5314 |
self nextToken. |
5315 |
AllowDolphinExtensions == true ifFalse:[ |
|
1335 | 5316 |
self parseError:'non-Standard Dolphin extension: ##(..). Enable in settings.' position:pos to:tokenPosition. |
1227 | 5317 |
^ #Error |
5318 |
]. |
|
5319 |
^ self primary_dolphinComputedLiteral. |
|
5320 |
]. |
|
1299 | 5321 |
tokenType == #ExclaLeftBrack ifTrue:[ |
1295 | 5322 |
self nextToken. |
5323 |
AllowLazyValueExtension == true ifFalse:[ |
|
1335 | 5324 |
self parseError:'non-Standard LazyValue extension. Enable in classVariable.' position:pos to:tokenPosition. |
1295 | 5325 |
^ #Error |
5326 |
]. |
|
5327 |
^ self primary_lazyValue. |
|
5328 |
]. |
|
5329 |
tokenType == #HashHash ifTrue:[ |
|
1301
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
5330 |
self warnPossibleIncompatibility:'''##'' might be interpreted differently in other smalltalk systems' position:pos to:tokenPosition. |
1295 | 5331 |
tokenType := #Symbol. |
5332 |
token := tokenValue := tokenName := '#'. |
|
5333 |
^ self primary_simpleLiteral. |
|
5334 |
]. |
|
1227 | 5335 |
|
0 | 5336 |
(tokenType == #Error) ifTrue:[^ #Error]. |
44 | 5337 |
tokenType isCharacter ifTrue:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5338 |
self syntaxError:('error in primary; ' |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5339 |
, tokenType printString , |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5340 |
' unexpected') position:tokenPosition to:tokenPosition |
0 | 5341 |
] ifFalse:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5342 |
(#(BinaryOperator Keyword) includes:tokenType) ifTrue:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5343 |
eMsg := ('error in primary; ' |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5344 |
, tokenType printString , '(' , tokenName , ') ' , |
805 | 5345 |
' unexpected (missing receiver ?)') |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5346 |
] ifFalse:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5347 |
eMsg := ('error in primary; ' |
1295 | 5348 |
, (token ? '') , ' (', tokenType printString , |
5349 |
') unexpected') |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5350 |
]. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
5351 |
self syntaxError:eMsg position:tokenPosition to:source position1Based - 1 |
0 | 5352 |
]. |
5353 |
^ #Error |
|
120 | 5354 |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5355 |
"Created: / 13.9.1995 / 12:50:50 / claus" |
1068 | 5356 |
"Modified: / 18.8.2000 / 20:51:22 / cg" |
0 | 5357 |
! |
5358 |
||
1227 | 5359 |
primary_dolphinComputedLiteral |
1273
3a9541cd8fef
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
5360 |
"parse a dolphin computed literal; return a node-tree, or raise an Error. |
3a9541cd8fef
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
5361 |
In dolphin, these are written as: ##( expression ) |
3a9541cd8fef
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
5362 |
and create a literal constant for the expressions value. |
1274 | 5363 |
Right now, only a subset is supported - Strings, ByteArrays and Characters. |
5364 |
WARNING: this is only supported to allow filing in dolphin code. |
|
5365 |
since stc cannot handle this (at the moment), you should rewrite the code |
|
5366 |
if you ever plan to stc-compile it into a shared library" |
|
1227 | 5367 |
|
5368 |
|pos expr val| |
|
5369 |
||
5370 |
pos := tokenPosition. |
|
5371 |
||
5372 |
expr := self expression. |
|
5373 |
||
5374 |
tokenType ~~ $) ifTrue:[ |
|
5375 |
self parseError:''')'' expected' position:tokenPosition. |
|
5376 |
^ #Error |
|
5377 |
]. |
|
5378 |
self nextToken. |
|
5379 |
||
5380 |
(self noAssignmentAllowed:'invalid assignment' at:pos) ifFalse:[ |
|
5381 |
^ #Error |
|
5382 |
]. |
|
5383 |
||
5384 |
val := expr evaluate. |
|
5385 |
||
5386 |
val isLiteral ifTrue:[ |
|
1272
2a429e2293d1
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1271
diff
changeset
|
5387 |
val isString ifTrue:[ |
2a429e2293d1
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1271
diff
changeset
|
5388 |
^ ConstantNode type:#String value:val |
2a429e2293d1
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1271
diff
changeset
|
5389 |
]. |
1227 | 5390 |
val isByteArray ifTrue:[ |
5391 |
^ ConstantNode type:#ByteArray value:val |
|
5392 |
]. |
|
1234 | 5393 |
val isCharacter ifTrue:[ |
5394 |
^ ConstantNode type:#Character value:val |
|
5395 |
]. |
|
1295 | 5396 |
val isInteger ifTrue:[ |
5397 |
^ ConstantNode type:#Integer value:val |
|
5398 |
]. |
|
1328 | 5399 |
val isLimitedPrecisionReal ifTrue:[ |
5400 |
^ ConstantNode type:#Float value:val |
|
5401 |
]. |
|
1295 | 5402 |
val isArray ifTrue:[ |
5403 |
^ ConstantNode type:#Array value:val |
|
5404 |
]. |
|
1227 | 5405 |
] ifFalse:[ |
5406 |
self parseError:'must be representable as a literal (for now)' position:pos. |
|
5407 |
^ #Error |
|
5408 |
]. |
|
1326 | 5409 |
self halt:'unimplemented'. |
1227 | 5410 |
"/ "/ make it an array creation expression ... |
5411 |
"/ expr := MessageNode |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5412 |
"/ receiver:(VariableNode globalNamed:#Array) |
1227 | 5413 |
"/ selector:#new: |
5414 |
"/ arg:(ConstantNode type:#Integer value:(exprList size)). |
|
5415 |
"/ |
|
5416 |
"/ exprList size == 0 ifTrue:[ |
|
5417 |
"/ ^ expr. |
|
5418 |
"/ ]. |
|
5419 |
"/ exprList keysAndValuesDo:[:idx :e | |
|
5420 |
"/ expr := (idx == 1 ifTrue:[MessageNode] ifFalse:[CascadeNode]) |
|
5421 |
"/ receiver:expr |
|
5422 |
"/ selector:#at:put: |
|
5423 |
"/ arg1:(ConstantNode type:#Integer value:idx) |
|
5424 |
"/ arg2:e |
|
5425 |
"/ fold:false. |
|
5426 |
"/ ]. |
|
5427 |
"/ expr := CascadeNode |
|
5428 |
"/ receiver:expr |
|
5429 |
"/ selector:#yourself. |
|
5430 |
"/ ^ expr |
|
5431 |
! |
|
5432 |
||
5433 |
primary_expression |
|
5434 |
"parse a parentized expression primary; return a node-tree, or raise an Error." |
|
5435 |
||
5436 |
|pos val eMsg| |
|
5437 |
||
5438 |
pos := tokenPosition. |
|
5439 |
||
5440 |
self nextToken. |
|
5441 |
val := self expression. |
|
5442 |
(val == #Error) ifTrue:[^ #Error]. |
|
5443 |
(tokenType ~~ $) ) ifTrue:[ |
|
5444 |
tokenType isCharacter ifTrue:[ |
|
5445 |
eMsg := 'missing '')'' (i.e. ''' , tokenType asString , ''' unexpected)'. |
|
5446 |
] ifFalse:[ |
|
5447 |
eMsg := 'missing '')'''. |
|
5448 |
]. |
|
5449 |
self syntaxError:eMsg withCRs position:pos to:tokenPosition. |
|
5450 |
^ #Error |
|
5451 |
]. |
|
5452 |
self nextToken. |
|
5453 |
(self noAssignmentAllowed:'invalid assignment' at:pos) ifFalse:[ |
|
5454 |
^ #Error |
|
5455 |
]. |
|
5456 |
val parenthized:true. |
|
5457 |
^ val |
|
5458 |
! |
|
5459 |
||
5460 |
primary_false |
|
5461 |
"parse a false primary; return a node-tree, or raise an Error." |
|
5462 |
||
5463 |
|pos| |
|
5464 |
||
5465 |
pos := tokenPosition. |
|
5466 |
||
5467 |
self nextToken. |
|
5468 |
(self noAssignmentAllowed:'assignment to ''false''' at:pos) ifFalse:[ |
|
5469 |
^ #Error |
|
5470 |
]. |
|
5471 |
self markBooleanConstantFrom:pos to:pos+4. |
|
5472 |
^ ConstantNode type:#False value:false |
|
5473 |
! |
|
5474 |
||
5475 |
primary_here |
|
5476 |
"parse a here primary; return a node-tree, nil or #Error." |
|
5477 |
||
5478 |
|pos| |
|
5479 |
||
5480 |
pos := tokenPosition. |
|
5481 |
||
5482 |
self nextToken. |
|
5483 |
(self noAssignmentAllowed:'assignment to pseudo variable ''here''' at:pos) ifFalse:[ |
|
5484 |
^ #Error |
|
5485 |
]. |
|
5486 |
classToCompileFor isNil ifTrue:[ |
|
5487 |
self warning:'in which class are you ?' position:pos to:(pos + 3). |
|
5488 |
]. |
|
5489 |
self markSelfFrom:pos to:pos+3. |
|
5490 |
^ SuperNode value:selfValue inClass:classToCompileFor here:true |
|
5491 |
! |
|
5492 |
||
5493 |
primary_identifier |
|
5494 |
"parse a false primary; return a node-tree, or raise an Error." |
|
5495 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5496 |
|pos1 pos2 expr varName rawName var globlName nameSpace nameSpaceGlobal |
1359 | 5497 |
t cls lnr node holder autoHow| |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5498 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5499 |
pos1 := tokenPosition. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5500 |
pos2 := tokenPosition + tokenName size - 1. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5501 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5502 |
varName := tokenName. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5503 |
|
1440 | 5504 |
(self isDoIt |
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
5505 |
and:[currentBlock isNil |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5506 |
and:[(requestor askFor:#isWorkspace) |
1359 | 5507 |
and:[(autoHow := requestor autoDefineVariables) notNil]]]) ifTrue:[ |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5508 |
var := self variableOrError:varName. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5509 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5510 |
(var == #Error) ifTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5511 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
1359 | 5512 |
autoHow == #workspace ifTrue:[ |
5513 |
holder := Workspace addWorkspaceVariable:varName. |
|
5514 |
var := VariableNode type:#WorkspaceVariable holder:holder name:varName |
|
5515 |
] ifFalse:[ |
|
5516 |
holder := self addDoItTemporary:varName. |
|
5517 |
var := VariableNode type:#DoItTemporary holder:holder name:varName |
|
5518 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5519 |
] ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5520 |
var := self correctVariable:varName atPosition:pos1 to:pos2. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5521 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5522 |
] |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5523 |
] ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5524 |
var := self variable. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5525 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5526 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5527 |
|
1227 | 5528 |
"/ errorFlag == true ifTrue:[self halt]. |
5529 |
(var == #Error) ifTrue:[ |
|
5530 |
errorFlag := true |
|
5531 |
]. |
|
5532 |
||
5533 |
(tokenType == #'::') ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5534 |
globlName := rawName := varName. |
1227 | 5535 |
|
5536 |
"is it in a namespace ?" |
|
5537 |
nameSpace := self findNameSpaceWith:globlName. |
|
5538 |
nameSpace notNil ifTrue:[ |
|
5539 |
globlName := nameSpace name , '::' , globlName |
|
5540 |
]. |
|
5541 |
||
5542 |
[tokenType == #'::'] whileTrue:[ |
|
5543 |
nameSpace := globlName. |
|
5544 |
||
5545 |
self nextToken. |
|
5546 |
(tokenType == #Identifier) ifTrue:[ |
|
5547 |
ignoreWarnings ifFalse:[ |
|
5548 |
warnSTXNameSpaceUse ifTrue:[ |
|
5549 |
self warning:'nameSpaces are a nonstandard feature of ST/X' |
|
1458 | 5550 |
doNotShowAgainAction:[ WarnSTXSpecials := false ] |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
5551 |
position:pos1 to:(source position1Based). |
1227 | 5552 |
" |
5553 |
only warn once |
|
5554 |
" |
|
5555 |
warnSTXNameSpaceUse := false |
|
5556 |
] |
|
5557 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5558 |
varName := tokenName. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5559 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5560 |
globlName := (nameSpace , '::' , varName). |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5561 |
rawName := (rawName , '::' , varName). |
1227 | 5562 |
|
5563 |
nameSpaceGlobal := Smalltalk at:nameSpace asSymbol ifAbsent:nil. |
|
5564 |
nameSpaceGlobal isNil ifTrue:[ |
|
5565 |
warnedUnknownNamespaces isNil ifTrue:[ |
|
5566 |
warnedUnknownNamespaces := Set new. |
|
5567 |
]. |
|
5568 |
(warnedUnknownNamespaces includes:nameSpace) ifFalse:[ |
|
5569 |
self warning:('unknown nameSpace: ', nameSpace) |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5570 |
position:pos1 to:tokenPosition-1. |
1227 | 5571 |
"/ self parseError:('unknown nameSpace: ', nameSpace) position:pos to:tokenPosition-1. |
5572 |
warnedUnknownNamespaces add:nameSpace. |
|
5573 |
] |
|
5574 |
] ifFalse:[ |
|
5575 |
nameSpaceGlobal isNameSpace ifTrue:[ |
|
5576 |
"/ for now: only Smalltalk is allowed |
|
5577 |
nameSpaceGlobal ~~ Smalltalk ifTrue:[ |
|
5578 |
"/ self parseError:('(currently) the only valid nameSpace is `Smalltalk''') position:pos to:tokenPosition-1. |
|
5579 |
] ifFalse:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5580 |
globlName := varName |
1227 | 5581 |
]. |
5582 |
] ifFalse:[ |
|
5583 |
nameSpaceGlobal isBehavior ifFalse:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5584 |
self parseError:('invalid nameSpace: ' , nameSpace) position:pos1 to:tokenPosition-1. |
1227 | 5585 |
] ifTrue:[ |
1391 | 5586 |
nameSpaceGlobal isLoaded ifTrue:[ |
5587 |
(nameSpaceGlobal privateClassesAt:varName asSymbol) isNil ifTrue:[ |
|
5588 |
self warning:('no private class: ' , varName , ' in class: ' , nameSpace) |
|
5589 |
position:pos1 to:tokenPosition-1. |
|
5590 |
"/ self parseError:('no private class: ' , name , ' in class: ' , nameSpace) position:pos to:tokenPosition-1. |
|
5591 |
] |
|
1227 | 5592 |
] |
5593 |
] |
|
5594 |
]. |
|
5595 |
]. |
|
5596 |
self nextToken. |
|
5597 |
]. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5598 |
var := VariableNode globalNamed:globlName. |
1227 | 5599 |
parseForCode ifFalse:[self rememberGlobalUsed:globlName]. |
5600 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5601 |
self markVariable:var from:pos1 to:pos1 + rawName size - 1. |
1227 | 5602 |
]. |
5603 |
||
5604 |
var == #Error ifTrue:[ |
|
5605 |
^ #Error |
|
5606 |
]. |
|
5607 |
||
5608 |
errorFlag ~~ true ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5609 |
self markVariable:var from:pos1 to:pos1 + varName size - 1. |
1227 | 5610 |
]. |
5611 |
(ignoreErrors or:[ignoreWarnings or:[parseForCode not]]) ifTrue:[ |
|
5612 |
errorFlag := false. |
|
5613 |
]. |
|
5614 |
||
5615 |
((tokenType ~~ $_) and:[tokenType ~~ #':=']) ifTrue:[ |
|
5616 |
parseForCode ifFalse:[ |
|
5617 |
var isInstanceVariable ifTrue:[ self rememberInstVarRead:var name]. |
|
5618 |
var isClassVariable ifTrue:[ self rememberClassVarRead:var name]. |
|
5619 |
]. |
|
5620 |
^ var |
|
5621 |
]. |
|
5622 |
||
5623 |
"/ careful: it could already be an implicit self send |
|
5624 |
ImplicitSelfSends ifTrue:[ |
|
5625 |
var isMessage ifTrue:[ |
|
5626 |
self nextToken. |
|
5627 |
expr := self expression. |
|
5628 |
self isSyntaxHighlighter ifFalse:[ |
|
5629 |
(errorFlag or:[expr == #Error]) ifTrue:[^ #Error]. |
|
5630 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5631 |
^ MessageNode receiver:(self selfNode) selector:('__' , varName , ':') asSymbol arg:expr. |
1227 | 5632 |
]. |
5633 |
]. |
|
5634 |
||
5635 |
(var ~~ #Error) ifTrue:[ |
|
5636 |
t := var type. |
|
5637 |
(t ~~ #MethodVariable) ifTrue:[ |
|
5638 |
(t == #PrivateClass) ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5639 |
self parseError:'assignment to private class' position:pos1 to:pos2. |
1227 | 5640 |
] ifFalse:[ |
5641 |
(t == #MethodArg) ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5642 |
self parseError:'assignment to method argument' position:pos1 to:pos2. |
1227 | 5643 |
] ifFalse:[ |
5644 |
(t == #BlockArg) ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5645 |
self parseError:'assignment to block argument' position:pos1 to:pos2. |
1227 | 5646 |
] ifFalse:[ |
5647 |
(t == #InstanceVariable) ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5648 |
varName := self classesInstVarNames at:(var index). |
1227 | 5649 |
|
5650 |
"/ ca once did this to `name' and wondered what happened to his class ... |
|
5651 |
"/ (not really a beginners bug, but may happen as a typo or missing local variable; |
|
5652 |
"/ and is hard to track down later) |
|
5653 |
||
5654 |
warnCommonMistakes ifTrue:[ |
|
5655 |
classToCompileFor isMeta ifTrue:[ |
|
5656 |
(classToCompileFor isSubclassOf:Class) ifTrue:[ |
|
5657 |
(Class allInstVarNames includes:(var name)) ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5658 |
self warning:'assignment to a classInstanceVariable\(see hierarchy of `Class'')' withCRs position:pos1 to:pos2. |
1227 | 5659 |
] |
5660 |
] |
|
5661 |
] |
|
5662 |
]. |
|
5663 |
parseForCode ifFalse:[ |
|
5664 |
modifiedInstVars isNil ifTrue:[ |
|
5665 |
modifiedInstVars := Set new |
|
5666 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5667 |
modifiedInstVars add:varName |
1227 | 5668 |
] |
5669 |
] ifFalse:[ |
|
5670 |
(t == #ClassVariable) ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5671 |
varName := var name. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5672 |
varName := varName copyFrom:((varName indexOf:$:) + 1). |
1227 | 5673 |
parseForCode ifFalse:[ |
5674 |
modifiedClassVars isNil ifTrue:[ |
|
5675 |
modifiedClassVars := Set new |
|
5676 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5677 |
modifiedClassVars add:varName |
1227 | 5678 |
] |
5679 |
] ifFalse:[ |
|
5680 |
(t == #GlobalVariable) ifTrue:[ |
|
5681 |
(cls := Smalltalk classNamed:var name) notNil ifTrue:[ |
|
5682 |
cls name = var name ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5683 |
self warning:'assignment to global which refers to a class' position:pos1 to:pos2. |
1227 | 5684 |
] |
5685 |
]. |
|
5686 |
parseForCode ifFalse:[ |
|
5687 |
modifiedGlobals isNil ifTrue:[ |
|
5688 |
modifiedGlobals := Set new |
|
5689 |
]. |
|
5690 |
modifiedGlobals add:var name |
|
5691 |
] |
|
5692 |
] |
|
5693 |
] |
|
5694 |
] |
|
5695 |
] |
|
5696 |
] |
|
5697 |
] |
|
5698 |
]. |
|
5699 |
t == #MethodVariable ifTrue:[ |
|
5700 |
modifiedLocalVars isNil ifTrue:[ |
|
5701 |
modifiedLocalVars := Set new. |
|
5702 |
]. |
|
5703 |
modifiedLocalVars add:var name. |
|
5704 |
]. |
|
5705 |
]. |
|
5706 |
||
5707 |
lnr := tokenLineNr. |
|
5708 |
||
5709 |
self nextToken. |
|
5710 |
pos2 := tokenPosition. |
|
5711 |
expr := self expression. |
|
5712 |
||
5713 |
"/ a typical beginner error: |
|
5714 |
"/ expr ifTrue:[ |
|
5715 |
"/ var := super |
|
5716 |
"/ ] ifFalse:[ |
|
5717 |
"/ var := something-else |
|
5718 |
"/ ]. |
|
5719 |
"/ var messageSend |
|
5720 |
"/ |
|
5721 |
"/ does not what a beginner might think. |
|
5722 |
||
5723 |
self isSyntaxHighlighter ifTrue:[ |
|
5724 |
(expr == #Error) ifTrue:[^ #Error]. |
|
5725 |
] ifFalse:[ |
|
5726 |
warnCommonMistakes ifTrue:[ |
|
5727 |
(expr ~~ #Error and:[expr isSuper]) ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5728 |
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:pos1 to:pos2. |
1227 | 5729 |
]. |
5730 |
]. |
|
5731 |
||
5732 |
(errorFlag or:[expr == #Error]) ifTrue:[^ #Error]. |
|
5733 |
expr isVariable ifTrue:[ |
|
5734 |
expr name = var name ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5735 |
self warning:('useless assignment to `' , var name, '''' ) position:pos1 to:pos2-1. |
1227 | 5736 |
]. |
5737 |
]. |
|
5738 |
]. |
|
5739 |
||
5740 |
node := AssignmentNode variable:var expression:expr. |
|
5741 |
(lineNumberInfo == #full) ifTrue:[node lineNumber:lnr]. |
|
5742 |
^ node |
|
5743 |
! |
|
5744 |
||
1295 | 5745 |
primary_lazyValue |
5746 |
|pos block expr| |
|
5747 |
||
5748 |
pos := tokenPosition. |
|
5749 |
||
5750 |
(tokenType == $: ) ifTrue:[ |
|
5751 |
self parseError:'lazyValues have no arguments' position:tokenPosition. |
|
5752 |
^ #Error |
|
5753 |
]. |
|
5754 |
||
5755 |
block := self blockBody:#(). |
|
5756 |
self nextToken. |
|
5757 |
||
5758 |
expr := MessageNode |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5759 |
receiver:(VariableNode globalNamed:#LazyValue) |
1295 | 5760 |
selector:#'block:' |
5761 |
arg:block. |
|
5762 |
^ expr |
|
5763 |
! |
|
5764 |
||
1227 | 5765 |
primary_nil |
5766 |
"parse a nil primary; return a node-tree, nil or #Error." |
|
5767 |
||
5768 |
|pos| |
|
5769 |
||
5770 |
pos := tokenPosition. |
|
5771 |
||
5772 |
self nextToken. |
|
5773 |
(self noAssignmentAllowed:'assignment to ''nil''' at:pos) ifFalse:[ |
|
5774 |
^ #Error |
|
5775 |
]. |
|
5776 |
"/ self markConstantFrom:pos to:pos+2. |
|
5777 |
nilNode isNil ifTrue:[ |
|
5778 |
nilNode := ConstantNode type:#Nil value:nil |
|
5779 |
]. |
|
5780 |
^ nilNode |
|
5781 |
! |
|
5782 |
||
5783 |
primary_self |
|
5784 |
"parse a self primary; return a node-tree, nil or #Error." |
|
5785 |
||
5786 |
|pos| |
|
5787 |
||
5788 |
pos := tokenPosition. |
|
5789 |
||
5790 |
self nextToken. |
|
5791 |
(self noAssignmentAllowed:'assignment to pseudo variable ''self''' at:pos) ifFalse:[ |
|
5792 |
^ ParseError raise |
|
5793 |
]. |
|
5794 |
self markSelfFrom:pos to:pos+3. |
|
1262 | 5795 |
^ self selfNode |
1227 | 5796 |
! |
5797 |
||
5798 |
primary_simpleLiteral |
|
5799 |
"parse a simple literal primary; return a node-tree, or raise an Error." |
|
5800 |
||
5801 |
|pos val| |
|
5802 |
||
5803 |
pos := tokenPosition. |
|
5804 |
||
5805 |
"/ |
|
5806 |
"/ ImmutableStrings are experimental |
|
5807 |
"/ |
|
5808 |
((tokenType == #String) |
|
5809 |
and:[(StringsAreImmutable == true) |
|
5810 |
and:[ImmutableString notNil]]) ifTrue:[ |
|
5811 |
tokenValue := tokenValue copy. |
|
5812 |
tokenValue changeClassTo:ImmutableString. |
|
5813 |
token := tokenValue |
|
5814 |
]. |
|
5815 |
(tokenType == #Symbol) ifTrue:[ |
|
5816 |
parseForCode ifFalse:[ |
|
5817 |
self rememberSymbolUsed:tokenValue |
|
5818 |
]. |
|
5819 |
]. |
|
5820 |
val := ConstantNode type:tokenType value:tokenValue. |
|
5821 |
||
5822 |
tokenValue isSymbol ifTrue:[ |
|
5823 |
self markSymbolFrom:tokenPosition to:tokenPosition+tokenValue size-1. |
|
5824 |
]. |
|
5825 |
||
5826 |
self nextToken. |
|
5827 |
(self noAssignmentAllowed:'assignment to a constant' at:pos) ifFalse:[ |
|
5828 |
^ #Error |
|
5829 |
]. |
|
5830 |
^ val |
|
5831 |
! |
|
5832 |
||
5833 |
primary_squeakComputedArray |
|
1274 | 5834 |
"parse a squeak computed array literal; return a node-tree, or raise an Error. |
5835 |
In squeak, these are written as: { expr1 . expr2 . ... exprN ) |
|
5836 |
and create a literalArray containing the exprI values. |
|
5837 |
WARNING: this is only supported to allow filing in squeak code. |
|
5838 |
since stc cannot handle this (at the moment), you should rewrite the code |
|
5839 |
if you ever plan to stc-compile it into a shared library" |
|
5840 |
||
1227 | 5841 |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5842 |
|pos exprList| |
1227 | 5843 |
|
5844 |
pos := tokenPosition. |
|
5845 |
||
5846 |
self nextToken. |
|
5847 |
exprList := self squeakComputedArray. |
|
1277
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
5848 |
(exprList == #Error) ifTrue:[ ^ #Error ]. |
1227 | 5849 |
|
5850 |
tokenType ~~ $} ifTrue:[ |
|
5851 |
self parseError:'''}'' expected' position:tokenPosition. |
|
5852 |
^ #Error |
|
5853 |
]. |
|
5854 |
self nextToken. |
|
5855 |
(self noAssignmentAllowed:'invalid assignment' at:pos) ifFalse:[ |
|
5856 |
^ #Error |
|
5857 |
]. |
|
5858 |
||
5859 |
"/ make it an array creation expression ... |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5860 |
^ self genMakeArrayWith:exprList |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5861 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5862 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5863 |
Compiler allowSqueakExtensions:true. |
1299 | 5864 |
" |
5865 |
||
5866 |
" |
|
5867 |
{ 1@2. 10 factorial. Date today }. |
|
5868 |
" |
|
5869 |
||
5870 |
" |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5871 |
Compiler allowSqueakExtensions:false. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5872 |
" |
1227 | 5873 |
! |
5874 |
||
5875 |
primary_super |
|
5876 |
"parse a super primary; return a node-tree, nil or #Error." |
|
5877 |
||
5878 |
|pos| |
|
5879 |
||
5880 |
pos := tokenPosition. |
|
5881 |
||
5882 |
usesSuper := true. |
|
5883 |
self nextToken. |
|
5884 |
(self noAssignmentAllowed:'assignment to pseudo variable ''super''' at:pos) ifFalse:[ |
|
5885 |
^ #Error |
|
5886 |
]. |
|
5887 |
(classToCompileFor isNil or:[classToCompileFor superclass isNil]) ifTrue:[ |
|
5888 |
self warning:'superclass is (currently ?) nil' position:pos to:(pos + 4). |
|
5889 |
]. |
|
5890 |
superNode isNil ifTrue:[ |
|
5891 |
superNode := SuperNode value:selfValue inClass:classToCompileFor |
|
5892 |
]. |
|
5893 |
self markSelfFrom:pos to:pos+4. |
|
5894 |
^ superNode |
|
5895 |
! |
|
5896 |
||
1262 | 5897 |
primary_thisContext |
5898 |
"parse a thisContext primary; return a node-tree, or raise an Error." |
|
5899 |
||
5900 |
|pos| |
|
5901 |
||
5902 |
pos := tokenPosition. |
|
5903 |
||
5904 |
self nextToken. |
|
5905 |
(self noAssignmentAllowed:'assignment to pseudo variable ''thisContext''' at:pos) ifFalse:[ |
|
5906 |
^ #Error |
|
5907 |
]. |
|
5908 |
self markIdentifierFrom:pos to:pos+10. |
|
5909 |
^ VariableNode type:#ThisContext context:contextToEvaluateIn. "/ often nil |
|
5910 |
! |
|
5911 |
||
1227 | 5912 |
primary_true |
5913 |
"parse a true primary; return a node-tree, or raise an Error." |
|
5914 |
||
5915 |
|pos| |
|
5916 |
||
5917 |
pos := tokenPosition. |
|
5918 |
||
5919 |
self nextToken. |
|
5920 |
(self noAssignmentAllowed:'assignment to ''true''' at:pos) ifFalse:[ |
|
5921 |
^ #Error |
|
5922 |
]. |
|
5923 |
self markBooleanConstantFrom:pos to:pos+3. |
|
5924 |
^ ConstantNode type:#True value:true |
|
5925 |
! |
|
5926 |
||
924 | 5927 |
qualifiedName |
5928 |
"a vw3.x (and later) feature: QualifiedName is #{ id ... id } |
|
5929 |
and mapped to a global variable here. |
|
5930 |
The initial #{ is supposed to be not yet skipped." |
|
5931 |
||
1436 | 5932 |
|elements elem pos1 nm| |
924 | 5933 |
|
5934 |
pos1 := tokenPosition. |
|
5935 |
self nextToken. |
|
5936 |
elements := OrderedCollection new. |
|
1436 | 5937 |
[ tokenType ~~ $} ] whileTrue:[ |
5938 |
(tokenType == #Identifier) ifFalse:[ |
|
5939 |
self syntaxError:'bad qualifiedName; Identifier expected' |
|
924 | 5940 |
position:pos1 to:tokenPosition |
5941 |
]. |
|
1436 | 5942 |
elem := tokenName. |
924 | 5943 |
elements add:elem. |
1028 | 5944 |
|
5945 |
self nextToken. |
|
1436 | 5946 |
tokenType = $} ifTrue:[ |
1028 | 5947 |
] ifFalse:[ |
1436 | 5948 |
tokenType == #'::' ifTrue:[ |
5949 |
"/ notice that Foo.Bar has already been scanned as Foo::Bar |
|
5950 |
"/(which is a kludge) |
|
5951 |
self nextToken. |
|
5952 |
] ifFalse:[ |
|
1028 | 5953 |
self syntaxError:'bad qualifiedName syntax; ''.'' or ''}'' expected' |
5954 |
position:pos1 to:tokenPosition. |
|
5955 |
]. |
|
5956 |
]. |
|
1436 | 5957 |
|
5958 |
"/ elem := self variable. |
|
5959 |
"/ (elem == #Error) ifTrue:[ |
|
5960 |
"/ (tokenType == #EOF) ifTrue:[ |
|
5961 |
"/ self syntaxError:'unterminated qualifiedName; ''}'' expected' |
|
5962 |
"/ position:pos1 to:tokenPosition |
|
5963 |
"/ ]. |
|
5964 |
"/ ^ #Error |
|
5965 |
"/ ]. |
|
5966 |
"/ errorFlag := false. |
|
5967 |
"/ (elem isVariable and:[elem isGlobal]) ifFalse:[ |
|
5968 |
"/ self warning:'elements of a qualifiedName should be globalIdentifiers' |
|
5969 |
"/ position:pos1 to:tokenPosition |
|
5970 |
"/ ]. |
|
5971 |
"/ elements add:elem. |
|
5972 |
"/ |
|
5973 |
"/ self nextToken. |
|
5974 |
"/ tokenType == #'::' ifTrue:[ |
|
5975 |
"/ "/ notice that Foo.Bar has already been scanned as Foo::Bar |
|
5976 |
"/ "/(which is a kludge) |
|
5977 |
"/ self nextToken. |
|
5978 |
"/ ] ifFalse:[ |
|
5979 |
"/ tokenType ~~ $} ifTrue:[ |
|
5980 |
"/ self syntaxError:'bad qualifiedName syntax; ''.'' or ''}'' expected' |
|
5981 |
"/ position:pos1 to:tokenPosition. |
|
5982 |
"/ ^ #Error |
|
5983 |
"/ ]. |
|
5984 |
"/ ]. |
|
5985 |
]. |
|
1437 | 5986 |
nm := (elements asStringWith:'::') asSymbol. |
1436 | 5987 |
^ ConstantNode type:#Symbol value:nm |
5988 |
||
5989 |
"/ elements size > 1 ifTrue:[ |
|
5990 |
"/ self syntaxError:'Sorry: qualified names are not yet implemented.'. |
|
5991 |
"/ ]. |
|
5992 |
"/ ^ elements first. |
|
924 | 5993 |
|
5994 |
"Modified: / 14.4.1998 / 17:03:29 / cg" |
|
5995 |
! |
|
5996 |
||
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5997 |
squeakComputedArray |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5998 |
|expressions elem pos1| |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5999 |
|
1275
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6000 |
tokenType == $} ifTrue:[ |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6001 |
^ #() |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6002 |
]. |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6003 |
|
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6004 |
pos1 := tokenPosition. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6005 |
expressions := OrderedCollection new:20. |
1275
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6006 |
[true] whileTrue:[ |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6007 |
elem := self expression. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6008 |
(elem == #Error) ifTrue:[ |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6009 |
(tokenType == #EOF) ifTrue:[ |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6010 |
self syntaxError:'unterminated computed-array-element; ''}'' expected' |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6011 |
position:pos1 to:tokenPosition |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6012 |
]. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6013 |
^ #Error |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6014 |
]. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6015 |
expressions add:elem. |
1277
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6016 |
tokenType == $. ifFalse:[ |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6017 |
^ expressions |
1277
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6018 |
]. |
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6019 |
self nextToken. |
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6020 |
tokenType == $} ifTrue:[ |
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6021 |
^ expressions |
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6022 |
]. |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6023 |
]. |
1275
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6024 |
"/ not reached |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6025 |
! |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6026 |
|
141 | 6027 |
unaryExpression |
6028 |
"parse a unary-expression; return a node-tree, nil or #Error" |
|
6029 |
||
1328 | 6030 |
|receiver| |
141 | 6031 |
|
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
6032 |
receiver := self arrayIndexingExpression. |
141 | 6033 |
(receiver == #Error) ifTrue:[^ #Error]. |
1328 | 6034 |
^ self unaryExpressionFor:receiver |
6035 |
! |
|
6036 |
||
6037 |
unaryExpressionFor:receiverArg |
|
6038 |
"parse a unary-expression; return a node-tree, nil or #Error" |
|
6039 |
||
6040 |
|receiver thisReceiver sel pos pos2 try note| |
|
6041 |
||
6042 |
receiver := receiverArg. |
|
6043 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
6044 |
[ self isValidUnarySelector:tokenType ] whileTrue:[ |
663 | 6045 |
pos := tokenPosition. |
6046 |
pos2 := pos + tokenName size - 1. |
|
864 | 6047 |
self markSelector:tokenName from:pos to:pos2 receiverNode:receiver. |
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
6048 |
sel := tokenName. |
1022 | 6049 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2. |
1061 | 6050 |
thisReceiver := receiver. |
663 | 6051 |
try := UnaryNode receiver:receiver selector:sel fold:foldConstants. |
6052 |
(try isMemberOf:String) ifTrue:[ |
|
6053 |
self parseError:try position:pos to:pos2. |
|
6054 |
errorFlag := false. "ok, user wants it - so he'll get it" |
|
6055 |
receiver := UnaryNode receiver:receiver selector:sel fold:nil. |
|
6056 |
] ifFalse:[ |
|
6057 |
receiver := try |
|
6058 |
]. |
|
1193 | 6059 |
note := self plausibilityCheck:receiver. |
6060 |
note notNil ifTrue:[ |
|
6061 |
self warning:note position:pos to:pos2 |
|
6062 |
]. |
|
663 | 6063 |
receiver lineNumber:tokenLineNr. |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
6064 |
parseForCode ifFalse:[ |
1061 | 6065 |
self rememberSelectorUsed:sel receiver:thisReceiver |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
6066 |
]. |
663 | 6067 |
self nextToken. |
141 | 6068 |
]. |
6069 |
^ receiver |
|
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
6070 |
|
1032
f97183aecb4e
oops - super-send-doIt in a debugger used receivers class
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
6071 |
"Modified: / 6.2.2000 / 14:54:20 / cg" |
141 | 6072 |
! |
6073 |
||
6074 |
variable |
|
1028 | 6075 |
"parse a simple (i.e. non-namespace-access path) variable; |
6076 |
return a node-tree, nil or #Error. |
|
6077 |
Does not advance to next token. |
|
6078 |
If undefined, notify error and correct if user wants to" |
|
141 | 6079 |
|
864 | 6080 |
|v pos1 pos2| |
687 | 6081 |
|
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
6082 |
v := self variableOrError:tokenName. |
664 | 6083 |
(v ~~ #Error) ifTrue:[ |
663 | 6084 |
(v isMemberOf:VariableNode) ifTrue:[ |
687 | 6085 |
self markVariable:v. |
663 | 6086 |
]. |
6087 |
^ v |
|
6088 |
]. |
|
865 | 6089 |
|
687 | 6090 |
pos1 := tokenPosition. |
864 | 6091 |
pos2 := pos1+tokenName size-1. |
6092 |
self markUnknownIdentifierFrom:pos1 to:pos2. |
|
664 | 6093 |
|
1089 | 6094 |
parseForCode == true ifTrue:[ |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
6095 |
v := self correctVariable:tokenName atPosition:pos1 to:pos2. |
1089 | 6096 |
(v ~~ #Error) ifTrue:[^ v]. |
6097 |
]. |
|
6098 |
||
6099 |
errorFlag := true. |
|
664 | 6100 |
|
141 | 6101 |
parseForCode ifFalse:[ |
1304
ade15708e7c1
undeclared variable handling was broken (to allow reference search)
penk
parents:
1301
diff
changeset
|
6102 |
self rememberGlobalUsed:(Smalltalk undeclaredPrefix) , tokenName. |
ade15708e7c1
undeclared variable handling was broken (to allow reference search)
penk
parents:
1301
diff
changeset
|
6103 |
self rememberGlobalUsed:tokenName. |
141 | 6104 |
] ifTrue:[ |
663 | 6105 |
tokenName first isLowercase ifTrue:[ |
6106 |
ImplicitSelfSends ifTrue:[ |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6107 |
^ UnaryNode receiver:(self selfNode) selector:('__' , tokenName) asSymbol. |
663 | 6108 |
]. |
6109 |
^ #Error |
|
6110 |
] |
|
141 | 6111 |
]. |
865 | 6112 |
|
869 | 6113 |
"/ self markGlobalIdentifierFrom:pos1 to:pos2. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6114 |
^ VariableNode globalNamed:tokenName |
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
6115 |
|
687 | 6116 |
"Modified: / 16.4.1998 / 18:46:45 / cg" |
141 | 6117 |
! |
6118 |
||
0 | 6119 |
variableOrError |
1028 | 6120 |
"parse a simple (i.e. non-namespace-access path) variable; |
6121 |
return a node-tree, nil or #Error. |
|
6122 |
Does not advance to next token." |
|
0 | 6123 |
|
21 | 6124 |
^ self variableOrError:tokenName |
6125 |
! |
|
6126 |
||
6127 |
variableOrError:varName |
|
1028 | 6128 |
"parse a simple (i.e. non-namespace-access path) variable; |
6129 |
return a node-tree, nil or #Error. |
|
6130 |
Does not advance to next token." |
|
21 | 6131 |
|
1351 | 6132 |
|varIndex aClass searchBlock args vars |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6133 |
tokenSymbol space classVarIndex holder node| |
0 | 6134 |
|
6135 |
"is it a block-arg or block-var ?" |
|
6136 |
searchBlock := currentBlock. |
|
6137 |
[searchBlock notNil] whileTrue:[ |
|
628 | 6138 |
vars := searchBlock variables. |
6139 |
vars notNil ifTrue:[ |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6140 |
varIndex := vars findFirst:[:aBlockVar | aBlockVar name = varName]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6141 |
varIndex ~~ 0 ifTrue:[ |
628 | 6142 |
^ VariableNode type:#BlockVariable |
6143 |
name:varName |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6144 |
token:(vars at:varIndex) |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6145 |
index:varIndex |
628 | 6146 |
block:searchBlock |
6147 |
from:currentBlock |
|
6148 |
]. |
|
6149 |
]. |
|
6150 |
||
6151 |
args := searchBlock arguments. |
|
6152 |
args notNil ifTrue:[ |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6153 |
varIndex := args findFirst:[:aBlockArg | aBlockArg name = varName]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6154 |
varIndex ~~ 0 ifTrue:[ |
628 | 6155 |
^ VariableNode type:#BlockArg |
6156 |
name:varName |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6157 |
token:(args at:varIndex) |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6158 |
index:varIndex |
628 | 6159 |
block:searchBlock |
6160 |
from:currentBlock |
|
6161 |
]. |
|
6162 |
||
6163 |
]. |
|
6164 |
||
6165 |
searchBlock := searchBlock home |
|
0 | 6166 |
]. |
6167 |
||
6168 |
"is it a method-variable ?" |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6169 |
(node := self nodeForMethodVariable:varName) notNil |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6170 |
ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6171 |
^ node |
0 | 6172 |
]. |
6173 |
||
6174 |
"is it a method-argument ?" |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6175 |
(node := self nodeForMethodArg:varName) notNil |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6176 |
ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6177 |
^ node |
0 | 6178 |
]. |
6179 |
||
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6180 |
contextToEvaluateIn notNil ifTrue:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6181 |
|con varNames| |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6182 |
|
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6183 |
"/ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6184 |
"/ search names of the context. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6185 |
"/ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6186 |
con := contextToEvaluateIn. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6187 |
[con notNil] whileTrue:[ |
1446
ac887ee4881a
** changed access to blockContexts source, args and vars -- please watch out
penk
parents:
1445
diff
changeset
|
6188 |
varNames := con argAndVarNames. |
690 | 6189 |
varNames size > 0 ifTrue:[ |
6190 |
varIndex := varNames lastIndexOf:varName. |
|
6191 |
varIndex ~~ 0 ifTrue:[ |
|
6192 |
^ VariableNode type:#ContextVariable |
|
6193 |
name:varName |
|
6194 |
context:con |
|
6195 |
index:varIndex |
|
6196 |
]. |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6197 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6198 |
con := con home. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6199 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6200 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6201 |
|
0 | 6202 |
classToCompileFor notNil ifTrue:[ |
628 | 6203 |
"is it an instance-variable ?" |
6204 |
||
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6205 |
varIndex := (self classesInstVarNames) lastIndexOf:varName. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6206 |
varIndex ~~ 0 ifTrue:[ |
628 | 6207 |
classToCompileFor isMeta ifTrue:[ |
6208 |
classVarIndex := (self classesClassVarNames) lastIndexOf:varName. |
|
6209 |
classVarIndex ~~ 0 ifTrue:[ |
|
6210 |
"/ give a warning - that maybe a common error |
|
825 | 6211 |
alreadyWarnedClassInstVarRefs isNil ifTrue:[ |
6212 |
alreadyWarnedClassInstVarRefs := Set new |
|
6213 |
]. |
|
6214 |
(alreadyWarnedClassInstVarRefs includes:varName) ifFalse:[ |
|
6215 |
self warning:('there is both a class variable and a class-instance variable named ''' , varName , '''.\\Refering to the class-instance variable here.') withCRs. |
|
6216 |
alreadyWarnedClassInstVarRefs add:varName. |
|
6217 |
]. |
|
628 | 6218 |
]. |
6219 |
]. |
|
6220 |
parseForCode ifFalse:[self rememberInstVarUsed:varName]. |
|
6221 |
^ VariableNode type:#InstanceVariable |
|
6222 |
name:varName |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6223 |
index:varIndex |
628 | 6224 |
selfValue:selfValue |
6225 |
]. |
|
6226 |
||
6227 |
"/ see if there is a corresponding classVar (for the warning) |
|
6228 |
classVarIndex := (self classesClassVarNames) lastIndexOf:varName. |
|
6229 |
||
6230 |
"/ "is it a class-instance-variable ?" |
|
6231 |
"/ |
|
6232 |
"/ Notice: |
|
6233 |
"/ it is no longer allowed to fetch class-instance variables |
|
6234 |
"/ from instance methods ... |
|
6235 |
"/ (used to be in previous ST/X versions) |
|
6236 |
"/ |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6237 |
varIndex := (self classesClassInstVarNames) lastIndexOf:varName. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6238 |
varIndex ~~ 0 ifTrue:[ |
628 | 6239 |
aClass := self inWhichClassIsClassInstVar:varName. |
6240 |
aClass notNil ifTrue:[ |
|
6241 |
classToCompileFor isMeta ifFalse:[ |
|
6242 |
classVarIndex == 0 ifTrue:[ |
|
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6243 |
"/ there is no corresponding classVar; |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6244 |
"/ wants to access classInstVar ? |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6245 |
contextToEvaluateIn notNil ifTrue:[ |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6246 |
"/ allow it in a doIt ... |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6247 |
|
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6248 |
^ VariableNode type:#ClassInstanceVariable |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6249 |
name:varName |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6250 |
index:varIndex |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6251 |
selfClass:aClass |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6252 |
]. |
628 | 6253 |
self parseError:'access to class-inst-var from inst method is not allowed'. |
6254 |
^ #Error. |
|
6255 |
] ifFalse:[ |
|
6256 |
"/ give a warning - that maybe a common error |
|
738 | 6257 |
self warning:('there is both a class variable and a class-instance variable named ''' , varName , '''.\\Refering to the class variable here (instMethods dont see classInstVars).') withCRs. |
628 | 6258 |
] |
6259 |
]. |
|
6260 |
||
6261 |
"/ OLD CODE: |
|
6262 |
"/ self warning:'access to class-inst-var from inst method will soon be no longer supported'. |
|
443
e7d0bad68d60
oops - previous versions allowed access to class-instance variables
Claus Gittinger <cg@exept.de>
parents:
432
diff
changeset
|
6263 |
"/ |
628 | 6264 |
"/ parseForCode ifFalse:[self rememberClassVarUsed:varName]. |
6265 |
"/ ^ VariableNode type:#ClassInstanceVariable |
|
6266 |
"/ name:varName |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6267 |
"/ index:varIndex |
628 | 6268 |
"/ selfClass:aClass |
6269 |
"/ ]. |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6270 |
] ifFalse:[ |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6271 |
"/ self halt:'oops - should not happen'. |
628 | 6272 |
] |
6273 |
]. |
|
6274 |
||
6275 |
"is it a class-variable ?" |
|
6276 |
||
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6277 |
varIndex := classVarIndex. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6278 |
varIndex ~~ 0 ifTrue:[ |
628 | 6279 |
aClass := self inWhichClassIsClassVar:varName. |
6280 |
aClass notNil ifTrue:[ |
|
6281 |
parseForCode ifFalse:[self rememberClassVarUsed:varName]. |
|
6282 |
^ VariableNode type:#ClassVariable class:aClass name:varName |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6283 |
]. |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6284 |
"/ self halt:'oops - should not happen'. |
628 | 6285 |
]. |
6286 |
||
6287 |
"is it a private-class ?" |
|
6288 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6289 |
aClass := self classToLookForClassVars. |
1212
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6290 |
aClass := aClass theNonMetaclass. |
628 | 6291 |
(aClass privateClassesAt:varName) notNil ifTrue:[ |
6292 |
parseForCode ifFalse:[self rememberGlobalUsed:(aClass name , '::' , varName)]. |
|
6293 |
^ VariableNode type:#PrivateClass class:aClass name:varName |
|
6294 |
]. |
|
418 | 6295 |
]. |
6296 |
||
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6297 |
"is it in a namespace ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6298 |
space := self findNameSpaceWith:varName. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6299 |
space notNil ifTrue:[ |
628 | 6300 |
space ~~ Smalltalk ifTrue:[ |
6301 |
parseForCode ifFalse:[self rememberGlobalUsed:(space name , '::' , varName)]. |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6302 |
space isNameSpace ifTrue:[ |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6303 |
^ VariableNode globalNamed:(space name , '::' , varName) |
1212
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6304 |
]. |
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6305 |
^ VariableNode type:#PrivateClass class:space name:varName |
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6306 |
]. |
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6307 |
parseForCode ifFalse:[self rememberGlobalUsed:varName]. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6308 |
^ VariableNode globalNamed:varName |
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
6309 |
]. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
6310 |
|
0 | 6311 |
"is it a global-variable ?" |
63 | 6312 |
tokenSymbol := varName asSymbolIfInterned. |
6313 |
tokenSymbol notNil ifTrue:[ |
|
628 | 6314 |
(Smalltalk includesKey:tokenSymbol) ifTrue:[ |
6315 |
parseForCode ifFalse:[self rememberGlobalUsed:varName]. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6316 |
^ VariableNode globalNamed:tokenSymbol |
628 | 6317 |
] |
0 | 6318 |
]. |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6319 |
|
877 | 6320 |
"is it a workspace variable ?" |
6321 |
(requestor notNil and:[requestor isStream not]) ifTrue:[ |
|
6322 |
"/ when parsing doits, this is done twice; |
|
6323 |
"/ first, for the parse, then as a block-code |
|
6324 |
"/ for the code. |
|
6325 |
"/ We only care for WorkspaceVars in doIts |
|
1440 | 6326 |
(self isDoIt) ifTrue:[ |
1295 | 6327 |
(Workspace notNil |
6328 |
and:[(holder := Workspace workspaceVariableAt:varName) notNil]) |
|
6329 |
ifTrue:[ |
|
6330 |
^ VariableNode type:#WorkspaceVariable holder:holder name:varName |
|
877 | 6331 |
] |
6332 |
] |
|
6333 |
]. |
|
1295 | 6334 |
"is it a doIt variable ?" |
6335 |
||
6336 |
"/ (requestor notNil and:[requestor isStream not]) ifTrue:[ |
|
6337 |
"/ when parsing doits, this is done twice; |
|
6338 |
"/ first, for the parse, then as a block-code |
|
6339 |
"/ for the code. |
|
6340 |
"/ We only care for WorkspaceVars in doIts |
|
6341 |
||
1440 | 6342 |
(self isDoIt) ifTrue:[ |
1295 | 6343 |
(doItTemporaries notNil |
6344 |
and:[(holder := doItTemporaries at:varName asSymbol ifAbsent:nil) notNil]) |
|
6345 |
ifTrue:[ |
|
6346 |
^ VariableNode type:#DoItTemporary holder:holder name:varName |
|
6347 |
] |
|
6348 |
]. |
|
6349 |
"/ ]. |
|
0 | 6350 |
^ #Error |
1212
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6351 |
"Modified: / 5.11.2001 / 16:45:35 / cg" |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6352 |
! ! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6353 |
|
1410 | 6354 |
!Parser methodsFor:'parsing-primitives & pragmas'! |
6355 |
||
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6356 |
checkForClosingAngle |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6357 |
((tokenType == #BinaryOperator) and:[tokenName = '>']) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6358 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6359 |
] ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6360 |
self parseError:'bad primitive definition (''>'' expected)'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6361 |
] |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6362 |
! |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6363 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6364 |
parseApiCallPragma |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6365 |
|cString| |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6366 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6367 |
cString := source upTo:$>. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6368 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6369 |
"/ TODO: generate that interface ... |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6370 |
^ -1 |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6371 |
! |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6372 |
|
1410 | 6373 |
parseApiPragma |
6374 |
|cString| |
|
6375 |
||
6376 |
cString := source upTo:$>. |
|
6377 |
self nextToken. |
|
6378 |
"/ TODO: generate that interface ... |
|
6379 |
^ -1 |
|
6380 |
! |
|
6381 |
||
6382 |
parseCDeclPragma |
|
6383 |
|cString cStream cParser returnType functionName argTypes| |
|
6384 |
||
6385 |
cString := source upTo:$>. |
|
6386 |
self nextToken. |
|
6387 |
cStream := cString readStream. |
|
6388 |
||
6389 |
cParser := CParser new. |
|
6390 |
cParser source:cStream scannerClass:CDeclScanner. |
|
6391 |
cParser nextToken. |
|
6392 |
returnType := cParser type. |
|
6393 |
||
6394 |
cParser tokenType ~~ #String ifTrue:[ |
|
6395 |
self parseError:'invalid cdecl - functionName expected'. |
|
6396 |
^ -1 |
|
6397 |
]. |
|
6398 |
functionName := cParser token. |
|
6399 |
cParser nextToken. |
|
6400 |
argTypes := cParser parseFunctionArgumentSpec. |
|
6401 |
self halt. |
|
6402 |
"/ TODO: generate that ffi-calling code ... |
|
6403 |
^ -1 |
|
6404 |
! |
|
6405 |
||
6406 |
parseCPragma |
|
6407 |
|cString cParser cType| |
|
6408 |
||
6409 |
cString := source upTo:$>. |
|
6410 |
self nextToken. |
|
6411 |
"/ TODO: generate that type |
|
6412 |
cParser := CParser new. |
|
6413 |
cParser source:(cString , ';'). |
|
6414 |
cParser nextToken. |
|
6415 |
cType := cParser type. |
|
6416 |
||
6417 |
primitiveResource "primitiveType" := cType. |
|
6418 |
^ -1 |
|
6419 |
! |
|
6420 |
||
6421 |
parsePrimitive |
|
6422 |
"parse an ST-80 type primitive as '< primitive: nr >'; |
|
6423 |
return primitive number or #Error. |
|
6424 |
or a Squeak-style primitive, as '< primitive: string >'; |
|
6425 |
return primitive name or #Error. |
|
6426 |
||
6427 |
Also, ST-80 style resource specs are parsed; the result is |
|
6428 |
left (as side effect) in primitiveResource. |
|
6429 |
(maybe someone else knows what to do with it ...) |
|
6430 |
Well, as we now have this mechanism, I'll use it to mark methods which |
|
6431 |
do keyboard processing ... <resource: keyboard ( keys )> |
|
6432 |
For faster finding of used keyboard accelerators, |
|
6433 |
and to mark resource methods (image, menu or canvas resources). |
|
6434 |
||
6435 |
prim ::= st80Primitive | st80Pragma | stxPragma |
|
6436 |
squeakPrimitive | newSTXPrimitive | resourceDecl |
|
6437 |
||
6438 |
st80Primitive ::= 'primitive:' INTEGER |
|
6439 |
st80Pragma ::= 'exception:' ( 'handle | 'raise' | 'unwind' ) |
|
6440 |
stxPragma ::= 'context:' 'return' |
|
6441 |
||
6442 |
squeakPrimitive ::= 'primitive:' STRING |
|
6443 |
||
6444 |
newSTXPrimitive ::= 'primitive' |
|
6445 |
||
6446 |
resourceDecl ::= 'resource:' SYMBOL - leave SYMBOL in primitiveResource |
|
6447 |
| 'resource:' SYMBOL (...) - leave (SYMBOL (...)) in primitiveResource |
|
6448 |
" |
|
6449 |
||
6450 |
(tokenType == #Keyword or:[tokenType == #Identifier]) ifFalse:[ |
|
6451 |
self parseError:'bad primitive definition (keyword expected)'. |
|
6452 |
^ #Error |
|
6453 |
]. |
|
6454 |
||
6455 |
(tokenName = 'primitive:') ifTrue:[ |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6456 |
^ self parseTraditionalPrimitive. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6457 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6458 |
(tokenName = 'primitive') ifTrue:[ |
1410 | 6459 |
self nextToken. |
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6460 |
self checkForClosingAngle. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6461 |
^ 0. "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6462 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6463 |
(tokenName = 'resource:') ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6464 |
self parseResourcePragma. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6465 |
^ nil. "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6466 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6467 |
(tokenName = 'exception:' |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6468 |
or:[tokenName = 'context:']) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6469 |
self parseExceptionOrContextPragma. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6470 |
self checkForClosingAngle. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6471 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6472 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6473 |
(tokenName = 'C:') ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6474 |
self parseCPragma. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6475 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6476 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6477 |
(tokenName = 'api:') ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6478 |
self parseApiPragma. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6479 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6480 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6481 |
(tokenName = 'apicall:') ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6482 |
self parseApiCallPragma. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6483 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6484 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6485 |
(tokenName = 'cdecl:') ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6486 |
self parseCDeclPragma. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6487 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6488 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6489 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6490 |
self parseError:'unrecognized pragma: ' , tokenName. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6491 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6492 |
"/ skip |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6493 |
[tokenType ~~ #EOF] whileTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6494 |
((tokenType == #BinaryOperator) and:[tokenName = '>']) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6495 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6496 |
^ nil "/ no primitive number |
1410 | 6497 |
]. |
6498 |
self nextToken. |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6499 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6500 |
^ nil "/ no primitive number |
1410 | 6501 |
! |
6502 |
||
6503 |
parsePrimitiveOrResourceSpecOrEmpty |
|
6504 |
"parse a methods primitive or resource spec" |
|
6505 |
||
6506 |
|pos wmsg primNr primNrOrString| |
|
6507 |
||
6508 |
[(tokenType == #BinaryOperator) and:[tokenName = '<']] whileTrue:[ |
|
6509 |
"/ an ST-80 primitive or resourceSpec - parsed but ignored |
|
6510 |
||
6511 |
pos := tokenPosition. |
|
6512 |
self nextToken. |
|
6513 |
primNrOrString := self parsePrimitive. |
|
6514 |
||
6515 |
(primNrOrString == #Error) ifTrue:[^ #Error]. |
|
6516 |
wmsg := nil. |
|
6517 |
||
6518 |
primNrOrString isString ifTrue:[ |
|
6519 |
primNr := self primitiveNumberFromName:primNrOrString |
|
6520 |
] ifFalse:[ |
|
6521 |
primNr := primNrOrString |
|
6522 |
]. |
|
6523 |
||
6524 |
primNr notNil ifTrue:[ |
|
6525 |
primNr < 0 ifTrue:[ |
|
6526 |
WarnST80Directives == true ifTrue:[ |
|
6527 |
wmsg := 'ST-80/Squeak directive ignored'. |
|
6528 |
]. |
|
6529 |
] ifFalse:[ |
|
6530 |
primNr > 0 ifTrue:[ |
|
6531 |
primitiveNr := primNr. |
|
6532 |
wmsg := 'ST-80 primitive may not work' |
|
6533 |
] ifFalse:[ |
|
6534 |
primitiveNr := primNr. |
|
6535 |
wmsg := 'ST/X primitives only work in rel5 and newer' |
|
6536 |
] |
|
6537 |
]. |
|
6538 |
]. |
|
6539 |
wmsg notNil ifTrue:[self warning:wmsg position:pos] |
|
6540 |
]. |
|
6541 |
||
6542 |
"Created: 27.4.1996 / 16:55:55 / cg" |
|
6543 |
"Modified: 29.5.1996 / 17:25:52 / cg" |
|
6544 |
! |
|
6545 |
||
6546 |
parseResourcePragma |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6547 |
" '< resource:' has already been parsed." |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6548 |
|
1410 | 6549 |
|keys resource resourceValue| |
6550 |
||
6551 |
self nextToken. |
|
6552 |
(tokenType ~~ #Symbol) ifTrue:[ |
|
6553 |
self parseError:'symbol expected'. |
|
6554 |
^ #Error |
|
6555 |
]. |
|
6556 |
||
6557 |
resource := tokenValue. |
|
6558 |
resourceValue := true. |
|
6559 |
||
6560 |
self nextToken. |
|
6561 |
||
6562 |
tokenType == $( ifTrue:[ |
|
6563 |
self nextToken. |
|
6564 |
keys := OrderedCollection new. |
|
6565 |
[(tokenType == $)) or:[tokenType == #EOF] ] whileFalse:[ |
|
6566 |
keys add:tokenValue. |
|
6567 |
self nextToken. |
|
6568 |
]. |
|
6569 |
resourceValue := keys. |
|
6570 |
(tokenType == $)) ifFalse:[ |
|
6571 |
self parseError:'unterminated primitive/spec (missing '')'')'. |
|
6572 |
]. |
|
6573 |
self nextToken. |
|
6574 |
]. |
|
6575 |
||
6576 |
primitiveResource isNil ifTrue:[ |
|
6577 |
primitiveResource := IdentityDictionary new. |
|
6578 |
]. |
|
6579 |
primitiveResource at:(resource asSymbol) put:resourceValue. |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6580 |
self checkForClosingAngle. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6581 |
! |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6582 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6583 |
parseTraditionalPrimitive |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6584 |
"parse everything after the initial '<primitive:'" |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6585 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6586 |
|primNumber| |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6587 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6588 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6589 |
(tokenType == #Integer) ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6590 |
allowSqueakExtensions ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6591 |
(tokenType == #String) ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6592 |
self parseError:'primitive number or name expected'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6593 |
^ #Error |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6594 |
] |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6595 |
] ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6596 |
self parseError:'primitive number expected'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6597 |
^ #Error |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6598 |
] |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6599 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6600 |
primitiveNr notNil ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6601 |
self parseError:'only one primitive spec allowed'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6602 |
primNumber := -1. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6603 |
] ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6604 |
primNumber := tokenValue. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6605 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6606 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6607 |
((tokenType == #BinaryOperator) and:[tokenName = '>']) ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6608 |
((tokenType == #Keyword) and:[tokenName = 'errorCode:']) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6609 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6610 |
(tokenType == #Identifier) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6611 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6612 |
] ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6613 |
self error:'not yet implemented'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6614 |
] |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6615 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6616 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6617 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6618 |
self checkForClosingAngle. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6619 |
^ primNumber |
1410 | 6620 |
! |
6621 |
||
6622 |
primitiveNumberFromName:aPrimitiveName |
|
6623 |
"for future compatibility with Squeak ..." |
|
6624 |
||
6625 |
^ nil |
|
6626 |
! ! |
|
6627 |
||
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6628 |
!Parser methodsFor:'private'! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6629 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6630 |
currentNameSpace |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6631 |
|spc| |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6632 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6633 |
spc := currentNamespace. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6634 |
spc isNil ifTrue:[ |
832
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6635 |
(requestor respondsTo:#currentNameSpace) ifTrue:[ |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6636 |
spc := requestor currentNameSpace |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6637 |
] ifFalse:[ |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6638 |
spc := Class nameSpaceQuerySignal query. |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6639 |
]. |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6640 |
currentNamespace := spc. |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6641 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6642 |
^ spc |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6643 |
|
832
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6644 |
"Created: / 19.12.1996 / 23:47:58 / cg" |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6645 |
"Modified: / 14.10.1997 / 20:56:06 / cg" |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6646 |
"Modified: / 18.3.1999 / 18:25:50 / stefan" |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6647 |
! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6648 |
|
492
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
6649 |
currentNameSpace:aNameSpace |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
6650 |
currentNamespace := aNameSpace. |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
6651 |
|
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
6652 |
"Created: 8.2.1997 / 19:37:03 / cg" |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
6653 |
! |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
6654 |
|
1247
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6655 |
currentPackage |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6656 |
|pkg| |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6657 |
|
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6658 |
pkg := currentPackage. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6659 |
pkg isNil ifTrue:[ |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6660 |
(requestor respondsTo:#currentPackage) ifTrue:[ |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6661 |
pkg := requestor currentPackage |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6662 |
] ifFalse:[ |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6663 |
pkg := Class packageQuerySignal query. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6664 |
]. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6665 |
currentPackage := pkg. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6666 |
]. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6667 |
^ pkg |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6668 |
! |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6669 |
|
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6670 |
currentPackage:aPackageName |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6671 |
currentPackage := aPackageName. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6672 |
! |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
6673 |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6674 |
currentUsedNameSpaces |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6675 |
|spaces| |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6676 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6677 |
spaces := currentUsedNamespaces. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6678 |
spaces isNil ifTrue:[ |
679
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6679 |
(requestor respondsTo:#usedNameSpaces) ifTrue:[ |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6680 |
spaces := requestor usedNameSpaces |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6681 |
] ifFalse:[ |
832
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6682 |
spaces := Class usedNameSpaceQuerySignal query. |
679
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6683 |
]. |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6684 |
spaces isNil ifTrue:[ |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6685 |
spaces := #() |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6686 |
]. |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6687 |
currentUsedNamespaces := spaces. |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6688 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6689 |
^ spaces |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6690 |
|
679
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6691 |
"Created: / 19.12.1996 / 23:49:10 / cg" |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
6692 |
"Modified: / 7.4.1998 / 08:59:28 / cg" |
832
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
6693 |
"Modified: / 18.3.1999 / 18:25:57 / stefan" |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6694 |
! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6695 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6696 |
findNameSpaceWith:aVariableName |
692 | 6697 |
|ns currentSpace usedSpaces| |
486
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
6698 |
|
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
6699 |
"/ 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
|
6700 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6701 |
classToCompileFor notNil ifTrue:[ |
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6702 |
"/ Q: |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6703 |
"/ consider private classes of superclasses. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6704 |
"/ or search in the top owing classes namespace only ? |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6705 |
|
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6706 |
"/ for now, ignore other private classes - they are only |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6707 |
"/ known to the corresponding ownerClass. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6708 |
|
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6709 |
"is it in the classes namespace ?" |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6710 |
|
1315 | 6711 |
ns := classToCompileFor topNameSpace. |
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6712 |
(ns notNil |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6713 |
and:[ns ~~ Smalltalk]) ifTrue:[ |
1142 | 6714 |
ns isNameSpace ifTrue:[ |
6715 |
(ns at:aVariableName) notNil ifTrue:[ |
|
6716 |
^ ns |
|
6717 |
] |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6718 |
] |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6719 |
]. |
494
bb3e71c90dfd
currentClasses nameSpace is first to look for globals.
Claus Gittinger <cg@exept.de>
parents:
493
diff
changeset
|
6720 |
|
495 | 6721 |
"/ ns := classToCompileFor nameSpace. |
6722 |
"/ ns notNil ifTrue:[ |
|
6723 |
"/ "is it in the current classes namespace ?" |
|
6724 |
"/ (ns at:aVariableName asSymbol) notNil ifTrue:[ |
|
6725 |
"/ ^ ns |
|
6726 |
"/ ] |
|
6727 |
"/ ]. |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6728 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6729 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6730 |
"is it in the current namespace ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6731 |
currentSpace := self currentNameSpace. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6732 |
(currentSpace notNil |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6733 |
and:[currentSpace ~~ Smalltalk]) ifTrue:[ |
1043 | 6734 |
currentSpace isNameSpace ifTrue:[ |
6735 |
(currentSpace at:aVariableName) notNil ifTrue:[ |
|
6736 |
^ currentSpace |
|
6737 |
] |
|
6738 |
] ifFalse:[ |
|
6739 |
(currentSpace privateClassesAt:aVariableName) notNil ifTrue:[ |
|
6740 |
^ currentSpace |
|
6741 |
] |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6742 |
] |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6743 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6744 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6745 |
"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
|
6746 |
usedSpaces := self currentUsedNameSpaces. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6747 |
usedSpaces notNil ifTrue:[ |
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6748 |
usedSpaces do:[:aNameSpace | |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6749 |
(aNameSpace at:aVariableName) notNil ifTrue:[ |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6750 |
^ aNameSpace |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6751 |
] |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6752 |
] |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6753 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6754 |
^ nil |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6755 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6756 |
"Created: 19.12.1996 / 23:51:02 / cg" |
619 | 6757 |
"Modified: 14.10.1997 / 20:56:35 / cg" |
713 | 6758 |
! |
6759 |
||
1327 | 6760 |
implementedInAnyClass:selector |
6761 |
Smalltalk allClassesAndMetaclassesDo:[:cls | |
|
6762 |
(cls implements:selector) ifTrue:[^ true]. |
|
6763 |
]. |
|
6764 |
^ false |
|
6765 |
! |
|
6766 |
||
713 | 6767 |
inWhichClassIsClassInstVar:aString |
6768 |
"search class-chain for the class-instance variable named aString |
|
6769 |
- return the class or nil if not found" |
|
6770 |
||
6771 |
|aClass| |
|
6772 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6773 |
aClass := self classToLookForClassVars. |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6774 |
|
713 | 6775 |
[aClass notNil] whileTrue:[ |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6776 |
(aClass class instVarNames includes:aString) ifTrue:[ ^ aClass]. |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6777 |
aClass := aClass superclass |
713 | 6778 |
]. |
6779 |
^ nil |
|
6780 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6781 |
"Modified: / 18.6.1998 / 15:45:34 / cg" |
713 | 6782 |
! |
6783 |
||
6784 |
inWhichClassIsClassVar:aString |
|
6785 |
"search class-chain for the classvariable named aString |
|
6786 |
- return the class or nil if not found" |
|
6787 |
||
6788 |
|aClass className baseClass| |
|
6789 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6790 |
aClass := self classToLookForClassVars. |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6791 |
|
713 | 6792 |
aClass isMeta ifTrue:[ |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6793 |
className := aClass name copyWithoutLast:6. |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6794 |
baseClass := Smalltalk at:(className asSymbol). |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6795 |
baseClass notNil ifTrue:[ |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6796 |
aClass := baseClass |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6797 |
] |
713 | 6798 |
]. |
6799 |
^ aClass whichClassDefinesClassVar:aString |
|
6800 |
||
6801 |
"/ [aClass notNil] whileTrue:[ |
|
6802 |
"/ (aClass classVarNames includes:aString) ifTrue:[ ^ aClass]. |
|
6803 |
"/ aClass := aClass superclass |
|
6804 |
"/ ]. |
|
6805 |
"/ ^ nil |
|
6806 |
||
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6807 |
"Modified: / 17.6.1996 / 17:18:41 / stefan" |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6808 |
"Modified: / 18.6.1998 / 15:45:29 / cg" |
787 | 6809 |
! |
6810 |
||
1262 | 6811 |
makeReferenceFor:aNode |
6812 |
|rec sel indexNode contextNode arg1 arg2| |
|
6813 |
||
6814 |
contextNode := VariableNode type:#ThisContext context:contextToEvaluateIn. |
|
6815 |
indexNode := ConstantNode type:#Integer value:aNode index. |
|
6816 |
||
6817 |
aNode isArgument ifTrue:[ |
|
6818 |
sel := #forArgument:in:. |
|
6819 |
arg1 := indexNode. |
|
6820 |
arg2 := contextNode. |
|
6821 |
] ifFalse:[ |
|
6822 |
aNode isLocal ifTrue:[ |
|
6823 |
sel := #forLocal:in:. |
|
6824 |
arg1 := indexNode. |
|
6825 |
arg2 := contextNode. |
|
6826 |
] ifFalse:[ |
|
6827 |
self parseError:'unsupported variable reference (must be local or argument)'. |
|
6828 |
^ aNode |
|
6829 |
] |
|
6830 |
]. |
|
6831 |
||
6832 |
parseForCode ifFalse:[self rememberGlobalUsed:'Reference']. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6833 |
rec := VariableNode globalNamed:'Reference'. |
1262 | 6834 |
|
6835 |
^ MessageNode receiver:rec selector:sel arg1:arg1 arg2:arg2. |
|
6836 |
! |
|
6837 |
||
1003
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6838 |
noAssignmentAllowed:eMsg at:pos |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6839 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6840 |
self parseError:eMsg position:pos to:tokenPosition + tokenType size - 1. |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6841 |
self isSyntaxHighlighter ifFalse:[ |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6842 |
^ false |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6843 |
]. |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6844 |
self nextToken. "/ eat the assign when doing highlighting only |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6845 |
]. |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6846 |
^ true |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6847 |
! |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
6848 |
|
787 | 6849 |
plausibilityCheck:aNode |
1193 | 6850 |
|note| |
6851 |
||
6852 |
note := aNode plausibilityCheck. |
|
6853 |
note isNil ifTrue:[ |
|
6854 |
aNode isMessage ifTrue:[ |
|
6855 |
(contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[ "/ do not check this for doits |
|
6856 |
aNode receiver isSuper ifTrue:[ |
|
6857 |
aNode selector ~= selector ifTrue:[ |
|
6858 |
^ 'possible bad super message (selector should be same as in current method) ?' |
|
6859 |
]. |
|
6860 |
]. |
|
6861 |
]. |
|
6862 |
]. |
|
6863 |
]. |
|
6864 |
^ note |
|
1262 | 6865 |
! |
6866 |
||
6867 |
selfNode |
|
6868 |
selfNode isNil ifTrue:[ |
|
6869 |
selfNode := SelfNode value:selfValue |
|
6870 |
]. |
|
6871 |
^ selfNode |
|
141 | 6872 |
! ! |
6873 |
||
6874 |
!Parser methodsFor:'queries'! |
|
6875 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6876 |
classToLookForClassVars |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6877 |
"helper - return the class to look for classVars. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6878 |
If there is a context in which we evaluate, the |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6879 |
methods implementing class is used instead of the |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6880 |
class of the receiver." |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6881 |
|
1160 | 6882 |
|m who| |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6883 |
|
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6884 |
contextToEvaluateIn notNil ifTrue:[ |
748 | 6885 |
m := contextToEvaluateIn method. |
6886 |
m notNil ifTrue:[ |
|
6887 |
who := contextToEvaluateIn method who. |
|
6888 |
who notNil ifTrue:[ |
|
6889 |
^ who methodClass. |
|
6890 |
] |
|
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6891 |
]. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6892 |
"/ mhmh - might be a doIt ... |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6893 |
]. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6894 |
^ classToCompileFor |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6895 |
|
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6896 |
"Created: / 18.6.1998 / 15:43:42 / cg" |
748 | 6897 |
"Modified: / 21.7.1998 / 18:19:52 / cg" |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6898 |
! |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6899 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6900 |
classesClassInstVarNames |
141 | 6901 |
"caching allInstVarNames for next compilation saves time ..." |
6902 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6903 |
|names| |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6904 |
|
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6905 |
[ |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6906 |
|cls| |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6907 |
|
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6908 |
cls := self classToLookForClassVars. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6909 |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6910 |
(PrevClassInstVarNames isNil or:[PrevClass ~~ cls]) ifTrue:[ |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6911 |
PrevClass notNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6912 |
PrevClass removeDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6913 |
]. |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6914 |
PrevClass := cls. |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6915 |
|
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6916 |
PrevClassInstVarNames := cls class allInstVarNames. |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6917 |
PrevClass addDependent:Parser. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6918 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6919 |
names := PrevClassInstVarNames. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6920 |
] valueUninterruptably. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6921 |
^ names |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6922 |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6923 |
"Created: / 14.10.1996 / 18:03:35 / cg" |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6924 |
"Modified: / 18.6.1998 / 15:44:41 / cg" |
0 | 6925 |
! |
6926 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6927 |
classesClassVarNames |
141 | 6928 |
"caching allClassVarNames for next compilation saves time ..." |
6929 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6930 |
|names| |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6931 |
|
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6932 |
[ |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6933 |
|cls aClass| |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6934 |
|
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6935 |
cls := self classToLookForClassVars. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6936 |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6937 |
(PrevClassVarNames isNil or:[PrevClass ~~ cls]) ifTrue:[ |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6938 |
PrevClass notNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6939 |
PrevClass removeDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6940 |
]. |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6941 |
aClass := PrevClass := cls. |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6942 |
aClass isMeta ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6943 |
aClass := aClass soleInstance. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6944 |
aClass isNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6945 |
aClass := classToCompileFor |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6946 |
] |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6947 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6948 |
PrevClassVarNames := aClass allClassVarNames. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6949 |
PrevClass addDependent:Parser. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6950 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6951 |
names := PrevClassVarNames. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6952 |
] valueUninterruptably. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6953 |
^ names |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
6954 |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6955 |
"Modified: / 17.6.1996 / 17:15:53 / stefan" |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6956 |
"Created: / 14.10.1996 / 18:02:41 / cg" |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6957 |
"Modified: / 18.6.1998 / 15:44:30 / cg" |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6958 |
! |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6959 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6960 |
classesInstVarNames |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6961 |
"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
|
6962 |
|
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6963 |
|names| |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6964 |
|
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6965 |
[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6966 |
(PrevInstVarNames isNil or:[PrevClass ~~ classToCompileFor]) ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6967 |
PrevClass notNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6968 |
PrevClass removeDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6969 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6970 |
PrevClass := classToCompileFor. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6971 |
PrevInstVarNames := classToCompileFor allInstVarNames. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6972 |
PrevClassInstVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6973 |
PrevClassVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6974 |
PrevClass addDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6975 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6976 |
names := PrevInstVarNames |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6977 |
] valueUninterruptably. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6978 |
|
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
6979 |
^ names |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6980 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6981 |
"Created: 14.10.1996 / 18:00:26 / cg" |
0 | 6982 |
! |
6983 |
||
934
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
6984 |
contextMustBeReturnable |
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
6985 |
^ primitiveContextInfo notNil |
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
6986 |
and:[ ^ primitiveContextInfo includes:('context:' -> #return) ] |
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
6987 |
|
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
6988 |
|
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
6989 |
! |
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
6990 |
|
141 | 6991 |
hasNonOptionalPrimitiveCode |
6992 |
"return true if there was any ST/X style primitive code (valid after parsing)" |
|
6993 |
||
6994 |
^ hasNonOptionalPrimitiveCode |
|
0 | 6995 |
! |
6996 |
||
141 | 6997 |
hasPrimitiveCode |
6998 |
"return true if there was any ST/X style primitive code (valid after parsing)" |
|
6999 |
||
7000 |
^ hasPrimitiveCode |
|
98 | 7001 |
! |
7002 |
||
1440 | 7003 |
isDoIt |
7004 |
^ (selector isNil or:[selector == #'doIt' or:[selector == #'doIt:']]) |
|
7005 |
! |
|
7006 |
||
883 | 7007 |
isSyntaxHighlighter |
7008 |
^ false |
|
7009 |
! |
|
7010 |
||
385 | 7011 |
lineNumberInfo |
7012 |
^ lineNumberInfo |
|
7013 |
||
7014 |
"Created: 21.10.1996 / 17:06:16 / cg" |
|
7015 |
! |
|
7016 |
||
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7017 |
lineNumberInfo:how |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7018 |
lineNumberInfo := how |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7019 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7020 |
"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
|
7021 |
! |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7022 |
|
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7023 |
messagesSent |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7024 |
"return a collection with sent message selectors (valid after parsing). |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7025 |
Includes all sent messages (i.e. also sent super messages)" |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7026 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7027 |
^ (messagesSent ? #()) collect:[:each | each asSymbol] |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7028 |
! |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7029 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7030 |
messagesSentToSelf |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7031 |
"return a collection with message selectors sent to self only (valid after parsing)" |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7032 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7033 |
^ (messagesSentToSelf ? #()) collect:[:each | each asSymbol] |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7034 |
! |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7035 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7036 |
messagesSentToSuper |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7037 |
"return a collection with message selectors sent to super only (valid after parsing)" |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7038 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7039 |
^ (messagesSentToSuper ? #()) collect:[:each | each asSymbol] |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7040 |
! |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7041 |
|
141 | 7042 |
methodArgs |
7043 |
"return an array with methodarg names (valid after parsing spec)" |
|
7044 |
||
7045 |
^ methodArgNames |
|
7046 |
! |
|
7047 |
||
7048 |
methodVars |
|
7049 |
"return a collection with method variablenames (valid after parsing)" |
|
7050 |
||
7051 |
^ methodVarNames |
|
23 | 7052 |
! |
7053 |
||
141 | 7054 |
modifiedClassVars |
7055 |
"return a collection with classvariablenames modified by method (valid after parsing)" |
|
7056 |
||
541 | 7057 |
^ modifiedClassVars ? #() |
7058 |
||
7059 |
"Modified: 19.6.1997 / 17:54:48 / cg" |
|
141 | 7060 |
! |
7061 |
||
7062 |
modifiedGlobals |
|
7063 |
"return a collection with globalnames modified by method (valid after parsing)" |
|
7064 |
||
541 | 7065 |
^ modifiedGlobals ? #() |
7066 |
||
7067 |
"Modified: 19.6.1997 / 17:54:51 / cg" |
|
141 | 7068 |
! |
7069 |
||
7070 |
modifiedInstVars |
|
7071 |
"return a collection with instvariablenames modified by method (valid after parsing)" |
|
7072 |
||
541 | 7073 |
^ modifiedInstVars ? #() |
7074 |
||
7075 |
"Modified: 19.6.1997 / 17:54:27 / cg" |
|
0 | 7076 |
! |
7077 |
||
141 | 7078 |
numberOfMethodArgs |
7079 |
"return the number of methodargs (valid after parsing spec)" |
|
7080 |
||
7081 |
^ methodArgs size |
|
7082 |
! |
|
7083 |
||
7084 |
numberOfMethodVars |
|
7085 |
"return the number of method variables (valid after parsing)" |
|
7086 |
||
7087 |
^ methodVars size |
|
7088 |
! |
|
7089 |
||
1077
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7090 |
readClassVars |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7091 |
"return a collection with classvariablenames read by method (valid after parsing)" |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7092 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7093 |
^ readClassVars ? #() |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7094 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7095 |
"Modified: 19.6.1997 / 17:54:38 / cg" |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7096 |
! |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7097 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7098 |
readInstVars |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7099 |
"return a collection with instvariablenames read by method (valid after parsing)" |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7100 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7101 |
^ readInstVars ? #() |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7102 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7103 |
"Modified: 19.6.1997 / 17:54:38 / cg" |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7104 |
! |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7105 |
|
141 | 7106 |
selector |
7107 |
"return the selector (valid after parsing spec)" |
|
7108 |
||
7109 |
^ selector |
|
0 | 7110 |
! |
7111 |
||
141 | 7112 |
usedClassVars |
7113 |
"return a collection with classvariablenames refd by method (valid after parsing)" |
|
7114 |
||
541 | 7115 |
^ usedClassVars ? #() |
7116 |
||
7117 |
"Modified: 19.6.1997 / 17:54:56 / cg" |
|
141 | 7118 |
! |
7119 |
||
7120 |
usedGlobals |
|
7121 |
"return a collection with globalnames refd by method (valid after parsing)" |
|
7122 |
||
541 | 7123 |
^ usedGlobals ? #() |
7124 |
||
7125 |
"Modified: 19.6.1997 / 17:55:00 / cg" |
|
141 | 7126 |
! |
7127 |
||
7128 |
usedInstVars |
|
7129 |
"return a collection with instvariablenames refd by method (valid after parsing)" |
|
7130 |
||
541 | 7131 |
^ usedInstVars ? #() |
7132 |
||
7133 |
"Modified: 19.6.1997 / 17:54:38 / cg" |
|
141 | 7134 |
! |
7135 |
||
1064
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7136 |
usedSymbols |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7137 |
"return a collection with used symbols (except for sent messages) (valid after parsing)" |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7138 |
|
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7139 |
^ (usedSymbols ? #()) |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7140 |
! |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7141 |
|
141 | 7142 |
usedVars |
7143 |
"return a collection with variablenames refd by method (valid after parsing)" |
|
7144 |
||
541 | 7145 |
^ usedVars ? #() |
7146 |
||
7147 |
"Modified: 19.6.1997 / 17:55:04 / cg" |
|
0 | 7148 |
! |
7149 |
||
141 | 7150 |
usesSuper |
7151 |
"return true if the parsed method uses super (valid after parsing)" |
|
7152 |
||
7153 |
^ usesSuper |
|
7154 |
! ! |
|
7155 |
||
7156 |
!Parser methodsFor:'setup'! |
|
7157 |
||
1220
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7158 |
classToCompileFor |
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7159 |
^ classToCompileFor |
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7160 |
|
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7161 |
"Created: / 15.11.2001 / 17:21:10 / cg" |
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7162 |
! |
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7163 |
|
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7164 |
foldConstants:aSymbolOrNil |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7165 |
"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
|
7166 |
|
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7167 |
foldConstants := aSymbolOrNil |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7168 |
|
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7169 |
"Created: 21.3.1996 / 16:03:22 / cg" |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7170 |
"Modified: 21.3.1996 / 16:05:04 / cg" |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7171 |
! |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7172 |
|
141 | 7173 |
initialize |
7174 |
super initialize. |
|
7175 |
||
7176 |
hasPrimitiveCode := hasNonOptionalPrimitiveCode := false. |
|
7177 |
warnSTXHereExtensionUsed := WarnSTXSpecials. |
|
7178 |
usesSuper := false. |
|
7179 |
parseForCode := false. |
|
377 | 7180 |
foldConstants := FoldConstants. |
7181 |
lineNumberInfo := LineNumberInfo. |
|
607 | 7182 |
warnUndeclared := true. |
1160 | 7183 |
warnUnusedVars := WarnUnusedVars. |
607 | 7184 |
|
7185 |
"Modified: 7.9.1997 / 02:04:34 / cg" |
|
141 | 7186 |
! |
7187 |
||
1363 | 7188 |
initializeFlagsFrom:aParser |
7189 |
"initialize flags from another scanner" |
|
7190 |
||
7191 |
super initializeFlagsFrom:aParser. |
|
7192 |
warnSTXHereExtensionUsed := aParser warnSTXHereExtensionUsed. |
|
7193 |
! |
|
7194 |
||
141 | 7195 |
parseForCode |
7196 |
"turns off certain statistics (keeping referenced variables, modified vars etc.) |
|
7197 |
Use this when parsing for compilation or evaluation" |
|
7198 |
||
7199 |
parseForCode := true |
|
0 | 7200 |
! |
7201 |
||
141 | 7202 |
setClassToCompileFor:aClass |
7203 |
"set the class to be used for parsing/evaluating" |
|
7204 |
||
7205 |
classToCompileFor := aClass. |
|
7206 |
(classToCompileFor ~~ PrevClass) ifTrue:[ |
|
7207 |
PrevClass notNil ifTrue:[ |
|
7208 |
Parser update:PrevClass |
|
7209 |
] |
|
7210 |
] |
|
7211 |
! |
|
7212 |
||
7213 |
setContext:aContext |
|
7214 |
"set the context used while evaluating" |
|
7215 |
||
7216 |
contextToEvaluateIn := aContext |
|
7217 |
! |
|
7218 |
||
7219 |
setSelf:anObject |
|
7220 |
"set the value to be used for self while evaluating" |
|
7221 |
||
7222 |
selfValue := anObject. |
|
7223 |
classToCompileFor := anObject class. |
|
7224 |
(classToCompileFor ~~ PrevClass) ifTrue:[ |
|
7225 |
PrevClass notNil ifTrue:[ |
|
7226 |
Parser update:PrevClass |
|
7227 |
] |
|
7228 |
] |
|
607 | 7229 |
! |
7230 |
||
7231 |
warnUndeclared:aBoolean |
|
7232 |
warnUndeclared := aBoolean. |
|
7233 |
||
7234 |
"Created: 7.9.1997 / 02:05:00 / cg" |
|
1160 | 7235 |
! |
7236 |
||
7237 |
warnUnusedVars:aBoolean |
|
7238 |
warnUnusedVars := aBoolean. |
|
0 | 7239 |
! ! |
7240 |
||
84 | 7241 |
!Parser methodsFor:'statistic'! |
7242 |
||
1077
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7243 |
rememberClassVarRead:name |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7244 |
readClassVars isNil ifTrue:[ |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7245 |
readClassVars := Set new |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7246 |
]. |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7247 |
readClassVars add:name. |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7248 |
self rememberClassVarUsed:name |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7249 |
! |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7250 |
|
141 | 7251 |
rememberClassVarUsed:name |
7252 |
usedClassVars isNil ifTrue:[ |
|
7253 |
usedClassVars := Set new |
|
7254 |
]. |
|
7255 |
usedClassVars add:name. |
|
7256 |
self rememberVariableUsed:name |
|
7257 |
! |
|
7258 |
||
7259 |
rememberGlobalUsed:name |
|
7260 |
usedGlobals isNil ifTrue:[ |
|
7261 |
usedGlobals := Set new |
|
7262 |
]. |
|
7263 |
usedGlobals add:name. |
|
7264 |
self rememberVariableUsed:name |
|
7265 |
! |
|
7266 |
||
1077
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7267 |
rememberInstVarRead:name |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7268 |
readInstVars isNil ifTrue:[ |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7269 |
readInstVars := Set new |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7270 |
]. |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7271 |
readInstVars add:name. |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7272 |
self rememberVariableUsed:name |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7273 |
! |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7274 |
|
141 | 7275 |
rememberInstVarUsed:name |
7276 |
usedInstVars isNil ifTrue:[ |
|
7277 |
usedInstVars := Set new |
|
7278 |
]. |
|
7279 |
usedInstVars add:name. |
|
7280 |
self rememberVariableUsed:name |
|
7281 |
! |
|
7282 |
||
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7283 |
rememberLocalUsed:name |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7284 |
usedLocalVars isNil ifTrue:[ |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7285 |
usedLocalVars := Set new |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7286 |
]. |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7287 |
usedLocalVars add:name. |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7288 |
|
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7289 |
! |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7290 |
|
1231 | 7291 |
rememberReturnedValue:anExpressionNode |
7292 |
|expr| |
|
7293 |
||
7294 |
returnedValues isNil ifTrue:[returnedValues := Set new]. |
|
7295 |
||
7296 |
expr := anExpressionNode. |
|
7297 |
expr isAssignment ifTrue:[ |
|
7298 |
expr := expr expression. |
|
7299 |
]. |
|
7300 |
(expr isConstant or:[expr isSelf]) ifTrue:[ |
|
7301 |
returnedValues add:expr |
|
7302 |
]. |
|
7303 |
! |
|
7304 |
||
84 | 7305 |
rememberSelectorUsed:sel |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7306 |
messagesSent isNil ifTrue:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7307 |
messagesSent := IdentitySet new. |
84 | 7308 |
]. |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7309 |
messagesSent add:sel |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7310 |
! |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7311 |
|
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7312 |
rememberSelectorUsed:sel receiver:receiverNode |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7313 |
self rememberSelectorUsed:sel. |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7314 |
receiverNode isSuper ifTrue:[ |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7315 |
self rememberSelectorUsedInSuperSend:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7316 |
] ifFalse:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7317 |
receiverNode isSelf ifTrue:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7318 |
self rememberSelectorUsedInSelfSend:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7319 |
]. |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7320 |
]. |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7321 |
! |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7322 |
|
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7323 |
rememberSelectorUsedInSelfSend:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7324 |
messagesSentToSelf isNil ifTrue:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7325 |
messagesSentToSelf := IdentitySet new. |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7326 |
]. |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7327 |
messagesSentToSelf add:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7328 |
! |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7329 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7330 |
rememberSelectorUsedInSuperSend:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7331 |
messagesSentToSuper isNil ifTrue:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7332 |
messagesSentToSuper := IdentitySet new. |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7333 |
]. |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7334 |
messagesSentToSuper add:sel |
84 | 7335 |
! |
7336 |
||
1064
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7337 |
rememberSymbolUsed:aSymbol |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7338 |
usedSymbols isNil ifTrue:[ |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7339 |
usedSymbols := IdentitySet new. |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7340 |
]. |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7341 |
usedSymbols add:aSymbol |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7342 |
! |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7343 |
|
84 | 7344 |
rememberVariableUsed:name |
7345 |
usedVars isNil ifTrue:[ |
|
7346 |
usedVars := Set new |
|
7347 |
]. |
|
7348 |
usedVars add:name |
|
7349 |
! ! |
|
7350 |
||
1340 | 7351 |
!Parser::ParseError methodsFor:'accessing'! |
7352 |
||
1386 | 7353 |
description |
1434
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7354 |
|s| |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7355 |
|
1461 | 7356 |
s := super description. |
7357 |
s last isSeparator ifFalse:[ |
|
7358 |
errorMessage size > 0 ifTrue:[ |
|
7359 |
s := s , ' ' |
|
7360 |
] |
|
7361 |
]. |
|
7362 |
s := s , (errorMessage ? ''). |
|
1434
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7363 |
lineNumber notNil ifTrue:[ |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7364 |
s := s , ' [' , lineNumber asString , ']' |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7365 |
]. |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7366 |
^ s |
1386 | 7367 |
! |
7368 |
||
1340 | 7369 |
endPosition |
7370 |
^ endPosition |
|
7371 |
! |
|
7372 |
||
7373 |
errorMessage |
|
7374 |
^ errorMessage |
|
7375 |
! |
|
7376 |
||
1460 | 7377 |
errorMessage:errorMessageArg startPosition:startPositionArg |
7378 |
errorMessage := errorMessageArg. |
|
7379 |
startPosition := startPositionArg. |
|
7380 |
! |
|
7381 |
||
1340 | 7382 |
errorMessage:errorMessageArg startPosition:startPositionArg endPosition:endPositionArg |
7383 |
errorMessage := errorMessageArg. |
|
7384 |
startPosition := startPositionArg. |
|
7385 |
endPosition := endPositionArg. |
|
7386 |
! |
|
7387 |
||
1434
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7388 |
lineNumber:something |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7389 |
lineNumber := something. |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7390 |
! |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7391 |
|
1340 | 7392 |
parser |
7393 |
^ originator |
|
7394 |
! |
|
7395 |
||
7396 |
startPosition |
|
7397 |
^ startPosition |
|
7398 |
! ! |
|
7399 |
||
1399
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7400 |
!Parser::UndefinedVariableNotification methodsFor:'accessing'! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7401 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7402 |
parser |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7403 |
"return the value of the instance variable 'parser' (automatically generated)" |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7404 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7405 |
^ parser |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7406 |
! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7407 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7408 |
parser:something |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7409 |
"set the value of the instance variable 'parser' (automatically generated)" |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7410 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7411 |
parser := something. |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7412 |
! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7413 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7414 |
variableName |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7415 |
^ parameter |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7416 |
! ! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7417 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7418 |
!Parser class methodsFor:'documentation'! |
148 | 7419 |
|
7420 |
version |
|
1482
d80c83f1167a
catch twoByte string parsing in selectorInExpression
Claus Gittinger <cg@exept.de>
parents:
1471
diff
changeset
|
7421 |
^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.413 2004-02-12 18:39:06 cg Exp $' |
148 | 7422 |
! ! |
1322
da25e31f423c
autodefine workspace variables
Claus Gittinger <cg@exept.de>
parents:
1315
diff
changeset
|
7423 |
|
141 | 7424 |
Parser initialize! |