author | Claus Gittinger <cg@exept.de> |
Thu, 25 Nov 2004 15:30:33 +0100 | |
changeset 1561 | 175735dcd732 |
parent 1557 | 311e94185248 |
child 1562 | d426603ccc4e |
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 |
1521
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
41 |
AllowArrayIndexSyntaxExtension AllowDomainVariables |
1522
777862196320
checkVariable-conventions: can be (are by default) disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1521
diff
changeset
|
42 |
WarnAboutWrongVariableNames WarnAboutVariableNameConventions' |
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
43 |
poolDictionaries:'' |
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
44 |
category:'System-Compiler' |
0 | 45 |
! |
46 |
||
1423 | 47 |
ProceedableError subclass:#ParseError |
1434
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
48 |
instanceVariableNames:'errorMessage startPosition endPosition lineNumber' |
971 | 49 |
classVariableNames:'' |
50 |
poolDictionaries:'' |
|
51 |
privateIn:Parser |
|
52 |
! |
|
53 |
||
54 |
Parser::ParseError subclass:#UndefinedSuperclassError |
|
55 |
instanceVariableNames:'' |
|
56 |
classVariableNames:'' |
|
57 |
poolDictionaries:'' |
|
58 |
privateIn:Parser |
|
59 |
! |
|
60 |
||
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
61 |
Notification subclass:#UndefinedVariableNotification |
1399
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
62 |
instanceVariableNames:'parser' |
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
63 |
classVariableNames:'' |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
64 |
poolDictionaries:'' |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
65 |
privateIn:Parser |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
66 |
! |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
67 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
68 |
!Parser class methodsFor:'documentation'! |
19 | 69 |
|
20 | 70 |
copyright |
71 |
" |
|
72 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
44 | 73 |
All Rights Reserved |
20 | 74 |
|
75 |
This software is furnished under a license and may be used |
|
76 |
only in accordance with the terms of that license and with the |
|
77 |
inclusion of the above copyright notice. This software may not |
|
78 |
be provided or otherwise made available to, or used by, any |
|
79 |
other person. No title to or ownership of the software is |
|
80 |
hereby transferred. |
|
81 |
" |
|
82 |
! |
|
83 |
||
19 | 84 |
documentation |
85 |
" |
|
86 |
Parser is used for both parsing and evaluating smalltalk expressions; |
|
87 |
it first builds a parseTree which is then interpreted (evaluate) or |
|
88 |
compiled. Compilation is done in the subclass ByteCodeCompiler and/or |
|
89 |
the (planned) MachineCodeCompiler. |
|
90 |
||
173
247ae4b8af76
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
171
diff
changeset
|
91 |
methods of main interest are: |
755 | 92 |
Parser evaluateExpression:... |
19 | 93 |
|
94 |
and: |
|
755 | 95 |
Parser parseExpression:... |
96 |
Parser parseMethod:... |
|
19 | 97 |
|
98 |
there is protocol to parse complete methods, selector specs, body only etc. |
|
99 |
||
100 |
Parser is also used to find the referenced/modified inst/classvars of |
|
101 |
a method - this is done by sending parseXXX message to a parser and asking |
|
102 |
the parser for referencedXVars or modifiedXVars (see SystemBrowser). |
|
103 |
||
104 |
You can also use parsers for all kinds of other things (ChangesBrowser for |
|
105 |
example analyzes the expressions in the changelist ...) by looking at the |
|
106 |
parsers tree. (Although this is somewhat dangerous, since it exports the |
|
755 | 107 |
compilers internals ... better style is to add specialized query methods here) |
19 | 108 |
|
109 |
One instance of Parser is created to parse one method or expression - i.e. |
|
110 |
its not suggested to reuse parsers. |
|
111 |
||
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
112 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
113 |
Constant folding: |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
114 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
115 |
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
|
116 |
expressions involving integers and floats are constant folded |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
117 |
(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
|
118 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
Therefore, this mode is a bit dangerous and disabled by default. |
755 | 125 |
The current implementation, base upon a global constant-folding setting is somewhat stupid |
126 |
and intermediate - a better solution would be to allow the optimization to be controlled |
|
127 |
by a method-pragma, since it may make sense to disable optimization on a method level, |
|
128 |
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
|
129 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
130 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
131 |
Immutable arrays: |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
132 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
133 |
Immutable arrays are experimental and being evaluated. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
return the modified array. These are hard to find bugs. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
138 |
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
|
139 |
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
|
140 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
141 |
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
|
142 |
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
|
143 |
of st/x. |
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 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
146 |
|
260 | 147 |
[Instance variables:] |
148 |
||
755 | 149 |
classToCompileFor <Class> the class (or nil) we are compiling for |
150 |
||
151 |
selfValue <any> value to use as self when interpreting |
|
152 |
||
153 |
contextToEvaluateIn <Context> the context (or nil) when interpreting |
|
154 |
||
155 |
selector <Symbol> the selector of the parsed method |
|
156 |
(valid after parseMethodSpecification) |
|
157 |
methodArgs internal |
|
158 |
||
159 |
methodArgNames <Collection> the names of the arguments |
|
160 |
(valid after parseMethodSpecification) |
|
161 |
||
162 |
methodVars internal |
|
163 |
||
164 |
methodVarNames <Collection> the names of the method locals |
|
165 |
(valid after parseMethodBodyVarSpec) |
|
166 |
||
167 |
tree <ParseTree> the parse tree - valid after parsing |
|
168 |
||
169 |
currentBlock if currently parsing for a block |
|
170 |
||
171 |
usedInstVars set of all accessed instances variables |
|
172 |
(valid after parsing) |
|
173 |
||
174 |
usedClassVars same for classVars |
|
175 |
||
176 |
usedVars all used variables (inst, class & globals) |
|
177 |
||
178 |
modifiedInstVars set of all modified instance variables |
|
179 |
||
180 |
modifiedClassVars same for clasVars |
|
181 |
||
182 |
localVarDefPosition <Integer> the character offset of the local variable |
|
183 |
def. (i.e. the first '|' if any) |
|
184 |
Not yet used - prepared for automatic add of |
|
185 |
undefined variables |
|
186 |
||
187 |
evalExitBlock internal for interpretation |
|
188 |
||
189 |
selfNode <Node> cached one-and-only 'self' node |
|
190 |
superNode <Node> cached one-and-only 'super' node |
|
191 |
||
192 |
hasPrimitiveCode <Boolean> true, if it contains ST/X style primitive code |
|
193 |
hasNonOptionalPrimitiveCode |
|
194 |
<Boolean> true, if it contains ST/X style primitive code |
|
195 |
which is NOT flagged by the OPTIONAL directive. |
|
196 |
||
197 |
primitiveNr <Integer> the parsed ST-80 type primitive number (or nil) |
|
198 |
||
199 |
logged |
|
200 |
||
201 |
warnedUndefVars <Set> set of all variables which the parser has |
|
202 |
already output a warning (to avoid multiple |
|
203 |
warnings about the same variable) |
|
260 | 204 |
|
205 |
[Class variables:] |
|
206 |
||
755 | 207 |
PrevClass <Class> class, of which properties are |
208 |
cached in: |
|
209 |
||
210 |
PrevInstVarNames <Collection> instance variablenames of cached class |
|
211 |
PrevClassVarNames <Collection> class variablenames of cached class |
|
212 |
PrevClassInstVarNames <Collection> class instance variablenames of cached class |
|
213 |
||
214 |
LazyCompilation <Boolean> EXPERIMENTAL: lazy compilation |
|
215 |
||
216 |
ArraysAreImmutable <Boolean> if true, create array literals |
|
217 |
as instances of ImmutableArray, |
|
218 |
which cannot be stored into. |
|
219 |
Default is false, for compatibility. |
|
220 |
Can be turned on while developping |
|
221 |
new code to make certain that side |
|
222 |
effects are avoided. |
|
223 |
||
224 |
WarnST80Directives <Boolean> if true, give warnings about |
|
225 |
ST-80 directives (resource defs) |
|
226 |
which are ignored in st/x. |
|
227 |
defaults to false. |
|
228 |
||
229 |
FoldConstants <Symbol> controls how constant folding should be |
|
230 |
done. |
|
231 |
Can be one of: |
|
232 |
nil - no constant folding |
|
233 |
#level1 - numeric optimizations only |
|
234 |
#level2 - secure optimizations only |
|
235 |
#full - full folding |
|
236 |
||
237 |
level1: arithmetic on constant numbers |
|
238 |
||
239 |
level2: above PLUS array conversions with #asFloatArray, |
|
240 |
#asDoubleArray, string concatenation |
|
241 |
||
242 |
full: constant points. |
|
260 | 243 |
|
244 |
[see also:] |
|
755 | 245 |
ByteCodeCompiler Scanner ObjectFileLoader |
246 |
Workspace |
|
247 |
SystemBrowser |
|
263 | 248 |
|
249 |
[author:] |
|
755 | 250 |
Claus Gittinger |
19 | 251 |
" |
1399
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 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
254 |
examples |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
255 |
" |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
256 |
[exBegin] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
257 |
Parser |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
258 |
evaluate:'1+2*3' |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
259 |
in:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
260 |
receiver:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
261 |
notifying:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
262 |
logged:false |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
263 |
ifFail:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
264 |
[exEnd] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
265 |
[exBegin] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
266 |
Parser undefinedVariableNotification handle:[:ex | |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
267 |
|badName| |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
268 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
269 |
badName := ex variableName. |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
270 |
ex proceedWith:(ConstantNode value:5). |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
271 |
] do:[ |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
272 |
^ self compilerClass |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
273 |
evaluate:'foo * 3' |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
274 |
in:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
275 |
receiver:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
276 |
notifying:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
277 |
logged:false |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
278 |
ifFail:nil |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
279 |
] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
280 |
[exEnd] |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
281 |
" |
141 | 282 |
! ! |
283 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
284 |
!Parser class methodsFor:'instance creation'! |
141 | 285 |
|
286 |
for:aStringOrStream in:aClass |
|
287 |
"return a new parser, reading code for aClass from aStringOrStream" |
|
288 |
||
289 |
|parser| |
|
290 |
||
291 |
parser := self for:aStringOrStream. |
|
292 |
parser setClassToCompileFor:aClass. |
|
293 |
^ parser |
|
294 |
! ! |
|
295 |
||
1419 | 296 |
!Parser class methodsFor:'Compatibility-ST80'! |
540 | 297 |
|
298 |
parse:aString class:aClass |
|
299 |
"same as #parseMethod:in: for ST80 compatibility." |
|
300 |
||
301 |
|parser| |
|
302 |
||
303 |
parser := self parseMethod:aString in:aClass. |
|
304 |
parser notNil ifTrue:[^ parser tree]. |
|
305 |
^ nil |
|
306 |
||
307 |
"Modified: 19.6.1997 / 16:34:57 / cg" |
|
308 |
! ! |
|
309 |
||
1419 | 310 |
!Parser class methodsFor:'Compatibility-Squeak'! |
920 | 311 |
|
312 |
evaluate:someString for:aReceiver logged:logged |
|
313 |
^ self evaluate:someString receiver:aReceiver logged:logged |
|
314 |
||
315 |
||
316 |
||
317 |
! ! |
|
318 |
||
1062 | 319 |
!Parser class methodsFor:'Signal constants'! |
320 |
||
321 |
parseErrorSignal |
|
322 |
^ ParseErrorSignal |
|
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
323 |
! |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
324 |
|
1468 | 325 |
restartCompilationSignal |
326 |
^ RestartCompilationSignal |
|
327 |
||
328 |
"Created: / 15.11.2001 / 22:57:05 / cg" |
|
329 |
! |
|
330 |
||
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
331 |
undefinedVariableNotification |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
332 |
^ UndefinedVariableNotification |
1062 | 333 |
! ! |
334 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
335 |
!Parser class methodsFor:'changes'! |
141 | 336 |
|
337 |
flushNameCache |
|
338 |
"unconditional flush name caches" |
|
339 |
||
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
340 |
[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
341 |
PrevClass notNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
342 |
PrevClass removeDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
343 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
344 |
PrevClass := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
345 |
PrevInstVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
346 |
PrevClassVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
347 |
PrevClassInstVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
348 |
] valueUninterruptably |
141 | 349 |
|
350 |
"Parser flushNameCache" |
|
351 |
! |
|
352 |
||
353 |
update:something with:someArgument from:changedObject |
|
354 |
"aClass has changed its definition - flush name caches if we have to" |
|
355 |
||
356 |
(changedObject == PrevClass) ifTrue:[ |
|
1090
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
357 |
something == #definition ifTrue:[ |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
358 |
self flushNameCache |
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 |
]. |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
361 |
(changedObject == Smalltalk) ifTrue:[ |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
362 |
something == #classDefinition ifTrue:[ |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
363 |
self flushNameCache |
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
364 |
] |
141 | 365 |
] |
366 |
! ! |
|
367 |
||
717 | 368 |
!Parser class methodsFor:'class initialization'! |
369 |
||
370 |
initialize |
|
371 |
LazyCompilation := false. "/ usually set to true in your .rc file |
|
752 | 372 |
ArraysAreImmutable := false. "/ usually left false for ST-80 compatibility |
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
373 |
StringsAreImmutable := false. "/ usually left false for ST-80 compatibility |
752 | 374 |
|
717 | 375 |
ImplicitSelfSends := false. |
376 |
WarnST80Directives := false. |
|
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
377 |
WarnUnusedVars := true. |
717 | 378 |
FoldConstants := #level1. |
379 |
LineNumberInfo := false. |
|
380 |
||
1062 | 381 |
ParseErrorSignal isNil ifTrue:[ |
1380 | 382 |
ParseErrorSignal := ParseError. |
1062 | 383 |
ParseErrorSignal notifierString:'parse error'. |
1380 | 384 |
|
385 |
"/ ParseErrorSignal := Error newSignalMayProceed:true. |
|
386 |
"/ ParseErrorSignal notifierString:'parse error'. |
|
387 |
"/ ParseErrorSignal nameClass:self message:#parseErrorSignal. |
|
1062 | 388 |
]. |
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
389 |
RestartCompilationSignal := Signal new. |
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
390 |
|
1090
7f49c607a315
catch change-notifications from Smalltalk (to flush PrevClass cache)
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
391 |
Smalltalk addDependent:self. |
1062 | 392 |
|
717 | 393 |
" |
394 |
self initialize |
|
395 |
" |
|
396 |
||
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
397 |
"Modified: / 15.11.2001 / 22:54:09 / cg" |
717 | 398 |
! ! |
399 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
400 |
!Parser class methodsFor:'controlling compilation'! |
141 | 401 |
|
402 |
arraysAreImmutable |
|
403 |
"return true if arrays are immutable literals" |
|
404 |
||
405 |
^ ArraysAreImmutable |
|
406 |
! |
|
407 |
||
408 |
arraysAreImmutable:aBoolean |
|
409 |
"turn on/off immutable array literals - default is false for ST-80 compatibilty." |
|
410 |
||
411 |
ArraysAreImmutable := aBoolean. |
|
412 |
||
413 |
" |
|
414 |
can be added to your private.rc file: |
|
415 |
||
416 |
Compiler arraysAreImmutable:true |
|
417 |
Compiler arraysAreImmutable:false |
|
418 |
" |
|
419 |
! |
|
420 |
||
421 |
compileLazy |
|
422 |
"return true if compiling lazy" |
|
423 |
||
424 |
^ LazyCompilation. |
|
425 |
! |
|
426 |
||
427 |
compileLazy:aBoolean |
|
428 |
"turn on/off lazy compilation - return previous setting. |
|
429 |
Actually this flag belongs into the ByteCodeCompiler subclass, |
|
430 |
but it also controls the reporting of some errors here; therefore |
|
431 |
its located here" |
|
432 |
||
433 |
|oldLazy| |
|
434 |
||
435 |
oldLazy := LazyCompilation. |
|
436 |
LazyCompilation := aBoolean. |
|
437 |
^ oldLazy |
|
438 |
||
439 |
" |
|
440 |
Compiler compileLazy:false |
|
441 |
Compiler compileLazy:true |
|
442 |
" |
|
443 |
! |
|
444 |
||
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
445 |
foldConstants |
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
446 |
"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
|
447 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
448 |
^ FoldConstants |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
449 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
450 |
"Created: 9.2.1996 / 17:40:13 / cg" |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
451 |
! |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
452 |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
453 |
foldConstants:aSymbol |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
454 |
"set the symbol describing how constants are to be folded. |
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
455 |
It can be: |
619 | 456 |
nil - no constant folding |
457 |
#level1 - numeric constants only |
|
458 |
#level2 - level1 PLUS array conversions PLUS string concatenation |
|
459 |
#full - level2 PLUS constant points, constant rectangles (dangerous)" |
|
212
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
460 |
|
ff39051e219f
more constant folding options
Claus Gittinger <cg@exept.de>
parents:
210
diff
changeset
|
461 |
FoldConstants := aSymbol |
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
462 |
|
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
463 |
"Created: 9.2.1996 / 17:40:34 / cg" |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
464 |
! |
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
465 |
|
141 | 466 |
implicitSelfSends |
467 |
"return true if undefined variables with |
|
468 |
lowercase first character are to be turned |
|
469 |
into implicit self sends" |
|
470 |
||
471 |
^ ImplicitSelfSends |
|
472 |
! |
|
473 |
||
474 |
implicitSelfSends:aBoolean |
|
475 |
"turn on/off implicit self sends" |
|
476 |
||
477 |
ImplicitSelfSends := aBoolean |
|
478 |
||
479 |
" |
|
480 |
Compiler implicitSelfSends:true |
|
481 |
Compiler implicitSelfSends:false |
|
482 |
" |
|
377 | 483 |
! |
484 |
||
485 |
lineNumberInfo |
|
486 |
^ LineNumberInfo |
|
487 |
! |
|
488 |
||
489 |
lineNumberInfo:aBoolean |
|
490 |
LineNumberInfo := aBoolean |
|
752 | 491 |
! |
492 |
||
493 |
stringsAreImmutable |
|
494 |
"return true if strings are immutable literals" |
|
495 |
||
496 |
^ StringsAreImmutable |
|
497 |
||
498 |
"Created: / 3.8.1998 / 14:53:25 / cg" |
|
499 |
! |
|
500 |
||
501 |
stringsAreImmutable:aBoolean |
|
502 |
"turn on/off immutable string literals - default is false for ST-80 compatibilty." |
|
503 |
||
504 |
StringsAreImmutable := aBoolean. |
|
505 |
||
506 |
" |
|
507 |
can be added to your private.rc file: |
|
508 |
||
509 |
Compiler stringsAreImmutable:true |
|
510 |
Compiler stringsAreImmutable:false |
|
511 |
" |
|
512 |
||
513 |
"Created: / 3.8.1998 / 14:53:28 / cg" |
|
1160 | 514 |
! |
515 |
||
1523
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
516 |
warnAboutVariableNameConventions |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
517 |
"controls generation of warning messages about wrong variable names" |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
518 |
|
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
519 |
^ WarnAboutVariableNameConventions |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
520 |
! |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
521 |
|
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
522 |
warnAboutVariableNameConventions:aBoolean |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
523 |
"controls generation of warning messages about wrong variable names" |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
524 |
|
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
525 |
WarnAboutVariableNameConventions := aBoolean |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
526 |
! |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
527 |
|
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
528 |
warnAboutWrongVariableNames |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
529 |
"controls generation of warning messages about wrong variable names" |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
530 |
|
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
531 |
^ WarnAboutWrongVariableNames |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
532 |
! |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
533 |
|
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
534 |
warnAboutWrongVariableNames:aBoolean |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
535 |
"controls generation of warning messages about wrong variable names" |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
536 |
|
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
537 |
WarnAboutWrongVariableNames := aBoolean |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
538 |
! |
7846be9771d6
checkVariable-conventions accessors
Claus Gittinger <cg@exept.de>
parents:
1522
diff
changeset
|
539 |
|
1160 | 540 |
warnUnusedVars |
541 |
"controls generation of warning messages about unued method variables" |
|
542 |
||
543 |
^ WarnUnusedVars |
|
544 |
! |
|
545 |
||
546 |
warnUnusedVars:aBoolean |
|
547 |
"controls generation of warning messages about unued method variables" |
|
548 |
||
549 |
WarnUnusedVars := aBoolean |
|
19 | 550 |
! ! |
0 | 551 |
|
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
552 |
!Parser class methodsFor:'defaults'! |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
553 |
|
1413 | 554 |
allowArrayIndexSyntaxExtension |
555 |
"experimental" |
|
556 |
||
557 |
^ AllowArrayIndexSyntaxExtension ? false |
|
558 |
! |
|
559 |
||
560 |
allowArrayIndexSyntaxExtension:aBoolean |
|
561 |
"experimental" |
|
562 |
||
563 |
AllowArrayIndexSyntaxExtension := aBoolean. |
|
564 |
||
565 |
" |
|
566 |
self allowArrayIndexSyntaxExtension:true |
|
567 |
self allowArrayIndexSyntaxExtension:false |
|
568 |
" |
|
569 |
! |
|
570 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
571 |
allowReservedWordsAsSelectors |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
572 |
"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
|
573 |
as unary message selectors." |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
574 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
575 |
^ AllowReservedWordsAsSelectors ? false |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
576 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
577 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
578 |
allowReservedWordsAsSelectors:aBoolean |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
579 |
"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
|
580 |
as unary message selectors." |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
581 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
582 |
AllowReservedWordsAsSelectors := aBoolean. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
583 |
self setupActions |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
584 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
585 |
" |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
586 |
self allowReservedWordsAsSelectors:true |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
587 |
self allowReservedWordsAsSelectors:false |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
588 |
" |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
589 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
590 |
|
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
591 |
maxLineNumber |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
592 |
"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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
|
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
597 |
^ 255 |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
598 |
|
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
599 |
"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
|
600 |
! ! |
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
601 |
|
1187 | 602 |
!Parser class methodsFor:'error correction'! |
603 |
||
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
604 |
findBest:nMax selectorsFor:aString in:aClassOrNil |
1187 | 605 |
"collect known selectors with their spelling distances to aString; |
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
606 |
return the nMax best suggestions. If the argument, aClassOrNil is not nil, |
1187 | 607 |
the message is assumed to be sent to instances of that class (i.e. offer |
608 |
corrections from that hierarchy only)" |
|
609 |
||
1286 | 610 |
|info block lcSelector| |
1187 | 611 |
|
612 |
info := SortedCollection new. |
|
613 |
info sortBlock:[:a :b | a value > b value]. |
|
614 |
||
615 |
lcSelector := aString asLowercase. |
|
616 |
||
617 |
block := [:sym :mthd| |
|
1215 | 618 |
|dist lcSym keepThis| |
1187 | 619 |
|
620 |
lcSym := sym asLowercase. |
|
621 |
(info contains:[:i | i key == sym]) ifFalse:[ |
|
622 |
dist := lcSelector spellAgainst:lcSym. |
|
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
623 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
624 |
(lcSym startsWith:lcSelector) ifTrue:[ |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
625 |
dist := dist + (aString size * 10). |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
626 |
]. |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
627 |
|
1215 | 628 |
(dist > 20) ifTrue:[ |
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
629 |
(info contains:[:entry | entry key = sym]) ifFalse:[ |
1215 | 630 |
keepThis := true. |
631 |
info size >= nMax ifTrue:[ |
|
632 |
"will remove last entry anyway - so check if this one will remain ..." |
|
633 |
dist < info last value ifTrue:[ |
|
634 |
keepThis := false. |
|
635 |
] |
|
636 |
]. |
|
637 |
keepThis ifTrue:[ |
|
638 |
"expensive - therefore do this check at last" |
|
639 |
mthd isObsolete ifFalse:[ |
|
640 |
info add:(sym -> dist). |
|
641 |
info size > nMax ifTrue:[ |
|
642 |
info removeLast. |
|
643 |
] |
|
644 |
] |
|
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
645 |
] |
1187 | 646 |
] |
647 |
] |
|
648 |
] |
|
649 |
]. |
|
650 |
||
651 |
aClassOrNil isNil ifTrue:[ |
|
652 |
Smalltalk allClassesDo:[:cls | |
|
653 |
cls methodDictionary keysAndValuesDo:block. |
|
654 |
cls class methodDictionary keysAndValuesDo:block. |
|
655 |
] |
|
656 |
] ifFalse:[ |
|
657 |
aClassOrNil withAllSuperclassesDo:[:cls | |
|
658 |
cls methodDictionary keysAndValuesDo:block. |
|
1323 | 659 |
"/ cls class methodDictionary keysAndValuesDo:block. |
1187 | 660 |
] |
661 |
]. |
|
662 |
||
663 |
^ info asOrderedCollection collect:[:a | a key] |
|
664 |
||
665 |
"Modified: / 19.1.2000 / 16:43:37 / cg" |
|
1199
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
666 |
! |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
667 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
668 |
findBestSelectorsFor:aString |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
669 |
"collect known selectors with their spelling distances to aString; |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
670 |
return the 10 best suggestions" |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
671 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
672 |
^ self findBestSelectorsFor:aString in:nil |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
673 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
674 |
" |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
675 |
Parser findBestSelectorsFor:'at' |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
676 |
Parser findBestSelectorsFor:'at:pu' |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
677 |
" |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
678 |
! |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
679 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
680 |
findBestSelectorsFor:aString in:aClassOrNil |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
681 |
"collect known selectors with their spelling distances to aString; |
1323 | 682 |
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
|
683 |
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
|
684 |
corrections from that hierarchy only)" |
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
685 |
|
3ffc14d393a7
best selector matching improved
Claus Gittinger <cg@exept.de>
parents:
1197
diff
changeset
|
686 |
^ self |
1323 | 687 |
findBest:15 selectorsFor:aString in:aClassOrNil |
1187 | 688 |
! ! |
689 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
690 |
!Parser class methodsFor:'evaluating expressions'! |
0 | 691 |
|
19 | 692 |
evaluate:aStringOrStream |
71 | 693 |
"return the result of evaluating an expression in aStringOrStream. |
694 |
No doit-entry is added to the changeLog." |
|
0 | 695 |
|
19 | 696 |
^ self |
44 | 697 |
evaluate:aStringOrStream |
698 |
in:nil |
|
699 |
receiver:nil |
|
700 |
notifying:nil |
|
701 |
logged:false |
|
702 |
ifFail:nil |
|
71 | 703 |
compile:true |
19 | 704 |
|
705 |
" |
|
706 |
Compiler evaluate:'1 + 2' |
|
707 |
Compiler evaluate:'''hello world'' asSortedCollection displayString printNL' |
|
708 |
Compiler evaluate:'''hello world'' asSortedCollection printNL' |
|
709 |
" |
|
0 | 710 |
! |
711 |
||
71 | 712 |
evaluate:aStringOrStream compile:compile |
713 |
"return the result of evaluating aString, |
|
714 |
The compile argument specifies if the string should be compiled down to |
|
715 |
bytecode or instead be interpreted from the parseTree. |
|
716 |
The first should be done for doIts etc, where a readable walkback is |
|
717 |
required. |
|
718 |
The latter is better done for constants, styleSheet and resource |
|
719 |
reading and simple sends, where the overhead of compilation is bigger |
|
720 |
than the interpretation overhead." |
|
721 |
||
722 |
^ self |
|
723 |
evaluate:aStringOrStream |
|
724 |
in:nil |
|
725 |
receiver:nil |
|
726 |
notifying:nil |
|
727 |
logged:false |
|
728 |
ifFail:nil |
|
729 |
compile:compile |
|
730 |
! |
|
731 |
||
20 | 732 |
evaluate:aStringOrStream ifFail:failBlock |
733 |
"return the result of evaluating an expression in aStringOrStream. |
|
71 | 734 |
In case of any syntax errors, return the value of failBlock. |
735 |
No doit-entry is added to the changeLog." |
|
20 | 736 |
|
737 |
^ self |
|
44 | 738 |
evaluate:aStringOrStream |
739 |
in:nil |
|
740 |
receiver:nil |
|
741 |
notifying:nil |
|
742 |
logged:false |
|
743 |
ifFail:failBlock |
|
71 | 744 |
compile:true |
20 | 745 |
" |
746 |
Compiler evaluate:'1 +' ifFail:['oops'] |
|
747 |
" |
|
748 |
! |
|
749 |
||
71 | 750 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor ifFail:failBlock |
751 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
752 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
753 |
No doIt entry is added to the change-file. |
|
754 |
If the failBlock argument is non-nil, it is evaluated if an error occurs." |
|
755 |
||
756 |
^ self |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
757 |
evaluate:aStringOrStream |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
758 |
in:aContext |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
759 |
receiver:anObject |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
760 |
notifying:requestor |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
761 |
logged:false |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
762 |
ifFail:nil |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
763 |
compile:true |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
764 |
|
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
765 |
"Modified: / 17.1.1998 / 02:54:07 / cg" |
20 | 766 |
! |
767 |
||
768 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock |
|
769 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
770 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
771 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
772 |
is non-nil, it is evaluated if an error occurs." |
|
773 |
||
71 | 774 |
^ self |
775 |
evaluate:aStringOrStream |
|
776 |
in:aContext |
|
777 |
receiver:anObject |
|
778 |
notifying:requestor |
|
779 |
logged:logged |
|
780 |
ifFail:failBlock |
|
781 |
compile:true |
|
782 |
! |
|
783 |
||
784 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile |
|
785 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
786 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
787 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
788 |
is non-nil, it is evaluated if an error occurs. |
|
789 |
Finally, compile specifies if the string should be compiled down to |
|
790 |
bytecode or instead be interpreted from the parseTree. |
|
791 |
The first should be done for doIts etc, where a readable walkback is |
|
792 |
required. |
|
793 |
The latter is better done for constants, styleSheet and resource |
|
794 |
reading and simple sends, where the overhead of compilation is bigger |
|
795 |
than the interpretation overhead." |
|
796 |
||
1363 | 797 |
^ self new |
1548 | 798 |
evaluate:aStringOrStream |
799 |
in:aContext |
|
800 |
receiver:anObject |
|
801 |
notifying:requestor |
|
802 |
logged:logged |
|
803 |
ifFail:failBlock |
|
804 |
compile:compile |
|
1561
175735dcd732
do not check for endOfInput if parsing from a Stream
Claus Gittinger <cg@exept.de>
parents:
1557
diff
changeset
|
805 |
checkForEndOfInput:(aStringOrStream isStream not) |
141 | 806 |
! |
807 |
||
808 |
evaluate:aStringOrStream logged:logged |
|
809 |
"return the result of evaluating an expression in aStringOrStream. |
|
810 |
The argument log controls if an entry is added to the changeLog." |
|
811 |
||
812 |
^ self |
|
813 |
evaluate:aStringOrStream |
|
814 |
in:nil |
|
815 |
receiver:nil |
|
816 |
notifying:nil |
|
817 |
logged:logged |
|
818 |
ifFail:nil |
|
819 |
compile:true |
|
820 |
" |
|
821 |
Compiler evaluate:'''some string''' logged:false |
|
822 |
Compiler evaluate:'''some string''' logged:true |
|
823 |
" |
|
824 |
! |
|
825 |
||
826 |
evaluate:aStringOrStream notifying:requestor |
|
827 |
"return the result of evaluating aString, |
|
828 |
errors are reported to requestor" |
|
829 |
||
830 |
^ self |
|
831 |
evaluate:aStringOrStream |
|
832 |
in:nil |
|
833 |
receiver:nil |
|
834 |
notifying:requestor |
|
835 |
logged:false |
|
836 |
ifFail:nil |
|
837 |
compile:true |
|
838 |
! |
|
839 |
||
840 |
evaluate:aStringOrStream notifying:requestor compile:compile |
|
841 |
"return the result of evaluating aString, |
|
842 |
errors are reported to requestor. |
|
843 |
The compile argument specifies if the string should be compiled down to |
|
844 |
bytecode or instead be interpreted from the parseTree. |
|
845 |
The first should be done for doIts etc, where a readable walkback is |
|
846 |
required. |
|
847 |
The latter is better done for constants, styleSheet and resource |
|
848 |
reading and simple sends, where the overhead of compilation is bigger |
|
849 |
than the interpretation overhead." |
|
850 |
||
851 |
^ self |
|
852 |
evaluate:aStringOrStream |
|
853 |
in:nil |
|
854 |
receiver:nil |
|
855 |
notifying:requestor |
|
856 |
logged:false |
|
857 |
ifFail:nil |
|
858 |
compile:compile |
|
859 |
! |
|
860 |
||
1025
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
861 |
evaluate:aStringOrStream notifying:requestor logged:logged |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
862 |
"return the result of evaluating aString, |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
863 |
errors are reported to requestor" |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
864 |
|
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
865 |
^ self |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
866 |
evaluate:aStringOrStream |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
867 |
in:nil |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
868 |
receiver:nil |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
869 |
notifying:requestor |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
870 |
logged:logged |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
871 |
ifFail:nil |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
872 |
compile:true |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
873 |
! |
5b3022ecb269
added #evaluate:notifying:logged: (for RB)
Claus Gittinger <cg@exept.de>
parents:
1022
diff
changeset
|
874 |
|
572 | 875 |
evaluate:aStringOrStream receiver:anObject |
876 |
"return the result of evaluating aString, |
|
877 |
errors are reported to requestor. Allow access to |
|
878 |
anObject as self and to its instVars " |
|
879 |
||
880 |
^ self |
|
619 | 881 |
evaluate:aStringOrStream |
882 |
in:nil |
|
883 |
receiver:anObject |
|
884 |
notifying:nil |
|
885 |
logged:false |
|
886 |
ifFail:nil |
|
887 |
compile:true |
|
572 | 888 |
|
889 |
" |
|
890 |
Compiler evaluate:'self x' receiver:(1 @ 2) |
|
891 |
" |
|
892 |
||
893 |
"Created: 1.7.1997 / 19:02:24 / cg" |
|
894 |
"Modified: 1.7.1997 / 19:02:33 / cg" |
|
895 |
! |
|
896 |
||
919 | 897 |
evaluate:aStringOrStream receiver:someOne logged:logged |
898 |
"return the result of evaluating an expression in aStringOrStream. |
|
899 |
The argument log controls if an entry is added to the changeLog." |
|
900 |
||
901 |
^ self |
|
902 |
evaluate:aStringOrStream |
|
903 |
in:nil |
|
904 |
receiver:someOne |
|
905 |
notifying:nil |
|
906 |
logged:logged |
|
907 |
ifFail:nil |
|
908 |
compile:true |
|
909 |
" |
|
910 |
Compiler evaluate:'''some string''' logged:false |
|
911 |
Compiler evaluate:'''some string''' logged:true |
|
912 |
Compiler evaluate:'self class' receiver:nil logged:false |
|
913 |
Compiler evaluate:'self class' receiver:1 logged:false |
|
914 |
" |
|
915 |
! |
|
916 |
||
141 | 917 |
evaluate:aStringOrStream receiver:anObject notifying:requestor |
918 |
"return the result of evaluating aString, |
|
919 |
errors are reported to requestor. Allow access to |
|
920 |
anObject as self and to its instVars (used in the inspector)" |
|
921 |
||
922 |
^ self |
|
923 |
evaluate:aStringOrStream |
|
924 |
in:nil |
|
925 |
receiver:anObject |
|
926 |
notifying:requestor |
|
927 |
logged:false |
|
928 |
ifFail:nil |
|
929 |
compile:true |
|
930 |
||
931 |
" |
|
932 |
Compiler evaluate:'self x' receiver:(1 @ 2) notifying:nil |
|
933 |
" |
|
934 |
! |
|
935 |
||
936 |
evaluate:aStringOrStream receiver:anObject notifying:requestor compile:compile |
|
937 |
"return the result of evaluating aString, |
|
938 |
errors are reported to requestor. Allow access to |
|
939 |
anObject as self and to its instVars (used in the inspector). |
|
940 |
The compile argument specifies if the string should be compiled down to |
|
941 |
bytecode or instead be interpreted from the parseTree. |
|
942 |
The first should be done for doIts etc, where a readable walkback is |
|
943 |
required. |
|
944 |
The latter is better done for constants, styleSheet and resource |
|
945 |
reading and simple sends, where the overhead of compilation is bigger |
|
946 |
than the interpretation overhead." |
|
947 |
||
948 |
^ self |
|
949 |
evaluate:aStringOrStream |
|
950 |
in:nil |
|
951 |
receiver:anObject |
|
952 |
notifying:requestor |
|
953 |
logged:false |
|
954 |
ifFail:nil |
|
955 |
compile:compile |
|
1548 | 956 |
! |
957 |
||
958 |
evaluateFrom:aStringOrStream ifFail:failBlock |
|
959 |
"return the result of evaluating an expression from aStringOrStream. |
|
960 |
In case of any syntax errors, return the value of failBlock. |
|
961 |
No doit-entry is added to the changeLog." |
|
962 |
||
963 |
^ self |
|
964 |
evaluateFrom:aStringOrStream |
|
965 |
in:nil |
|
966 |
receiver:nil |
|
967 |
notifying:nil |
|
968 |
logged:false |
|
969 |
ifFail:failBlock |
|
970 |
compile:true |
|
971 |
" |
|
972 |
Compiler evaluate:'1 + 2' ifFail:['oops'] |
|
973 |
" |
|
974 |
! |
|
975 |
||
976 |
evaluateFrom:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile |
|
977 |
"return the result of evaluating the next expression from aStringOrStream, errors are reported to requestor. |
|
978 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
979 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
980 |
is non-nil, it is evaluated if an error occurs. |
|
981 |
Finally, compile specifies if the string should be compiled down to |
|
982 |
bytecode or instead be interpreted from the parseTree. |
|
983 |
The first should be done for doIts etc, where a readable walkback is |
|
984 |
required. |
|
985 |
The latter is better done for constants, styleSheet and resource |
|
986 |
reading and simple sends, where the overhead of compilation is bigger |
|
987 |
than the interpretation overhead." |
|
988 |
||
989 |
^ self new |
|
990 |
evaluate:aStringOrStream |
|
991 |
in:aContext |
|
992 |
receiver:anObject |
|
993 |
notifying:requestor |
|
994 |
logged:logged |
|
995 |
ifFail:failBlock |
|
996 |
compile:compile |
|
997 |
checkForEndOfInput:false |
|
0 | 998 |
! ! |
999 |
||
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
1000 |
!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
|
1001 |
|
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
1002 |
argAndVarNamesForContext:aContext |
1546 | 1003 |
<resource:#obsolete> |
1446
ac887ee4881a
** changed access to blockContexts source, args and vars -- please watch out
penk
parents:
1445
diff
changeset
|
1004 |
self obsoleteMethodWarning. |
ac887ee4881a
** changed access to blockContexts source, args and vars -- please watch out
penk
parents:
1445
diff
changeset
|
1005 |
^ aContext argAndVarNames. |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
1006 |
! ! |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
1007 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
1008 |
!Parser class methodsFor:'parsing'! |
141 | 1009 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1010 |
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
|
1011 |
"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
|
1012 |
return the containing BlockNode or nil. |
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1013 |
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
|
1014 |
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
|
1015 |
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
|
1016 |
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
|
1017 |
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
|
1018 |
|
429 | 1019 |
|compiler tree mSource who mClass blocks |
397 | 1020 |
maxSoFar innerBlock m| |
1021 |
||
481
187a88a9695d
care for maxLineNo when looking for a block-by-lineNo
Claus Gittinger <cg@exept.de>
parents:
480
diff
changeset
|
1022 |
(line isNil or:[line == self maxLineNumber]) ifTrue:[ |
815 | 1023 |
^ nil |
457
ad25339043ef
care for nil-lineNumber when looking for a block
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
1024 |
]. |
ad25339043ef
care for nil-lineNumber when looking for a block
Claus Gittinger <cg@exept.de>
parents:
455
diff
changeset
|
1025 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1026 |
aMethod notNil ifTrue:[ |
815 | 1027 |
m := aMethod. |
1028 |
who := m who. |
|
1029 |
who isNil ifTrue:[ |
|
1030 |
m isWrapped ifTrue:[ |
|
1031 |
m := m wrapper. |
|
1032 |
m notNil ifTrue:[ |
|
1033 |
who := m who. |
|
1034 |
] |
|
1035 |
] |
|
1036 |
]. |
|
1037 |
who notNil ifTrue:[ |
|
1038 |
mClass := who methodClass. |
|
1039 |
mClass isNil ifTrue:[ ^ nil]. |
|
1040 |
]. |
|
1041 |
||
1042 |
mSource := m source. |
|
1043 |
mSource isNil ifTrue:[^ nil]. |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1044 |
] ifFalse:[ |
815 | 1045 |
aString notNil ifTrue:[ |
1046 |
mSource := aString. |
|
1047 |
mClass := UndefinedObject |
|
1048 |
] ifFalse:[ |
|
1049 |
^ nil |
|
1050 |
] |
|
397 | 1051 |
]. |
1052 |
||
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1053 |
"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
|
1054 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1055 |
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
|
1056 |
compiler parseForCode. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1057 |
compiler notifying:nil. |
1365 | 1058 |
compiler ignoreWarnings:true. |
1059 |
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
|
1060 |
compiler lineNumberInfo:#full. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1061 |
|
1515
8ffe6db5e53f
suppress notifications while searching for blockAtLine.
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
1062 |
Notification |
8ffe6db5e53f
suppress notifications while searching for blockAtLine.
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
1063 |
handle: |
8ffe6db5e53f
suppress notifications while searching for blockAtLine.
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
1064 |
[:ex | |
8ffe6db5e53f
suppress notifications while searching for blockAtLine.
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
1065 |
ex proceed |
8ffe6db5e53f
suppress notifications while searching for blockAtLine.
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
1066 |
] |
8ffe6db5e53f
suppress notifications while searching for blockAtLine.
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
1067 |
do:[ |
1514 | 1068 |
aMethod notNil ifTrue:[ |
1069 |
(compiler parseMethodSpec == #Error) ifTrue:[ |
|
1070 |
^ nil. |
|
1071 |
]. |
|
1072 |
||
1073 |
who notNil ifTrue:[ |
|
1074 |
compiler selector ~~ (who methodSelector) ifTrue:[ |
|
1075 |
^ nil |
|
1076 |
] |
|
1077 |
]. |
|
1078 |
] ifFalse:[ |
|
1079 |
compiler nextToken. |
|
1080 |
]. |
|
1081 |
||
1082 |
tree := compiler parseMethodBody. |
|
1515
8ffe6db5e53f
suppress notifications while searching for blockAtLine.
Claus Gittinger <cg@exept.de>
parents:
1514
diff
changeset
|
1083 |
]. |
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1084 |
|
815 | 1085 |
(compiler errorFlag |
1086 |
or:[tree == #Error |
|
1087 |
or:[tree isNil]]) ifTrue:[ |
|
1088 |
^ nil |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1089 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1090 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1091 |
blocks := OrderedCollection new. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1092 |
tree collectBlocksInto:blocks. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1093 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1094 |
blocks := blocks select:[:aBlock | |
815 | 1095 |
line between: aBlock lineNumber and:aBlock endLineNumber |
1096 |
||
1097 |
]. |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1098 |
blocks size == 1 ifTrue:[ |
815 | 1099 |
^ 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
|
1100 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1101 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1102 |
nA notNil ifTrue:[ |
815 | 1103 |
blocks := blocks select:[:aBlock | |
1104 |
aBlock numArgs == nA |
|
1105 |
]. |
|
1106 |
blocks size == 1 ifTrue:[ |
|
1107 |
^ blocks at:1 |
|
1108 |
]. |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1109 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1110 |
nV notNil ifTrue:[ |
815 | 1111 |
blocks := blocks select:[:aBlock | |
1112 |
aBlock numVars == nV |
|
1113 |
]. |
|
1114 |
blocks size == 1 ifTrue:[ |
|
1115 |
^ blocks at:1 |
|
1116 |
]. |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1117 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1118 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1119 |
"/ 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
|
1120 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1121 |
maxSoFar := 0. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1122 |
blocks do:[:aBlock | |
815 | 1123 |
aBlock lineNumber > maxSoFar ifTrue:[ |
1124 |
innerBlock := aBlock. |
|
1125 |
maxSoFar := aBlock lineNumber |
|
1126 |
] |
|
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1127 |
]. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1128 |
^ innerBlock. |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1129 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1130 |
"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
|
1131 |
"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
|
1132 |
! |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
1133 |
|
1365 | 1134 |
checkMethod:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
629 | 1135 |
"parse a method in a given class. |
1136 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1137 |
The parser can be queried for selector, receiver, args, locals, |
|
1138 |
used selectors, modified instvars, referenced classvars etc. |
|
1139 |
The noErrors and noWarnings arguments specify if error and warning |
|
1140 |
messages should be sent to the Transcript or suppressed." |
|
1141 |
||
1142 |
|parser tree| |
|
1143 |
||
1144 |
aString isNil ifTrue:[^ nil]. |
|
1145 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1365 | 1146 |
parser ignoreErrors:ignoreErrors. |
1147 |
parser ignoreWarnings:ignoreWarnings. |
|
629 | 1148 |
tree := parser parseMethod. |
1149 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ nil]. |
|
1150 |
||
1151 |
ReadBeforeWrittenTester searchForReadBeforeWrittenIn:tree |
|
1152 |
||
1153 |
" |
|
1154 |
self |
|
1155 |
checkMethod:'foo |
|
1156 |
|local1 local2 local3| |
|
1157 |
||
1158 |
local1 := local2. |
|
1159 |
^ local3 |
|
1160 |
' |
|
1161 |
in:UndefinedObject |
|
1162 |
ignoreErrors:true |
|
1163 |
ignoreWarnings:true |
|
1164 |
" |
|
1165 |
||
1166 |
"Modified: / 30.10.1997 / 16:38:31 / cg" |
|
1167 |
! |
|
1168 |
||
141 | 1169 |
parseExpression:aString |
1170 |
"parse aString as an expression; |
|
1171 |
Return the parseTree (if ok), nil (for an empty string |
|
258 | 1172 |
or comment only) or #Error (syntactic error). |
1173 |
Error and warning messages are suppressed." |
|
141 | 1174 |
|
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1175 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1176 |
withSelf:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1177 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1178 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1179 |
notifying:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1180 |
ignoreErrors:true "silence on Transcript" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1181 |
ignoreWarnings:true |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1182 |
inNameSpace:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1183 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1184 |
" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1185 |
Parser parseExpression:'self foo' |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1186 |
Parser parseExpression:'self:123' |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1187 |
Parser parseExpression:'self:123' onError:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1188 |
" |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1189 |
! |
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1190 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1191 |
parseExpression:aString inNameSpace:aNameSpaceOrNil |
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1192 |
"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
|
1193 |
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
|
1194 |
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
|
1195 |
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
|
1196 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1197 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1198 |
withSelf:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1199 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1200 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1201 |
notifying:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1202 |
ignoreErrors:true "silence on Transcript" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1203 |
ignoreWarnings:true |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1204 |
inNameSpace:aNameSpaceOrNil |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1205 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1206 |
"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
|
1207 |
"Created: 24.6.1997 / 16:44:26 / cg" |
141 | 1208 |
! |
1209 |
||
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1210 |
parseExpression:aString inNameSpace:aNameSpaceOrNil onError:errorValue |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1211 |
"parse aString as an expression; |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1212 |
Return the parseTree (if ok), nil (for an empty string |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1213 |
or comment only) or errorValue (syntactic error). |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1214 |
Error and warning messages are suppressed." |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1215 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1216 |
^ self |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1217 |
withSelf:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1218 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1219 |
onError:errorValue |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1220 |
notifying:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1221 |
ignoreErrors:true "silence on Transcript" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1222 |
ignoreWarnings:true |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1223 |
inNameSpace:aNameSpaceOrNil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1224 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1225 |
"Modified: 24.6.1997 / 16:44:00 / cg" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1226 |
"Created: 24.6.1997 / 16:44:26 / cg" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1227 |
! |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1228 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1229 |
parseExpression:aString onError:errorValue |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1230 |
"parse aString as an expression; |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1231 |
Return the parseTree (if ok), nil (for an empty string |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1232 |
or comment only) or errorValue (syntactic error). |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1233 |
Error and warning messages are suppressed." |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1234 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1235 |
^ self |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1236 |
withSelf:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1237 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1238 |
onError:errorValue |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1239 |
notifying:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1240 |
ignoreErrors:true "silence on Transcript" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1241 |
ignoreWarnings:true |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1242 |
inNameSpace:nil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1243 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1244 |
"Modified: 24.6.1997 / 16:44:00 / cg" |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1245 |
! |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1246 |
|
141 | 1247 |
parseMethod:aString |
1248 |
"parse a method. |
|
1249 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1250 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 1251 |
used selectors etc. |
1252 |
Error and warning messages are sent to the Transcript." |
|
141 | 1253 |
|
1254 |
^ self parseMethod:aString in:nil |
|
1255 |
||
1256 |
" |
|
1257 |
|p| |
|
1258 |
||
1259 |
p := Parser |
|
619 | 1260 |
parseMethod:' |
1261 |
foo:arg1 bar:arg2 baz:arg3 |
|
1262 |
|l1 l2| |
|
1263 |
l1 := 0. |
|
1264 |
l2 := arg1. |
|
1265 |
^ self'. |
|
141 | 1266 |
|
1267 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
1268 |
'args: ' print. p methodArgs printNL. |
|
1269 |
'sel: ' print. p selector printNL. |
|
1270 |
'nLocal: ' print. p numberOfMethodVars printNL. |
|
1271 |
'locals: ' print. p methodVars printNL. |
|
1272 |
'tree: ' printNL. p tree printAllOn:Stdout. Stdout cr. |
|
1273 |
" |
|
258 | 1274 |
|
1275 |
"Modified: 24.4.1996 / 13:18:02 / cg" |
|
141 | 1276 |
! |
1277 |
||
1278 |
parseMethod:aString in:aClass |
|
1279 |
"parse a method in a given class. |
|
1280 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1281 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 1282 |
used selectors, modified instvars, referenced classvars etc. |
1283 |
Error and warning messages are sent to the Transcript." |
|
141 | 1284 |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1285 |
^ self |
619 | 1286 |
parseMethod:aString |
1287 |
in:aClass |
|
1288 |
ignoreErrors:false |
|
1289 |
ignoreWarnings:false |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1290 |
|
258 | 1291 |
"Modified: 24.4.1996 / 13:18:34 / cg" |
141 | 1292 |
! |
1293 |
||
1365 | 1294 |
parseMethod:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
141 | 1295 |
"parse a method in a given class. |
1296 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1297 |
The parser can be queried for selector, receiver, args, locals, |
|
258 | 1298 |
used selectors, modified instvars, referenced classvars etc. |
1299 |
The noErrors and noWarnings arguments specify if error and warning |
|
1300 |
messages should be sent to the Transcript or suppressed." |
|
141 | 1301 |
|
1302 |
|parser tree| |
|
1303 |
||
1304 |
aString isNil ifTrue:[^ nil]. |
|
1305 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1365 | 1306 |
parser ignoreErrors:ignoreErrors. |
1307 |
parser ignoreWarnings:ignoreWarnings. |
|
141 | 1308 |
tree := parser parseMethod. |
1309 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ nil]. |
|
1310 |
^ parser |
|
258 | 1311 |
|
1312 |
"Modified: 24.4.1996 / 13:19:23 / cg" |
|
141 | 1313 |
! |
1314 |
||
1315 |
parseMethod:aString in:aClass warnings:warnBoolean |
|
1316 |
"parse a method in a given class. |
|
1317 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1318 |
The parser can be queried for selector, receiver, args, locals, |
|
1319 |
used selectors, modified instvars, referenced classvars etc. |
|
258 | 1320 |
The warnBoolean arguments specifies if warning |
1321 |
messages should be sent to the Transcript or suppressed. |
|
1322 |
||
1323 |
This method is OBSOLETE, and left in for backward compatibility." |
|
1324 |
||
1325 |
self obsoleteMethodWarning. |
|
141 | 1326 |
^ self |
619 | 1327 |
parseMethod:aString |
1328 |
in:aClass |
|
1329 |
ignoreErrors:false |
|
1330 |
ignoreWarnings:warnBoolean not |
|
258 | 1331 |
|
1332 |
"Modified: 24.4.1996 / 13:28:05 / cg" |
|
141 | 1333 |
! |
1334 |
||
1335 |
parseMethodArgAndVarSpecification:aString |
|
1336 |
"parse a methods selector, arg and var spec (i.e. locals); |
|
1337 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
258 | 1338 |
The parser can be queried for selector, receiver etc. |
1339 |
Error and warning messages are sent to the Transcript. |
|
1340 |
This method is OBSOLETE." |
|
1341 |
||
1342 |
self obsoleteMethodWarning. |
|
141 | 1343 |
^ self parseMethodArgAndVarSpecification:aString in:nil |
1344 |
||
1345 |
" |
|
1346 |
|p| |
|
1347 |
||
1348 |
p := Parser |
|
619 | 1349 |
parseMethodArgAndVarSpecification:' |
1350 |
foo:arg1 bar:arg2 baz:arg3 |
|
1351 |
|l1 l2|'. |
|
141 | 1352 |
|
1353 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
1354 |
'args: ' print. p methodArgs printNL. |
|
1355 |
'sel: ' print. p selector printNL. |
|
1356 |
'nLocal: ' print. p numberOfMethodVars printNL. |
|
1357 |
'locals: ' print. p methodVars printNL. |
|
1358 |
" |
|
258 | 1359 |
|
1360 |
"Modified: 24.4.1996 / 13:29:43 / cg" |
|
141 | 1361 |
! |
1362 |
||
1363 |
parseMethodArgAndVarSpecification:aString in:aClass |
|
1364 |
"parse a methods selector, arg and var spec in a given class; |
|
1365 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
258 | 1366 |
The parser can be queried for selector, receiver, args and locals. |
1367 |
Error and warning messages are sent to the Transcript. |
|
1368 |
This method is OBSOLETE." |
|
1369 |
||
1370 |
self obsoleteMethodWarning. |
|
141 | 1371 |
^ self parseMethodArgAndVarSpecification:aString |
619 | 1372 |
in:aClass |
1373 |
ignoreErrors:false |
|
1374 |
ignoreWarnings:false |
|
1375 |
parseBody:false |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1376 |
|
258 | 1377 |
"Modified: 24.4.1996 / 13:30:03 / cg" |
141 | 1378 |
! |
1379 |
||
1365 | 1380 |
parseMethodArgAndVarSpecification:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings parseBody:body |
141 | 1381 |
"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
|
1382 |
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
|
1383 |
(for primitives & resourceSpecs). |
258 | 1384 |
The noErrors and noWarnings arguments specify if error and warning |
1385 |
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
|
1386 |
|
141 | 1387 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
1388 |
The parser can be queried for selector, receiver, args and locals" |
|
19 | 1389 |
|
0 | 1390 |
|parser| |
1391 |
||
141 | 1392 |
aString isNil ifTrue:[^ nil]. |
1393 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1365 | 1394 |
parser ignoreErrors:ignoreErrors. |
1395 |
parser ignoreWarnings:ignoreWarnings. |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1396 |
"/ parser nextToken. |
141 | 1397 |
(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
|
1398 |
"/ |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1399 |
"/ used to be #parseMethodBodyVarSpec |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1400 |
"/ - 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
|
1401 |
"/ |
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1402 |
body ifTrue:[ |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
1403 |
parser parseMethodBodyOrEmpty |
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1404 |
] ifFalse:[ |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
1405 |
parser parseMethodBodyVarSpec |
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1406 |
]. |
141 | 1407 |
parser errorFlag ifTrue:[^ nil]. |
0 | 1408 |
^ parser |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1409 |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1410 |
"Created: 24.4.1996 / 13:13:06 / cg" |
265 | 1411 |
"Modified: 27.4.1996 / 16:58:02 / cg" |
141 | 1412 |
! |
1413 |
||
1414 |
parseMethodArgAndVarSpecificationSilent:aString |
|
1415 |
"parse a methods selector, arg and var spec (i.e. locals); |
|
1416 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1417 |
The parser can be queried for selector, receiver etc. |
|
258 | 1418 |
Like #parseMethodArgAndVarSpecification:, but does NOT |
141 | 1419 |
display error/warning messages on the transcript." |
1420 |
||
1421 |
^ self parseMethodArgAndVarSpecificationSilent:aString in:nil |
|
258 | 1422 |
|
1423 |
"Modified: 24.4.1996 / 13:30:54 / cg" |
|
141 | 1424 |
! |
1425 |
||
1426 |
parseMethodArgAndVarSpecificationSilent:aString in:aClass |
|
1427 |
"parse a methods selector, arg and var spec in a given class; |
|
1428 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1429 |
The parser can be queried for selector, receiver, args and locals. |
|
1430 |
Like #parseMethodArgAndVarSpecification:in:, but does not |
|
1431 |
display error/warning messages on the transcript." |
|
1432 |
||
1433 |
^ self parseMethodArgAndVarSpecification:aString |
|
619 | 1434 |
in:aClass |
1435 |
ignoreErrors:true |
|
1436 |
ignoreWarnings:true |
|
1437 |
parseBody:false |
|
257
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1438 |
|
435dcaed969f
dont parse body (when interrested in args & locals only)
Claus Gittinger <cg@exept.de>
parents:
255
diff
changeset
|
1439 |
"Modified: 24.4.1996 / 13:14:27 / cg" |
141 | 1440 |
! |
1441 |
||
1442 |
parseMethodSilent:aString |
|
1443 |
"parse a method. |
|
1444 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1445 |
The parser can be queried for selector, receiver, args, locals, |
|
1446 |
used selectors etc. |
|
258 | 1447 |
Like #parseMethod:, but warning/error messages are suppressed." |
141 | 1448 |
|
1449 |
^ self parseMethodSilent:aString in:nil |
|
258 | 1450 |
|
1451 |
"Modified: 24.4.1996 / 13:32:44 / cg" |
|
141 | 1452 |
! |
1453 |
||
1454 |
parseMethodSilent:aString in:aClass |
|
1455 |
"parse a method in a given class. |
|
1456 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1457 |
The parser can be queried for selector, receiver, args, locals, |
|
1458 |
used selectors, modified instvars, referenced classvars etc. |
|
258 | 1459 |
Like #parseMethod:in:, but warning/error messages are suppressed." |
1460 |
||
1461 |
^ self |
|
619 | 1462 |
parseMethod:aString |
1463 |
in:aClass |
|
1464 |
ignoreErrors:true |
|
1465 |
ignoreWarnings:true |
|
258 | 1466 |
|
1467 |
"Modified: 24.4.1996 / 13:32:57 / cg" |
|
141 | 1468 |
! |
1469 |
||
1470 |
parseMethodSpecification:aString |
|
1471 |
"parse a methods selector & arg specification; |
|
1472 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1473 |
The parser can be queried for selector, receiver etc." |
|
1474 |
||
1475 |
^ self parseMethodSpecification:aString in:nil |
|
1476 |
||
1477 |
" |
|
1478 |
|p| |
|
1479 |
||
1480 |
p := Parser parseMethodSpecification:'foo:arg1 bar:arg2 baz:arg3'. |
|
1481 |
'nArgs: ' print. p numberOfMethodArgs printNL. |
|
1482 |
'args: ' print. p methodArgs printNL. |
|
1483 |
'sel: ' print. p selector printNL |
|
1484 |
" |
|
1485 |
! |
|
1486 |
||
1487 |
parseMethodSpecification:aString in:aClass |
|
1488 |
"parse a methods selector & arg spec for a given class; |
|
1489 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1490 |
The parser can be queried for selector, receiver etc." |
|
1491 |
||
1492 |
^ self parseMethodSpecification:aString |
|
1493 |
in:aClass |
|
1494 |
ignoreErrors:false |
|
1495 |
ignoreWarnings:false |
|
1496 |
! |
|
1497 |
||
1365 | 1498 |
parseMethodSpecification:aString in:aClass ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
141 | 1499 |
"parse a methods selector & arg spec for a given class; |
1500 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1501 |
The parser can be queried for selector, receiver etc. |
|
1502 |
noErrors and noWarnings specify if error- and warningMessages are |
|
1503 |
to be output onto the Transcript." |
|
1504 |
||
1505 |
|parser tree| |
|
1506 |
||
1507 |
aString isNil ifTrue:[^ nil]. |
|
1508 |
parser := self for:(ReadStream on:aString) in:aClass. |
|
1365 | 1509 |
parser ignoreErrors:ignoreErrors. |
1510 |
parser ignoreWarnings:ignoreWarnings. |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1511 |
"/ parser nextToken. |
141 | 1512 |
tree := parser parseMethodSpec. |
1513 |
(parser errorFlag or:[tree == #Error]) ifTrue:[^ #Error]. |
|
1514 |
^ parser |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1515 |
|
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
1516 |
"Modified: 20.4.1996 / 20:09:48 / cg" |
141 | 1517 |
! |
1518 |
||
1519 |
parseMethodSpecificationSilent:aString |
|
1520 |
"parse a methods selector & arg specification; |
|
1521 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1522 |
The parser can be queried for selector, receiver etc. |
|
1523 |
Like #parseMethodSpecification:, but does not display any error/warning Messages on the transcript." |
|
1524 |
||
1525 |
^ self parseMethodSpecificationSilent:aString in:nil |
|
1526 |
! |
|
1527 |
||
1528 |
parseMethodSpecificationSilent:aString in:aClass |
|
1529 |
"parse a methods selector & arg spec for a given class; |
|
1530 |
Return a parser (if ok), nil (empty) or #Error (syntax). |
|
1531 |
The parser can be queried for selector, receiver etc. |
|
1532 |
Like #parseMethodSpecification:in:, but does not display any error/warning Messages on the transcript." |
|
1533 |
||
1534 |
^ self parseMethodSpecification:aString |
|
1535 |
in:aClass |
|
1536 |
ignoreErrors:true |
|
1537 |
ignoreWarnings:true |
|
1538 |
||
1539 |
"Created: 31.10.1995 / 14:37:49 / cg" |
|
1540 |
! |
|
0 | 1541 |
|
7 | 1542 |
selectorInExpression:aString |
47 | 1543 |
"parse an expression - return the selector. Even malformed expressions |
1544 |
(such as missing receiver or missing arg are parsed. |
|
1545 |
Used for the SystemBrowsers implementors/senders query-box initial text. |
|
21 | 1546 |
Returns nil if unparsable." |
7 | 1547 |
|
1297
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1548 |
|tree parser sel| |
7 | 1549 |
|
813
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1550 |
(aString size == 0) ifTrue:[^ nil]. |
7 | 1551 |
|
1297
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1552 |
Error |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1553 |
handle:[:ex | ] |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1554 |
do:[ |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1555 |
tree := self withSelf:nil |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1556 |
parseExpression:aString |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1557 |
notifying:nil |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1558 |
ignoreErrors:true |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1559 |
ignoreWarnings:true. |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1560 |
]. |
21 | 1561 |
|
1562 |
" |
|
1563 |
special: take the expression of the right side, if its an |
|
1564 |
assignment or return |
|
1565 |
" |
|
7 | 1566 |
(tree notNil and:[tree ~~ #Error]) ifTrue:[ |
813
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1567 |
(tree isAssignment |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1568 |
or:[tree isReturnNode]) ifTrue:[ |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1569 |
tree expression isMessage ifTrue:[ |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1570 |
tree := tree expression |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1571 |
] |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1572 |
]. |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1573 |
tree isMessage ifTrue:[ |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1574 |
^ tree selector |
4d3ec8ff238c
(isNil or:[isEmpty ]) -> (size == 0)
Claus Gittinger <cg@exept.de>
parents:
807
diff
changeset
|
1575 |
]. |
7 | 1576 |
]. |
1577 |
||
21 | 1578 |
" |
1579 |
mhmh, try expression without receiver |
|
1580 |
" |
|
7 | 1581 |
parser := self for:(ReadStream on:aString). |
1365 | 1582 |
parser ignoreErrors:true. |
1297
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1583 |
Error |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1584 |
handle:[:ex | ] |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1585 |
do:[ |
1482
d80c83f1167a
catch twoByte string parsing in selectorInExpression
Claus Gittinger <cg@exept.de>
parents:
1471
diff
changeset
|
1586 |
parser nextToken. |
1297
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1587 |
sel := parser degeneratedKeywordExpressionForSelector |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1588 |
]. |
67332caafef7
catch errors when extracting a message selector
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
1589 |
^ sel |
7 | 1590 |
|
1591 |
" |
|
20 | 1592 |
Parser selectorInExpression:'foo at:1 put:(5 * bar)' |
1593 |
Parser selectorInExpression:'(foo at:1) at:1' |
|
47 | 1594 |
Parser selectorInExpression:'a + 4' |
1595 |
Parser selectorInExpression:'a negated' |
|
20 | 1596 |
Parser selectorInExpression:'at:1 put:5' |
47 | 1597 |
Parser selectorInExpression:'at:1 put:' |
1598 |
Parser selectorInExpression:'a at:1 put:5' |
|
1599 |
Parser selectorInExpression:'a at:1 put:' |
|
20 | 1600 |
Parser selectorInExpression:'a := foo at:1 put:5' |
7 | 1601 |
" |
451 | 1602 |
|
1603 |
"Modified: 17.12.1996 / 12:12:47 / cg" |
|
7 | 1604 |
! |
1605 |
||
1606 |
withSelf:anObject parseExpression:aString notifying:someOne |
|
1607 |
"parse aString as an expression with self set to anObject; |
|
21 | 1608 |
Return the parseTree (if ok), nil (for an empty string |
1609 |
or comment only ) or #Error (syntactic error). |
|
1610 |
||
1611 |
Errors and warnings are forwarded to someOne (usually some |
|
1612 |
codeView) which can highlight it and show a popup box." |
|
7 | 1613 |
|
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1614 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1615 |
withSelf:anObject |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1616 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1617 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1618 |
notifying:someOne |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1619 |
ignoreErrors:false |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1620 |
ignoreWarnings:false |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1621 |
inNameSpace:nil |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1622 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1623 |
"Modified: 24.6.1997 / 16:43:37 / cg" |
7 | 1624 |
! |
1625 |
||
1626 |
withSelf:anObject parseExpression:aString notifying:someOne ignoreErrors:ignore |
|
0 | 1627 |
"parse aString as an expression with self set to anObject; |
21 | 1628 |
Return the parseTree (if ok), nil (for an empty string |
1629 |
or comment only ) or #Error (syntactic error). |
|
1630 |
||
1631 |
Errors and warnings are forwarded to someOne (usually some |
|
1632 |
codeView) which can highlight it and show a popup box." |
|
1633 |
||
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1634 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1635 |
withSelf:anObject |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1636 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1637 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1638 |
notifying:someOne |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1639 |
ignoreErrors:ignore |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1640 |
ignoreWarnings:ignore |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1641 |
inNameSpace:nil |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1642 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1643 |
"Modified: 24.6.1997 / 16:43:26 / cg" |
21 | 1644 |
! |
1645 |
||
1646 |
withSelf:anObject parseExpression:aString notifying:someOne ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings |
|
1647 |
"parse aString as an expression with self set to anObject; |
|
1648 |
Return the parseTree (if ok), nil (for an empty string |
|
1649 |
or comment only ) or #Error (syntactic error). |
|
1650 |
||
1651 |
Errors and warnings are forwarded to someOne (usually some |
|
1652 |
codeView) which can highlight it and show a popup box, |
|
1653 |
iff ignoreErrors/ignoreWarnings is true respectively." |
|
0 | 1654 |
|
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1655 |
^ self |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1656 |
withSelf:anObject |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1657 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1658 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1659 |
notifying:someOne |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1660 |
ignoreErrors:ignoreErrors |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1661 |
ignoreWarnings:ignoreWarnings |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1662 |
inNameSpace:nil |
548
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1663 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1664 |
"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
|
1665 |
! |
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1666 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1667 |
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
|
1668 |
"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
|
1669 |
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
|
1670 |
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
|
1671 |
|
79948fed91a7
added entry to parse an expression in a specific nameSpace
Claus Gittinger <cg@exept.de>
parents:
547
diff
changeset
|
1672 |
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
|
1673 |
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
|
1674 |
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
|
1675 |
|
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1676 |
^ self |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1677 |
withSelf:anObject |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1678 |
parseExpression:aString |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1679 |
onError:#Error |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1680 |
notifying:someOne |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1681 |
ignoreErrors:ignoreErrors |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1682 |
ignoreWarnings:ignoreWarnings |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1683 |
inNameSpace:aNameSpaceOrNil |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1684 |
! |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1685 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1686 |
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
|
1687 |
"parse aString as an expression with self set to anObject; |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1688 |
Return the parseTree (if ok), nil (for an empty string |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1689 |
or comment only ) or errorValue (syntactic error). |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1690 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1691 |
Errors and warnings are forwarded to someOne (usually some |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1692 |
codeView) which can highlight it and show a popup box, |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1693 |
iff ignoreErrors/ignoreWarnings is true respectively." |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1694 |
|
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1695 |
|parser tree| |
0 | 1696 |
|
1697 |
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
|
1698 |
|
0 | 1699 |
parser := self for:(ReadStream on:aString). |
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1700 |
tree := parser |
1006 | 1701 |
parseExpressionWithSelf:anObject |
1702 |
notifying:someOne |
|
1703 |
ignoreErrors:ignoreErrors |
|
1704 |
ignoreWarnings:ignoreWarnings |
|
1705 |
inNameSpace:aNameSpaceOrNil. |
|
1096
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1706 |
tree == #Error ifTrue:[ |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1707 |
^ errorValue value |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1708 |
]. |
d1d897aba4d5
added #parseExpression:onError: protocol.
Claus Gittinger <cg@exept.de>
parents:
1091
diff
changeset
|
1709 |
^ tree |
1006 | 1710 |
|
1711 |
"Modified: / 14.12.1999 / 15:12:16 / cg" |
|
0 | 1712 |
! ! |
1713 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
1714 |
!Parser class methodsFor:'unparsing'! |
20 | 1715 |
|
1716 |
methodSpecificationForSelector:aSelector |
|
1717 |
"given a selector such as #foo:bar:, return a string that could |
|
1718 |
serve as a methods specification source code. |
|
1719 |
To be used for code generators" |
|
1720 |
||
807 | 1721 |
|argNames n| |
1722 |
||
1723 |
n := aSelector numArgs. |
|
1724 |
n == 1 ifTrue:[ |
|
1725 |
argNames := #('arg') |
|
1726 |
] ifFalse:[ |
|
1727 |
n <= 15 ifTrue:[ |
|
1728 |
argNames := #('arg1' 'arg2' 'arg3' 'arg4' 'arg5' 'arg6' |
|
1729 |
'arg7' 'arg8' 'arg9' 'arg10' 'arg11' 'arg12' |
|
1730 |
'arg13' 'arg14' 'arg15') |
|
1731 |
] ifFalse:[ |
|
1732 |
argNames := (1 to:aSelector numArgs) collect:[:i | 'arg' , i printString]. |
|
1733 |
]. |
|
1734 |
]. |
|
1735 |
^ self methodSpecificationForSelector:aSelector argNames:argNames |
|
1736 |
||
20 | 1737 |
" |
807 | 1738 |
Parser methodSpecificationForSelector:#foo: |
20 | 1739 |
Parser methodSpecificationForSelector:#foo:bar: |
807 | 1740 |
Parser methodSpecificationForSelector:#foo:bar:baz: |
21 | 1741 |
Parser methodSpecificationForSelector:#+ |
20 | 1742 |
Parser methodSpecificationForSelector:#negated |
1743 |
" |
|
807 | 1744 |
|
1745 |
"Modified: / 12.2.1999 / 13:12:44 / cg" |
|
20 | 1746 |
! |
1747 |
||
1748 |
methodSpecificationForSelector:aSelector argNames:argNames |
|
1749 |
"given a selector such as #foo:bar:, return a string that could |
|
1750 |
serve as a methods specification source code. |
|
1751 |
To be used for code generators" |
|
1752 |
||
806 | 1753 |
|s nargs parts part| |
20 | 1754 |
|
1755 |
s := WriteStream on:String new. |
|
44 | 1756 |
nargs := aSelector numArgs. |
20 | 1757 |
nargs == 0 ifTrue:[ |
806 | 1758 |
s nextPutAll:aSelector |
20 | 1759 |
] ifFalse:[ |
806 | 1760 |
parts := aSelector partsIfSelector. |
1761 |
1 to:nargs do:[:i | |
|
1762 |
part := parts at:i. |
|
1763 |
s nextPutAll:part. |
|
1764 |
(part endsWith:$:) ifFalse:[ |
|
1765 |
s space. |
|
1766 |
]. |
|
1767 |
s nextPutAll:(argNames at:i). |
|
1768 |
i ~~ nargs ifTrue:[s space]. |
|
1769 |
] |
|
20 | 1770 |
]. |
1771 |
^ s contents |
|
1772 |
||
1773 |
" |
|
1774 |
Parser methodSpecificationForSelector:#foo:bar: argNames:#('one' 'two' 'three') |
|
1775 |
Parser methodSpecificationForSelector:#+ argNames:#('one') |
|
1776 |
Parser methodSpecificationForSelector:#negated |
|
1777 |
" |
|
806 | 1778 |
|
1779 |
"Modified: / 12.2.1999 / 12:33:50 / cg" |
|
20 | 1780 |
! ! |
1781 |
||
1417 | 1782 |
!Parser methodsFor:'Compatibility-ST80'! |
0 | 1783 |
|
918 | 1784 |
evaluate:aString in:aClassOrContext to:to notifying:aRequestor ifFail:failBlock |
35 | 1785 |
|parseTree value| |
0 | 1786 |
|
1787 |
aString isNil ifTrue:[^ nil]. |
|
1788 |
self initializeFor:(ReadStream on:aString). |
|
918 | 1789 |
|
1790 |
"/ stupid - there seem to be differences among the various |
|
1791 |
"/ ST dialects ... |
|
1792 |
aClassOrContext isBehavior ifTrue:[ |
|
1793 |
self setClassToCompileFor:aClassOrContext. |
|
1794 |
selfValue := nil. |
|
1795 |
] ifFalse:[ |
|
1796 |
self setContext:aClassOrContext. |
|
1797 |
aClassOrContext notNil ifTrue:[ |
|
1798 |
self setSelf:(aClassOrContext receiver) |
|
1799 |
]. |
|
1800 |
]. |
|
0 | 1801 |
requestor := aRequestor. |
1802 |
||
1803 |
self nextToken. |
|
1804 |
parseTree := self parseMethodBody. |
|
1805 |
(errorFlag or:[tree == #Error]) ifTrue:[^ #Error]. |
|
1806 |
parseTree notNil ifTrue:[ |
|
918 | 1807 |
self evalExitBlock:[:value | ^ failBlock value]. |
1808 |
value := parseTree evaluate |
|
0 | 1809 |
]. |
35 | 1810 |
self release. |
1811 |
^ value |
|
547
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1812 |
! |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1813 |
|
624 | 1814 |
parse:methodSource in:aClass notifying:aRequestor |
1815 |
"parse a methods source. |
|
1816 |
Return the methods parseTree" |
|
1817 |
||
1818 |
self initializeFor:methodSource. |
|
1819 |
classToCompileFor := aClass. |
|
1820 |
requestor := aRequestor. |
|
1821 |
self parseMethod. |
|
918 | 1822 |
|
624 | 1823 |
^ MethodNode new |
1824 |
selector:selector |
|
1825 |
arguments:methodArgs |
|
1826 |
locals:methodVars |
|
1207 | 1827 |
statements:tree asCollectionOfStatements |
624 | 1828 |
|
1214 | 1829 |
"Created: / 17.10.1997 / 12:35:01 / cg" |
1830 |
"Modified: / 5.11.2001 / 16:56:43 / cg" |
|
624 | 1831 |
! |
1832 |
||
547
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1833 |
parseSelector:aStringOrStream |
624 | 1834 |
"parse a methods source for the methods selector. |
1835 |
Return the selector" |
|
1836 |
||
547
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1837 |
self initializeFor:aStringOrStream. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1838 |
self parseMethodSpec. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1839 |
^ selector. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1840 |
|
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1841 |
" |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1842 |
Parser new |
624 | 1843 |
parseSelector:' |
547
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1844 |
parseSelector:aStringOrStream |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1845 |
self initializeFor:aStringOrStream. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1846 |
self parseMethodSpec. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1847 |
^ selector. |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1848 |
' |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1849 |
" |
5a51414daf36
added #parseSelector for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
541
diff
changeset
|
1850 |
|
624 | 1851 |
"Modified: 17.10.1997 / 12:35:46 / cg" |
0 | 1852 |
! ! |
1853 |
||
44 | 1854 |
!Parser methodsFor:'accessing'! |
1855 |
||
1856 |
correctedSource |
|
1857 |
^ correctedSource |
|
1858 |
! |
|
1859 |
||
141 | 1860 |
errorFlag |
1861 |
"return true if there where any errors (valid after parsing)" |
|
1862 |
||
1863 |
^ errorFlag |
|
1864 |
! |
|
1865 |
||
1866 |
evalExitBlock:aBlock |
|
1867 |
"when evaluating a return expression, this block is evaluated" |
|
1868 |
||
1869 |
evalExitBlock := aBlock |
|
1870 |
! |
|
1871 |
||
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1872 |
getNameSpace |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1873 |
"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
|
1874 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1875 |
^ currentNamespace |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1876 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1877 |
"Modified: 8.11.1996 / 13:45:35 / cg" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1878 |
! |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1879 |
|
19 | 1880 |
primitiveNumber |
1881 |
"return the ST-80 style primitiveNumber or nil (valid after parsing)" |
|
1882 |
||
1883 |
^ primitiveNr |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
1884 |
! |
97 | 1885 |
|
285
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1886 |
primitiveResources |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1887 |
"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
|
1888 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1889 |
^ primitiveResource |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1890 |
|
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1891 |
"Created: 29.5.1996 / 17:28:00 / cg" |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1892 |
! |
19e8d6d22278
allow multiple resource definitions
Claus Gittinger <cg@exept.de>
parents:
273
diff
changeset
|
1893 |
|
35 | 1894 |
release |
664 | 1895 |
methodArgs := methodVars := tree := selfNode := superNode := nilNode := nil. |
35 | 1896 |
super release. |
664 | 1897 |
|
1898 |
"Modified: / 31.3.1998 / 19:45:58 / cg" |
|
90 | 1899 |
! |
1900 |
||
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1901 |
setNameSpace:aNameSpaceName |
1041
98fa50f8353f
renamed Namespace to NameSpace
Claus Gittinger <cg@exept.de>
parents:
1040
diff
changeset
|
1902 |
currentNamespace := NameSpace fullName:aNameSpaceName |
427
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1903 |
|
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1904 |
"Modified: 8.11.1996 / 13:43:14 / cg" |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1905 |
! |
3d6a4d002824
pass remembered nameSpace back from upQueries
Claus Gittinger <cg@exept.de>
parents:
424
diff
changeset
|
1906 |
|
1247
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
1907 |
setPackage:aPackageID |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
1908 |
currentPackage := aPackageID |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
1909 |
! |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
1910 |
|
141 | 1911 |
targetClass |
1912 |
^ classToCompileFor |
|
1913 |
! |
|
1914 |
||
90 | 1915 |
targetClass:aClass |
117 | 1916 |
classToCompileFor := aClass |
1917 |
! |
|
1918 |
||
141 | 1919 |
tree |
1920 |
"return the parsetree" |
|
1921 |
||
1922 |
^tree |
|
1923 |
! |
|
1924 |
||
1925 |
tree:aTree |
|
1926 |
"private: set the tree - for internal use only" |
|
1927 |
||
1928 |
tree := aTree |
|
1363 | 1929 |
! |
1930 |
||
1931 |
warnSTXHereExtensionUsed |
|
1932 |
"return the value of the instance variable 'warnSTXHereExtensionUsed' (automatically generated)" |
|
1933 |
||
1934 |
^ warnSTXHereExtensionUsed |
|
141 | 1935 |
! ! |
1936 |
||
1418 | 1937 |
!Parser methodsFor:'dummy-syntax detection'! |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1938 |
|
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1939 |
markArgumentIdentifierFrom:pos1 to:pos2 |
1525 | 1940 |
"intentionally left empty" |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1941 |
! |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
1942 |
|
883 | 1943 |
markBadIdentifierFrom:pos1 to:pos2 |
1525 | 1944 |
"intentionally left empty" |
883 | 1945 |
! |
1946 |
||
663 | 1947 |
markBooleanConstantFrom:pos1 to:pos2 |
1525 | 1948 |
"intentionally left empty" |
663 | 1949 |
! |
1950 |
||
673 | 1951 |
markBracketAt:pos |
1525 | 1952 |
"intentionally left empty" |
673 | 1953 |
! |
1954 |
||
663 | 1955 |
markConstantFrom:pos1 to:pos2 |
1525 | 1956 |
"intentionally left empty" |
663 | 1957 |
! |
1958 |
||
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
815
diff
changeset
|
1959 |
markGlobalClassIdentifierFrom:pos1 to:pos2 |
1525 | 1960 |
"intentionally left empty" |
822
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
815
diff
changeset
|
1961 |
! |
a773bb72cbd6
added extra globalClassIdentifierColor & emphasis
Claus Gittinger <cg@exept.de>
parents:
815
diff
changeset
|
1962 |
|
663 | 1963 |
markGlobalIdentifierFrom:pos1 to:pos2 |
1525 | 1964 |
"intentionally left empty" |
663 | 1965 |
! |
1966 |
||
1967 |
markHereFrom:pos1 to:pos2 |
|
1525 | 1968 |
"intentionally left empty" |
663 | 1969 |
! |
1970 |
||
1971 |
markIdentifierFrom:pos1 to:pos2 |
|
1525 | 1972 |
"intentionally left empty" |
663 | 1973 |
! |
1974 |
||
687 | 1975 |
markInstVarIdentifierFrom:pos1 to:pos2 |
1525 | 1976 |
"intentionally left empty" |
687 | 1977 |
! |
1978 |
||
663 | 1979 |
markLocalIdentifierFrom:pos1 to:pos2 |
1525 | 1980 |
"intentionally left empty" |
663 | 1981 |
! |
1982 |
||
1983 |
markMethodSelectorFrom:pos1 to:pos2 |
|
1525 | 1984 |
"intentionally left empty" |
663 | 1985 |
! |
1986 |
||
837 | 1987 |
markReturnAt:pos |
1525 | 1988 |
"intentionally left empty" |
837 | 1989 |
! |
1990 |
||
864 | 1991 |
markSelector:sel from:pos1 to:pos2 receiverNode:aNode |
1525 | 1992 |
"intentionally left empty" |
864 | 1993 |
! |
1994 |
||
663 | 1995 |
markSelfFrom:pos1 to:pos2 |
1525 | 1996 |
"intentionally left empty" |
663 | 1997 |
! |
1998 |
||
1999 |
markSuperFrom:pos1 to:pos2 |
|
1525 | 2000 |
"intentionally left empty" |
664 | 2001 |
! |
2002 |
||
2003 |
markUnknownIdentifierFrom:pos1 to:pos2 |
|
1525 | 2004 |
"intentionally left empty" |
687 | 2005 |
! |
2006 |
||
2007 |
markVariable:v |
|
1525 | 2008 |
"intentionally left empty" |
687 | 2009 |
! |
2010 |
||
2011 |
markVariable:v from:pos1 to:pos2 |
|
1525 | 2012 |
"intentionally left empty" |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
2013 |
! ! |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
2014 |
|
141 | 2015 |
!Parser methodsFor:'error correction'! |
2016 |
||
1295 | 2017 |
addDoItTemporary:varName |
2018 |
|holder| |
|
2019 |
||
2020 |
doItTemporaries isNil ifTrue:[ |
|
2021 |
doItTemporaries := IdentityDictionary new. |
|
2022 |
]. |
|
2023 |
doItTemporaries at:varName asSymbol put:(holder := ValueHolder new). |
|
2024 |
^ holder |
|
2025 |
! |
|
2026 |
||
141 | 2027 |
askForCorrection:aString fromList:aList |
2028 |
"launch a selection box, which allows user to enter correction. |
|
2029 |
return newString or nil (for abort)" |
|
2030 |
||
1323 | 2031 |
|box rslt| |
141 | 2032 |
|
2033 |
"in systems without widgets ..." |
|
2034 |
ListSelectionBox isNil ifTrue:[ |
|
1285 | 2035 |
^ self confirm:aString |
141 | 2036 |
]. |
2037 |
box := ListSelectionBox title:aString. |
|
2038 |
box initialText:(aList at:1). |
|
2039 |
box list:aList. |
|
1285 | 2040 |
box okText:'Correct'. |
1323 | 2041 |
box action:[:aString | rslt := aString]. |
141 | 2042 |
box showAtPointer. |
1323 | 2043 |
box destroy. |
2044 |
^ rslt |
|
2045 |
! |
|
2046 |
||
2047 |
askForCorrection:aString fromList:aList for:originalSelector |
|
2048 |
"launch a selection box, which allows user to enter correction. |
|
2049 |
return newString or nil (for abort)" |
|
2050 |
||
2051 |
|box rslt| |
|
2052 |
||
2053 |
"in systems without widgets ..." |
|
2054 |
ListSelectionBox isNil ifTrue:[ |
|
2055 |
^ self confirm:aString |
|
2056 |
]. |
|
2057 |
box := ListSelectionBox title:aString. |
|
2058 |
box initialText:(aList at:1). |
|
2059 |
box list:aList. |
|
2060 |
box okText:'Correct'. |
|
2061 |
box action:[:aString | rslt := aString]. |
|
2062 |
box addButton:(Button label:'Keep Selector' action:[rslt := originalSelector. box hide]) after:(box okButton). |
|
2063 |
box showAtPointer. |
|
2064 |
box destroy. |
|
2065 |
^ rslt |
|
141 | 2066 |
! |
2067 |
||
1295 | 2068 |
askForVariableTypeWhenDeclaringUndefined:varName |
2069 |
|l how varNameIsLowercase choice holder newClass| |
|
2070 |
||
2071 |
l := #(). |
|
2072 |
how := #(). |
|
2073 |
||
2074 |
varNameIsLowercase := (varName at:1) isLowercase. |
|
2075 |
||
2076 |
"/ BlockVar, InstVar and classInstVar not yet implemented |
|
2077 |
varNameIsLowercase ifTrue:[ |
|
2078 |
"/ currentBlock notNil ifTrue:[ |
|
2079 |
"/ l := l , #( 'Block local' ). |
|
2080 |
"/ how := how , #( BlockVariable ). |
|
2081 |
"/ ]. |
|
2082 |
selector notNil ifTrue:[ |
|
2083 |
l := l , #( 'Method Local Variable' ). |
|
2084 |
how := how , #( MethodVariable ). |
|
2085 |
]. |
|
2086 |
(classToCompileFor notNil |
|
2087 |
and:[classToCompileFor isMeta not |
|
2088 |
and:[classToCompileFor isBuiltInClass not |
|
1440 | 2089 |
and:[(self isDoIt not)]]]) ifTrue:[ |
1295 | 2090 |
l := l copyWith:'Instance Variable'. |
2091 |
how := how copyWith: #InstanceVariable. |
|
2092 |
]. |
|
2093 |
] ifFalse:[ |
|
2094 |
l := l , #( 'New Class' 'Global' 'NameSpace' ). |
|
2095 |
how := how , #( NewClass GlobalVariable NameSpace ). |
|
2096 |
||
2097 |
(classToCompileFor notNil |
|
2098 |
and:[classToCompileFor isBuiltInClass not |
|
1440 | 2099 |
and:[self isDoIt not]]) ifTrue:[ |
1295 | 2100 |
classToCompileFor isMeta ifTrue:[ |
2101 |
l := l , #('Class Instance Variable'). |
|
2102 |
how := how , #( ClassInstanceVariable). |
|
2103 |
]. |
|
2104 |
l := l , #('Class Variable' ). |
|
2105 |
how := how , #( ClassVariable). |
|
2106 |
] |
|
2107 |
]. |
|
1440 | 2108 |
self isDoIt ifTrue:[ |
1295 | 2109 |
l size > 0 ifTrue:[ |
2110 |
l := l , #( '-' ). |
|
2111 |
how := how , #( nil ). |
|
2112 |
]. |
|
2113 |
l := l , #( 'Workspace Variable' 'DoIt Temporary'). |
|
2114 |
how := how , #( WorkspaceVariable DoItTemporary ). |
|
2115 |
]. |
|
2116 |
||
2117 |
l size > 0 ifTrue:[ |
|
2118 |
l := (Array with:('Declare ' , varName allBold , ' as:') |
|
2119 |
with:'-' |
|
2120 |
) , l. |
|
2121 |
how := #(nil nil) , how. |
|
2122 |
choice := (PopUpMenu labels:l) startUp. |
|
2123 |
(choice notNil and:[choice > 0]) ifTrue:[ |
|
2124 |
choice := how at:choice. |
|
2125 |
||
2126 |
choice == #WorkspaceVariable ifTrue:[ |
|
2127 |
holder := Workspace addWorkspaceVariable:varName. |
|
2128 |
^ VariableNode type:#WorkspaceVariable holder:holder name:varName |
|
2129 |
]. |
|
2130 |
choice == #DoItTemporary ifTrue:[ |
|
2131 |
holder := self addDoItTemporary:varName. |
|
2132 |
^ VariableNode type:#DoItTemporary holder:holder name:varName |
|
2133 |
]. |
|
2134 |
||
2135 |
choice == #GlobalVariable ifTrue:[ |
|
2136 |
Smalltalk at:varName asSymbol put:nil. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2137 |
^ VariableNode globalNamed:varName |
1295 | 2138 |
]. |
2139 |
||
2140 |
choice == #NewClass ifTrue:[ |
|
2141 |
newClass := Object subclass:varName asSymbol |
|
2142 |
instanceVariableNames:'' |
|
2143 |
classVariableNames:'' |
|
2144 |
poolDictionaries:'' |
|
2145 |
category:'* As yet uncategorized *'. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2146 |
^ VariableNode globalNamed:newClass name |
1295 | 2147 |
]. |
2148 |
||
2149 |
choice == #NameSpace ifTrue:[ |
|
2150 |
NameSpace name:varName. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2151 |
^ VariableNode globalNamed:varName |
1295 | 2152 |
]. |
2153 |
||
2154 |
choice == #ClassVariable ifTrue:[ |
|
2155 |
classToCompileFor theNonMetaclass addClassVarName:varName. |
|
2156 |
^ VariableNode type:#ClassVariable class:classToCompileFor theNonMetaclass name:varName |
|
2157 |
]. |
|
2158 |
||
2159 |
choice == #InstanceVariable ifTrue:[ |
|
2160 |
classToCompileFor theNonMetaclass addInstVarName:varName. |
|
2161 |
"/ ST/X special - classToCompileFor is obsoleted |
|
2162 |
classToCompileFor := Smalltalk classNamed:(classToCompileFor name). |
|
2163 |
RestartCompilationSignal raise. |
|
2164 |
"/ not reached - restarted compile will not arrive here again |
|
2165 |
self error:'restart compile failed'. |
|
2166 |
]. |
|
2167 |
||
2168 |
choice == #ClassInstanceVariable ifTrue:[ |
|
2169 |
classToCompileFor theMetaclass addInstVarName:varName. |
|
2170 |
"/ ST/X special - classToCompileFor is obsoleted |
|
2171 |
classToCompileFor := Smalltalk classNamed:(classToCompileFor name). |
|
2172 |
RestartCompilationSignal raise. |
|
2173 |
"/ not reached - restarted compile will not arrive here again |
|
2174 |
self error:'restart compile failed'. |
|
2175 |
]. |
|
2176 |
||
2177 |
choice == #MethodVariable ifTrue:[ |
|
2178 |
|varIndex var endLocalsPos posToInsert ins| |
|
2179 |
||
2180 |
localVarDefPosition size == 2 ifTrue:[ |
|
2181 |
endLocalsPos := posToInsert := localVarDefPosition at:2. |
|
2182 |
ins := ' ' , varName. |
|
2183 |
] ifFalse:[ |
|
2184 |
endOfSelectorPosition notNil ifTrue:[ |
|
2185 |
posToInsert := endOfSelectorPosition. |
|
2186 |
ins := '|' , varName , '|' , Character cr asString , Character cr asString. |
|
2187 |
ins := ins , (String new:(requestor colOfCharacterPosition:posToInsert)-1). |
|
2188 |
] |
|
2189 |
]. |
|
2190 |
posToInsert notNil ifTrue:[ |
|
2191 |
requestor |
|
2192 |
insertString:ins |
|
2193 |
atCharacterPosition:posToInsert. |
|
2194 |
||
2195 |
endLocalsPos notNil ifTrue:[ |
|
2196 |
localVarDefPosition at:2 put:(endLocalsPos + varName size + 1). |
|
2197 |
||
2198 |
methodVarNames := methodVarNames copyWith:varName. |
|
2199 |
methodVars := methodVars copyWith:(var := Variable new name:varName). |
|
2200 |
] ifFalse:[ |
|
2201 |
localVarDefPosition := Array with:posToInsert with:posToInsert+varName size+1. |
|
2202 |
||
2203 |
methodVarNames := Array with:varName. |
|
2204 |
methodVars := Array with:(var := Variable new name:varName). |
|
2205 |
]. |
|
2206 |
correctedSource := requestor currentSourceCode. |
|
2207 |
source := (ReadStream on:correctedSource) |
|
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
2208 |
position:(source position1Based + ins size). |
1295 | 2209 |
|
2210 |
varIndex := methodVarNames size. |
|
2211 |
var used:true. |
|
2212 |
^ VariableNode type:#MethodVariable |
|
2213 |
name:varName |
|
2214 |
token:var |
|
2215 |
index:varIndex |
|
2216 |
]. |
|
2217 |
]. |
|
2218 |
self warning:'Sorry - unimplemented (adding ' , choice , ')'. |
|
2219 |
]. |
|
2220 |
^ #Error |
|
2221 |
]. |
|
2222 |
^ nil. |
|
2223 |
! |
|
2224 |
||
1519 | 2225 |
checkBlockArgumentNameConventionsFor:aVariableName |
2226 |
self checkLocalVariableNameConventionsFor:aVariableName. |
|
2227 |
! |
|
2228 |
||
2229 |
checkBlockVariableNameConventionsFor:aVariableName |
|
2230 |
self checkLocalVariableNameConventionsFor:aVariableName. |
|
2231 |
! |
|
2232 |
||
2233 |
checkForLowercaseVariableName:aVariableName |
|
2234 |
aVariableName first isUppercase ifTrue:[ |
|
2235 |
self |
|
2236 |
syntaxError:('variable "' , aVariableName , '" should be lowercase (by convention)') |
|
2237 |
position:tokenPosition to:source position1Based - 1. |
|
2238 |
]. |
|
2239 |
! |
|
2240 |
||
2241 |
checkForProperUseOfArticleInVariableName:aVariableName |
|
2242 |
|third| |
|
2243 |
||
1521
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2244 |
aVariableName size > 4 ifTrue:[ |
1519 | 2245 |
(aVariableName startsWith:'an') ifTrue:[ |
2246 |
third := aVariableName at:3. |
|
2247 |
third isUppercase ifTrue:[ |
|
2248 |
('AEIOX' includes:third) ifFalse:[ |
|
2249 |
self |
|
1520 | 2250 |
warnCommonMistake:('variable "' , aVariableName , '" should be named "a' , (aVariableName copyFrom:3) , '" (by english language rules)') |
1519 | 2251 |
position:tokenPosition to:source position1Based - 1. |
2252 |
]. |
|
2253 |
]. |
|
1521
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2254 |
]. |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2255 |
(aVariableName startsWith:'a') ifTrue:[ |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2256 |
third := aVariableName at:2. |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2257 |
third isUppercase ifTrue:[ |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2258 |
('AEIOX' includes:third) ifTrue:[ |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2259 |
self |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2260 |
warnCommonMistake:('variable "' , aVariableName , '" should be named "an' , (aVariableName copyFrom:2) , '" (by english language rules)') |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2261 |
position:tokenPosition to:source position1Based - 1. |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2262 |
]. |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2263 |
]. |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2264 |
]. |
1519 | 2265 |
]. |
2266 |
! |
|
2267 |
||
1512
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
2268 |
checkIfAllSubclassesOf:aClass implement:aSelector |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
2269 |
(aClass subclasses |
1517 | 2270 |
contains:[:cls | (cls implements:aSelector) not]) ifTrue:[^ false]. |
1512
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
2271 |
^ true. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
2272 |
! |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
2273 |
|
1522
777862196320
checkVariable-conventions: can be (are by default) disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1521
diff
changeset
|
2274 |
checkLocalVariableNameConventionsFor:aVariableName |
777862196320
checkVariable-conventions: can be (are by default) disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1521
diff
changeset
|
2275 |
WarnAboutVariableNameConventions == true ifTrue:[ |
777862196320
checkVariable-conventions: can be (are by default) disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1521
diff
changeset
|
2276 |
self checkForLowercaseVariableName:aVariableName. |
777862196320
checkVariable-conventions: can be (are by default) disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1521
diff
changeset
|
2277 |
]. |
1521
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2278 |
WarnAboutWrongVariableNames == true ifTrue:[ |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2279 |
self checkForProperUseOfArticleInVariableName:aVariableName. |
3488542e7a83
checkVariable-conventions: can be disabled via classVar.
Claus Gittinger <cg@exept.de>
parents:
1520
diff
changeset
|
2280 |
]. |
1519 | 2281 |
! |
2282 |
||
2283 |
checkMethodArgumentNameConventionsFor:aVariableName |
|
2284 |
self checkLocalVariableNameConventionsFor:aVariableName. |
|
2285 |
! |
|
2286 |
||
2287 |
checkMethodVariableNameConventionsFor:aVariableName |
|
2288 |
self checkLocalVariableNameConventionsFor:aVariableName. |
|
2289 |
! |
|
2290 |
||
1507 | 2291 |
checkSelector:selector for:receiver inClass:cls |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2292 |
"check wether a method with selector exists in class cls and |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2293 |
that the method is not obsolete. |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2294 |
If cls is nil, check all classes for the selector. |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2295 |
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
|
2296 |
|
1507 | 2297 |
|err mthd implementor implementors allowed| |
1190
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2298 |
|
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2299 |
cls isNil ifTrue:[ |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2300 |
SystemBrowser isNil ifTrue:[ |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2301 |
^ nil |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2302 |
]. |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2303 |
"beware, this is sort of slow, especially for the SyntaxHighlighter" |
1190
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2304 |
implementors := SystemBrowser |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2305 |
findImplementorsOf:selector |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2306 |
in:(Smalltalk allClasses) |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2307 |
ignoreCase:false. |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2308 |
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
|
2309 |
^ 'is nowhere implemented' |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2310 |
]. |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2311 |
|
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2312 |
(implementors conform:[:eachMethod| eachMethod isObsolete]) ifTrue:[ |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2313 |
^ 'each implementation of this selector in the system is deprecated' |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2314 |
]. |
1190
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2315 |
^ nil |
8600334a549e
oops - avoid cought error if method is parsed in no class.
Claus Gittinger <cg@exept.de>
parents:
1189
diff
changeset
|
2316 |
]. |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2317 |
|
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2318 |
mthd := cls lookupMethodFor:selector. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2319 |
mthd isNil ifTrue:[ |
1327 | 2320 |
cls == Boolean ifTrue:[ |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2321 |
mthd := True compiledMethodAt:selector. |
1327 | 2322 |
mthd isNil ifTrue:[ |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2323 |
mthd := False compiledMethodAt:selector. |
1327 | 2324 |
]. |
2325 |
] |
|
2326 |
]. |
|
2327 |
mthd isNil ifTrue:[ |
|
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2328 |
"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
|
2329 |
implementor := cls whichClassIncludesSelector:#doesNotUnderstand:. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2330 |
(implementor isNil or:[implementor == Object]) ifTrue:[ |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2331 |
err := 'is not implemented' |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2332 |
]. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2333 |
] ifFalse:[ |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2334 |
(mthd sends:#shouldNotImplement) ifTrue:[ |
1542 | 2335 |
allowed := (cls == classToCompileFor). "methods in abstract classes may send messages to abstract methods in the same class" |
2336 |
allowed ifFalse:[ |
|
2337 |
err := 'is not (should not be) implemented' |
|
2338 |
] |
|
1517 | 2339 |
] ifFalse:[ |
2340 |
(mthd sends:#subclassResponsibility) ifTrue:[ |
|
2341 |
allowed := (cls == classToCompileFor). "methods in abstract classes may send messages to abstract methods in the same class" |
|
2342 |
allowed ifFalse:[ |
|
2343 |
"methods in abstract classes may send messages to abstract methods in meta class" |
|
2344 |
(cls == classToCompileFor class) ifTrue:[ |
|
2345 |
allowed := receiver isMessage and:[receiver selector = 'class'] |
|
2346 |
]. |
|
1507 | 2347 |
]. |
1517 | 2348 |
allowed ifTrue:[ |
1519 | 2349 |
"/ not from cg to stefan: thats wrong - if not implemented in all subclasses, |
2350 |
"/ its a bug of the subclass not a bug here - that message send here |
|
2351 |
"/ is perfectly correct. (it is very annoying for a framework developped to get |
|
2352 |
"/ error messages for bugs which are not his... |
|
2353 |
"/ (self checkIfAllSubclassesOf:cls implement:selector) ifFalse:[ |
|
2354 |
"/ "if not all subclasses implement the selector - this is a possible bug" |
|
2355 |
"/ allowed := false |
|
2356 |
"/ ]. |
|
1507 | 2357 |
]. |
1517 | 2358 |
allowed ifFalse:[ |
2359 |
err := 'is subclassResponsibility' |
|
2360 |
]. |
|
2361 |
] ifFalse:[mthd isObsolete ifTrue:[ |
|
2362 |
err := 'is deprecated'. |
|
2363 |
]] |
|
2364 |
]. |
|
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2365 |
]. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2366 |
^ err. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2367 |
! |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2368 |
|
141 | 2369 |
correctByDeleting |
2370 |
"correct (by deleting token) if user wants to; |
|
2371 |
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
|
2372 |
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
|
2373 |
|
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2374 |
|selectionSize| |
141 | 2375 |
|
2376 |
(self confirm:'confirm deleting') ifFalse:[^ #Error]. |
|
2377 |
||
2378 |
" |
|
2379 |
tell requestor (i.e. CodeView) about the change |
|
2380 |
this will update what the requestor shows. |
|
2381 |
" |
|
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2382 |
selectionSize := requestor selection size. |
141 | 2383 |
requestor deleteSelection. |
2384 |
||
2385 |
" |
|
2386 |
get the updated source-string |
|
2387 |
which is needed, when we eventually install the new method |
|
2388 |
" |
|
2389 |
correctedSource := requestor currentSourceCode. |
|
1167 | 2390 |
"/ 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
|
2391 |
source := (ReadStream on:correctedSource) |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
2392 |
position:(source position1Based - selectionSize). |
1369
2304dd8c3173
recompilation after correct-by-deleting unused local
Claus Gittinger <cg@exept.de>
parents:
1368
diff
changeset
|
2393 |
|
141 | 2394 |
^ nil |
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2395 |
|
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2396 |
"Modified: / 22.1.1998 / 16:39:11 / stefan" |
141 | 2397 |
! |
2398 |
||
1439 | 2399 |
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
|
2400 |
"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
|
2401 |
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
|
2402 |
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
|
2403 |
|
1439 | 2404 |
|correctIt suggestedNames newSelector className classToGenerateCode pos1 pos2| |
2405 |
||
2406 |
pos1 := posVector first start. |
|
2407 |
pos2 := posVector last stop. |
|
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2408 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2409 |
alreadyWarnedUnimplementedSelectors isNil ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2410 |
alreadyWarnedUnimplementedSelectors := Set new |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2411 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2412 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2413 |
(alreadyWarnedUnimplementedSelectors includes:aSelectorString) ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2414 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2415 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2416 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2417 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2418 |
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
|
2419 |
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
|
2420 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2421 |
(aSelectorString occurrencesOf:$:) > 1 ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2422 |
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
|
2423 |
alreadyWarnedUnimplementedSelectors add:aSelectorString. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2424 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2425 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2426 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2427 |
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
|
2428 |
correctIt == #generate ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2429 |
receiverNode isSelf ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2430 |
classToGenerateCode := classToCompileFor |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2431 |
] ifFalse:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2432 |
receiverNode isVariable ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2433 |
receiverNode isGlobal ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2434 |
classToGenerateCode := receiverNode evaluate. |
1336
67ea8b161346
Generate class methods in class.
Stefan Vogel <sv@exept.de>
parents:
1335
diff
changeset
|
2435 |
classToGenerateCode isBehavior ifTrue:[ |
67ea8b161346
Generate class methods in class.
Stefan Vogel <sv@exept.de>
parents:
1335
diff
changeset
|
2436 |
classToGenerateCode := classToGenerateCode theMetaclass. |
67ea8b161346
Generate class methods in class.
Stefan Vogel <sv@exept.de>
parents:
1335
diff
changeset
|
2437 |
] ifFalse:[ |
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2438 |
classToGenerateCode := nil |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2439 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2440 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2441 |
] |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2442 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2443 |
classToGenerateCode isNil ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2444 |
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
|
2445 |
className size == 0 ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2446 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2447 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2448 |
classToGenerateCode := Smalltalk at:className asSymbol. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2449 |
classToGenerateCode isNil ifTrue:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2450 |
self warn:'No such class.'. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2451 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2452 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2453 |
]. |
1252
666db3206028
#implements: -> #includesSelector:
Claus Gittinger <cg@exept.de>
parents:
1247
diff
changeset
|
2454 |
(classToGenerateCode includesSelector:aSelectorString asSymbol) ifFalse:[ |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2455 |
"do not overwrite an already existant (deprecated) method" |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2456 |
classToGenerateCode |
1336
67ea8b161346
Generate class methods in class.
Stefan Vogel <sv@exept.de>
parents:
1335
diff
changeset
|
2457 |
compile:((self class methodSpecificationForSelector:aSelectorString) , '\ self shouldImplement' withCRs) |
1323 | 2458 |
classified:(Compiler defaultMethodCategory). |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
2459 |
]. |
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2460 |
correctIt := false. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2461 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2462 |
correctIt ifFalse:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2463 |
alreadyWarnedUnimplementedSelectors add:aSelectorString. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2464 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2465 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2466 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2467 |
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
|
2468 |
suggestedNames notNil ifTrue:[ |
1323 | 2469 |
newSelector := self askForCorrection:'Correct Selector to: ' fromList:suggestedNames for:aSelectorString. |
2470 |
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
|
2471 |
] ifFalse:[ |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2472 |
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
|
2473 |
^ aSelectorString |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2474 |
]. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2475 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2476 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2477 |
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
|
2478 |
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
|
2479 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2480 |
requestor replaceSelectionBy:newSelector keepCursor:false. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2481 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2482 |
get the updated source-string |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2483 |
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
|
2484 |
" |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2485 |
correctedSource := requestor currentSourceCode. |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2486 |
source := (ReadStream on:correctedSource) |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
2487 |
position:(source position1Based + 1 + (newSelector size - aSelectorString size)). |
1361 | 2488 |
"/ Parser murks. |
1156
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2489 |
^ newSelector |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2490 |
|
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2491 |
"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
|
2492 |
"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
|
2493 |
"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
|
2494 |
! |
b491528ad92b
fixed 'generate' option (in selector will not be understood)
Claus Gittinger <cg@exept.de>
parents:
1155
diff
changeset
|
2495 |
|
1167 | 2496 |
correctSourceByDeletingFrom:start to:stop |
2497 |
"correct (by deleting token) if user wants to; |
|
2498 |
return #Error if there was no correction; |
|
2499 |
nil if there was one." |
|
2500 |
||
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2501 |
|deleteSize localDefsStart localDefsStop newPos| |
1167 | 2502 |
|
2503 |
" |
|
2504 |
tell requestor (i.e. CodeView) about the change |
|
2505 |
this will update what the requestor shows. |
|
2506 |
" |
|
2507 |
deleteSize := stop - start + 1. |
|
2508 |
requestor deleteFromCharacterPosition:start to:stop. |
|
2509 |
||
2510 |
" |
|
2511 |
get the updated source-string |
|
2512 |
which is needed, when we eventually install the new method |
|
2513 |
" |
|
2514 |
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
|
2515 |
|
1167 | 2516 |
"/ 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
|
2517 |
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
|
2518 |
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
|
2519 |
] ifFalse:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2520 |
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
|
2521 |
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
|
2522 |
] ifFalse:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2523 |
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
|
2524 |
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
|
2525 |
] ifFalse:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2526 |
newPos := start |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2527 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2528 |
] |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2529 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2530 |
source := (ReadStream on:correctedSource) position1Based:newPos. |
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2531 |
|
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2532 |
localDefsStart := localVarDefPosition at:1. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2533 |
localDefsStop := localVarDefPosition at:2. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2534 |
|
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2535 |
localDefsStop <= start ifTrue:[^ self]. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2536 |
localDefsStart >= stop ifTrue:[^ self]. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2537 |
|
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2538 |
(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
|
2539 |
localVarDefPosition := nil. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2540 |
^ self |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2541 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2542 |
|
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2543 |
"/ must update |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2544 |
(start > localDefsStart and:[stop < localDefsStop]) ifTrue:[ |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2545 |
localVarDefPosition at:2 put:(localDefsStop - (stop-start+1)). |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2546 |
^ self. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2547 |
]. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2548 |
self halt. |
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
2549 |
^ self |
1167 | 2550 |
! |
2551 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2552 |
correctVariable:varName atPosition:pos1 to:pos2 |
141 | 2553 |
"notify error and correct if user wants to; |
2554 |
return #Error if there was no correction |
|
2555 |
or a ParseNode as returned by variable" |
|
2556 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2557 |
|correctIt suggestedNames newName rslt |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
2558 |
varNameIsLowercase undeclared boldName| |
141 | 2559 |
|
877 | 2560 |
varNameIsLowercase := (varName at:1) isLowercase. |
2561 |
||
141 | 2562 |
correctIt := self undefError:varName position:pos1 to:pos2. |
887 | 2563 |
(correctIt == false or:[correctIt == #continue]) ifTrue:[ |
877 | 2564 |
"/ no correction wanted. |
2565 |
||
2566 |
"/ lowerCase vars are added to the Undeclared dictionary, |
|
2567 |
"/ allowing easy search for bad-spots later. |
|
1285 | 2568 |
boldName := varName allBold. |
877 | 2569 |
|
2570 |
varNameIsLowercase ifTrue:[ |
|
1205 | 2571 |
undeclared := Smalltalk at:#Undeclared. |
2572 |
((undeclared notNil) |
|
2573 |
and:[(undeclared includes:varName asSymbol)]) ifFalse:[ |
|
1285 | 2574 |
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
|
2575 |
]. |
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2576 |
^ self defineAsUndeclaredVariable:varName |
877 | 2577 |
]. |
2578 |
||
2579 |
"/ upperCase vars are declared as global |
|
915
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
2580 |
(warnedUndefVars isNil or:[(warnedUndefVars includes:varName) not]) ifTrue:[ |
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
2581 |
(warnedUnknownNamespaces isNil or:[(warnedUnknownNamespaces includes:varName) not]) ifTrue:[ |
1285 | 2582 |
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
|
2583 |
]. |
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
2584 |
]. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2585 |
^ VariableNode globalNamed:varName |
877 | 2586 |
]. |
2587 |
||
1491 | 2588 |
correctIt == #Error ifTrue:[ |
2589 |
^ #Error |
|
2590 |
]. |
|
2591 |
||
877 | 2592 |
correctIt == #declare ifTrue:[ |
2593 |
"/ declare it |
|
1295 | 2594 |
rslt := self askForVariableTypeWhenDeclaringUndefined:varName. |
2595 |
rslt notNil ifTrue:[ |
|
2596 |
^ rslt |
|
2597 |
]. |
|
141 | 2598 |
]. |
1398
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
2599 |
(correctIt isKindOf:ParseNode) ifTrue:[ |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
2600 |
^ correctIt |
eaef898b063e
added undefinedVariableNotification
Claus Gittinger <cg@exept.de>
parents:
1394
diff
changeset
|
2601 |
]. |
141 | 2602 |
|
2603 |
suggestedNames := self findBestVariablesFor:varName. |
|
877 | 2604 |
suggestedNames isNil ifTrue:[ |
1285 | 2605 |
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
|
2606 |
^ #Error |
141 | 2607 |
]. |
2608 |
||
1285 | 2609 |
newName := self askForCorrection:'Correct Variable to: ' fromList:suggestedNames. |
877 | 2610 |
newName isNil ifTrue:[^ #Error]. |
2611 |
" |
|
2612 |
newName := suggestedNames at:1. |
|
2613 |
(self confirm:('confirm correction to: ' , newName)) ifFalse:[^ #Error]. |
|
2614 |
" |
|
2615 |
||
141 | 2616 |
" |
2617 |
tell requestor (i.e. CodeView) about the change |
|
2618 |
this will update what the requestor shows. |
|
2619 |
" |
|
2620 |
requestor replaceSelectionBy:newName. |
|
2621 |
" |
|
2622 |
get the updated source-string |
|
2623 |
which is needed, when we eventually install the new method |
|
2624 |
" |
|
2625 |
correctedSource := requestor currentSourceCode. |
|
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2626 |
source := (ReadStream on:correctedSource) |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
2627 |
position:(source position1Based + newName size - tokenName size). |
141 | 2628 |
|
2629 |
"redo parse with new value" |
|
1103
b75a71996388
ensure that token follows tomeName & tokenValue
Claus Gittinger <cg@exept.de>
parents:
1100
diff
changeset
|
2630 |
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
|
2631 |
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
|
2632 |
|
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
|
2633 |
"/ 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
|
2634 |
rslt == #Error ifTrue:[ |
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2635 |
"/ 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
|
2636 |
|
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2637 |
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
|
2638 |
]. |
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
|
2639 |
^ 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
|
2640 |
|
644
834399365be9
Highlighting of undefined variables didn't work after first correction
Stefan Vogel <sv@exept.de>
parents:
640
diff
changeset
|
2641 |
"Modified: / 22.1.1998 / 16:34:01 / stefan" |
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
2642 |
"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
|
2643 |
! |
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
|
2644 |
|
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
|
2645 |
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
|
2646 |
"define varName as undeclared variable |
629 | 2647 |
(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
|
2648 |
You can browse for methods with undeclareds by searching for global accesses |
629 | 2649 |
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
|
2650 |
|
1206 | 2651 |
|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
|
2652 |
|
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
|
2653 |
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
|
2654 |
|
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
|
2655 |
"/ 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
|
2656 |
|
1206 | 2657 |
undeclared := Smalltalk at:#Undeclared. |
2658 |
undeclared isNil ifTrue:[ |
|
2659 |
Smalltalk at:#Undeclared put:(undeclared := IdentitySet new). |
|
2660 |
]. |
|
2661 |
undeclared add:tokenName asSymbol. |
|
1304
ade15708e7c1
undeclared variable handling was broken (to allow reference search)
penk
parents:
1301
diff
changeset
|
2662 |
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
|
2663 |
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
|
2664 |
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
|
2665 |
|
762
66cd2b4f6689
Big BUG: remember original name in usedVars - not Undeclared::xxx
tm
parents:
755
diff
changeset
|
2666 |
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
|
2667 |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
2668 |
^ 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
|
2669 |
|
629 | 2670 |
"Modified: / 31.10.1997 / 01:16:03 / cg" |
141 | 2671 |
! |
2672 |
||
1167 | 2673 |
deleteDefinitionOf:varName in:defStartPos to:defEndPos |
1393 | 2674 |
"this removes the definition of varName from the declaration part i.e. |
2675 |
if the source was '... | foo bar baz |...' |
|
2676 |
deleting the var 'bar' changes the source to '... | foo baz |...'. |
|
2677 |
The code below tries to be somewhat smart w.r.t. spaces by |
|
2678 |
trying to remove the whiteSpace around the removed variable also. |
|
2679 |
However, this seems to not always work correctly" |
|
2680 |
||
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2681 |
|source startSearch pos pos2 nextChar varSlot p p2| |
1172 | 2682 |
|
2683 |
varSlot := methodVars detect:[:var | var name = varName]. |
|
2684 |
methodVars removeIdentical:varSlot. |
|
1167 | 2685 |
|
2686 |
source := requestor currentSourceCode. |
|
2687 |
startSearch := defStartPos+1. |
|
2688 |
||
2689 |
[ |
|
1393 | 2690 |
|prevChar isFirstVar didPassEndOfLine| |
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2691 |
|
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2692 |
"/ search this name's position in the declaration part ... |
1167 | 2693 |
pos := source indexOfSubCollection:varName startingAt:startSearch ifAbsent:0. |
1326 | 2694 |
(pos == 0 or:[pos >= defEndPos]) ifTrue:[ |
2695 |
self error:'should not happen' mayProceed:true. |
|
1167 | 2696 |
^ self. |
2697 |
]. |
|
2698 |
||
2699 |
pos2 := pos + varName size - 1. |
|
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2700 |
pos > 1 ifTrue:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2701 |
prevChar := source at:pos-1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2702 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2703 |
(prevChar isNil or:[prevChar isLetterOrDigit not]) ifTrue:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2704 |
nextChar := source at:pos2+1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2705 |
nextChar isLetterOrDigit ifFalse:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2706 |
"/ halfway intuitive space-removal behavior; |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2707 |
"/ if there was a space after/before the |-char, |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2708 |
"/ leave it; otherwise remove it. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2709 |
isFirstVar := pos == (defStartPos+1). |
1393 | 2710 |
(source at:pos-1) isSeparator ifTrue:[ |
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2711 |
pos := pos - 1. |
1393 | 2712 |
[ (source at:pos-1) isSeparator] whileTrue:[ |
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2713 |
pos := pos - 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2714 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2715 |
(source at:pos-1) == $| ifTrue:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2716 |
"/ there was a space before - leave it |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2717 |
pos := pos + 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2718 |
isFirstVar := true. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2719 |
] |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2720 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2721 |
|
1393 | 2722 |
(source at:pos2+1) isSeparator ifTrue:[ |
2723 |
didPassEndOfLine := (source at:pos2+1) == Character cr. |
|
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2724 |
pos2 := pos2 + 1. |
1393 | 2725 |
[ (source at:pos2+1) isSeparator] whileTrue:[ |
2726 |
(source at:pos2+1) == Character cr ifTrue:[ didPassEndOfLine := true ]. |
|
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2727 |
pos2 := pos2 + 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2728 |
]. |
1393 | 2729 |
|
2730 |
didPassEndOfLine ifFalse:[ |
|
2731 |
(source at:pos2+1) == $" ifTrue:[ |
|
2732 |
"/ comment follows - assume it belongs to the removed variable |
|
2733 |
pos2 := pos2 + 1. |
|
2734 |
(source at:pos2+1) == $/ ifTrue:[ |
|
2735 |
"/ EOL comment |
|
2736 |
[ (source at:pos2+1) == Character cr ] whileFalse:[ |
|
2737 |
pos2 := pos2 + 1. |
|
2738 |
]. |
|
2739 |
pos2 := pos2 + 1. |
|
2740 |
] ifFalse:[ |
|
2741 |
"/ regular comment |
|
2742 |
[ (source at:pos2+1) == $" ] whileFalse:[ |
|
2743 |
pos2 := pos2 + 1. |
|
2744 |
]. |
|
2745 |
pos2 := pos2 + 1. |
|
2746 |
]. |
|
2747 |
[ (source at:pos2+1) isSeparator] whileTrue:[ |
|
2748 |
(source at:pos2+1) == Character cr ifTrue:[ didPassEndOfLine := true ]. |
|
2749 |
pos2 := pos2 + 1. |
|
2750 |
]. |
|
2751 |
] |
|
2752 |
]. |
|
2753 |
||
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2754 |
(source at:pos2+1) == $| ifTrue:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2755 |
"/ there was a space after - leave it |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2756 |
pos2 := pos2 - 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2757 |
] ifFalse:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2758 |
isFirstVar ifFalse:[ |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2759 |
pos2 := pos2 - 1. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2760 |
] |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2761 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2762 |
]. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2763 |
|
1445
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2764 |
"/ 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
|
2765 |
((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
|
2766 |
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
|
2767 |
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
|
2768 |
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
|
2769 |
"/ 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
|
2770 |
p := pos. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2771 |
p2 := pos2. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2772 |
|
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2773 |
[(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
|
2774 |
[(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
|
2775 |
((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
|
2776 |
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
|
2777 |
pos2 := p2. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2778 |
(((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
|
2779 |
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
|
2780 |
ifFalse:[ |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2781 |
(((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
|
2782 |
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
|
2783 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2784 |
]. |
2bd299cdc753
delete unused variable-decl: when decl is empty, remove it as well
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
2785 |
|
1392
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2786 |
self correctSourceByDeletingFrom:pos to:pos2. |
2c06fa7b9bbe
remove unused variable fixed
Claus Gittinger <cg@exept.de>
parents:
1391
diff
changeset
|
2787 |
^ self. |
1167 | 2788 |
]. |
2789 |
]. |
|
2790 |
startSearch := pos2 + 1. |
|
2791 |
] loop |
|
2792 |
! |
|
2793 |
||
141 | 2794 |
findBestSelectorsFor:aString |
2795 |
"collect known selectors with their spelling distances to aString; |
|
2796 |
return the 10 best suggestions" |
|
2797 |
||
1187 | 2798 |
^ self class findBestSelectorsFor:aString |
141 | 2799 |
|
2800 |
"Time millisecondsToRun:[Parser new findBestSelectorsFor:'foo']" |
|
2801 |
"Parser new findBestSelectorsFor:'findBestSel'" |
|
2802 |
"Parser new findBestSelectorsFor:'fildBestSelectrFr'" |
|
2803 |
! |
|
2804 |
||
1022 | 2805 |
findBestSelectorsFor:aString in:aClassOrNil |
2806 |
"collect known selectors with their spelling distances to aString; |
|
2807 |
return the 10 best suggestions. If the argument, aClassOrNil is not nil, |
|
2808 |
the message is assumed to be sent to instances of that class (i.e. offer |
|
2809 |
corrections from that hierarchy only)" |
|
2810 |
||
1187 | 2811 |
^ self class findBestSelectorsFor:aString in:aClassOrNil |
1022 | 2812 |
! |
2813 |
||
141 | 2814 |
findBestVariablesFor:aString |
2815 |
"collect known variables with their spelling distances to aString; |
|
2816 |
return the 10 best suggestions" |
|
2817 |
||
1200 | 2818 |
|names dists searchBlock args vars "aClass className baseClass" |
2819 |
n instVarNames classVarNames spellAgainstAction| |
|
141 | 2820 |
|
2821 |
names := OrderedCollection new. |
|
2822 |
dists := OrderedCollection new. |
|
2823 |
||
1200 | 2824 |
spellAgainstAction := |
2825 |
[:aVarNode | |
|
2826 |
|varName dist| |
|
2827 |
||
2828 |
varName := aVarNode name. |
|
2829 |
names add:varName. |
|
2830 |
||
2831 |
dist := aString spellAgainst:varName. |
|
2832 |
(aString startsWith:varName) ifTrue:[ |
|
2833 |
dist := dist + (aString size * 10). |
|
2834 |
]. |
|
2835 |
dists add:dist |
|
2836 |
]. |
|
2837 |
||
141 | 2838 |
"block arguments" |
2839 |
searchBlock := currentBlock. |
|
2840 |
[searchBlock notNil] whileTrue:[ |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2841 |
args := searchBlock arguments. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2842 |
args notNil ifTrue:[ |
1200 | 2843 |
args do:spellAgainstAction |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2844 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2845 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2846 |
vars := searchBlock variables. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2847 |
vars notNil ifTrue:[ |
1200 | 2848 |
vars do:spellAgainstAction |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2849 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2850 |
searchBlock := searchBlock home |
141 | 2851 |
]. |
2852 |
||
1200 | 2853 |
spellAgainstAction := |
2854 |
[:givenName | |
|
2855 |
|dist| |
|
2856 |
||
2857 |
names add:givenName. |
|
2858 |
dist := aString spellAgainst:givenName. |
|
2859 |
(aString startsWith:givenName) ifTrue:[ |
|
2860 |
dist := dist + (aString size * 10). |
|
2861 |
]. |
|
2862 |
dists add:dist |
|
2863 |
]. |
|
2864 |
||
141 | 2865 |
"method-variables" |
2866 |
methodVars notNil ifTrue:[ |
|
1200 | 2867 |
methodVarNames do:spellAgainstAction |
141 | 2868 |
]. |
2869 |
||
2870 |
"method-arguments" |
|
2871 |
methodArgs notNil ifTrue:[ |
|
1200 | 2872 |
methodArgNames do:spellAgainstAction |
141 | 2873 |
]. |
2874 |
||
2875 |
"instance-variables" |
|
2876 |
classToCompileFor notNil ifTrue:[ |
|
1200 | 2877 |
self classesInstVarNames do:spellAgainstAction |
141 | 2878 |
]. |
2879 |
||
2880 |
"class-variables" |
|
2881 |
classToCompileFor notNil ifTrue:[ |
|
1200 | 2882 |
self classesClassVarNames do:spellAgainstAction. |
141 | 2883 |
|
2884 |
"/ aClass := classToCompileFor. |
|
2885 |
"/ aClass isMeta ifTrue:[ |
|
2886 |
"/ className := aClass name. |
|
2887 |
"/ className := className copyWithoutLast:5. |
|
2888 |
"/ baseClass := Smalltalk at:(className asSymbol). |
|
2889 |
"/ baseClass notNil ifTrue:[ |
|
2890 |
"/ aClass := baseClass |
|
2891 |
"/ ] |
|
2892 |
"/ ]. |
|
2893 |
"/ [aClass notNil] whileTrue:[ |
|
2894 |
"/ (aClass classVarNames) do:[:classVarName | |
|
2895 |
"/ names add:classVarName. |
|
2896 |
"/ dists add:(aString spellAgainst: "levenshteinTo:"classVarName) |
|
2897 |
"/ ]. |
|
2898 |
"/ aClass := aClass superclass |
|
2899 |
"/ ] |
|
2900 |
||
2901 |
]. |
|
2902 |
||
2903 |
"globals" |
|
2904 |
Smalltalk keysDo:[:aKey | |
|
1200 | 2905 |
|globalVarName| |
2906 |
||
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2907 |
globalVarName := aKey asString. |
1200 | 2908 |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2909 |
"only compare strings where length is about right" |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2910 |
((globalVarName size - aString size) abs < 3) ifTrue:[ |
1200 | 2911 |
spellAgainstAction value:globalVarName. |
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2912 |
] |
141 | 2913 |
]. |
2914 |
||
2915 |
"misc" |
|
1200 | 2916 |
#('self' 'super' 'nil' 'thisContext') do:spellAgainstAction. |
141 | 2917 |
|
2918 |
(dists size ~~ 0) ifTrue:[ |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2919 |
dists sortWith:names. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2920 |
dists := dists reverse. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2921 |
names := names reverse. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2922 |
n := names size min:10. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2923 |
names := names copyTo:n. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2924 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2925 |
"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
|
2926 |
(aString at:1) isLowercase ifTrue:[ |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2927 |
methodVarNames size > 0 ifTrue:[ |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2928 |
names add:'---- method locals ----'. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2929 |
methodVarNames asSortedCollection do:[:methodVarName | |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2930 |
names add:methodVarName. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2931 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2932 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2933 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2934 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2935 |
methodArgs size > 0 ifTrue:[ |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2936 |
names add:'---- method arguments ----'. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2937 |
methodArgNames asSortedCollection do:[:methodArgName | |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2938 |
names add:methodArgName. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2939 |
] |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2940 |
]. |
1078 | 2941 |
classToCompileFor notNil ifTrue:[ |
2942 |
instVarNames := OrderedCollection new. |
|
2943 |
self classesInstVarNames asSortedCollection do:[:instVarName | |
|
2944 |
(instVarNames includes:instVarName) ifFalse:[ |
|
2945 |
instVarNames add:instVarName. |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2946 |
] |
1078 | 2947 |
]. |
2948 |
||
2949 |
instVarNames size > 0 ifTrue:[ |
|
2950 |
(classToCompileFor notNil and:[classToCompileFor isMeta]) ifTrue:[ |
|
2951 |
names add:'---- class instance variables ----'. |
|
2952 |
] ifFalse:[ |
|
2953 |
names add:'---- instance variables ----'. |
|
2954 |
]. |
|
2955 |
instVarNames do:[:instVarName | |
|
2956 |
(names includes:instVarName) ifFalse:[ |
|
2957 |
names add:instVarName. |
|
2958 |
] |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2959 |
] |
1078 | 2960 |
]. |
2961 |
||
2962 |
classVarNames := OrderedCollection new. |
|
2963 |
self classesClassVarNames asSortedCollection do:[:classVarName | |
|
2964 |
(classVarNames includes:classVarName) ifFalse:[ |
|
2965 |
classVarNames add:classVarName. |
|
2966 |
] |
|
2967 |
]. |
|
2968 |
||
2969 |
classVarNames size > 0 ifTrue:[ |
|
2970 |
names add:'---- class variables ----'. |
|
2971 |
classVarNames do:[:classVarName | |
|
2972 |
(names includes:classVarName) ifFalse:[ |
|
2973 |
names add:classVarName. |
|
2974 |
] |
|
2975 |
] |
|
2976 |
]. |
|
989
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2977 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2978 |
]. |
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2979 |
|
6e535d9d87d8
better undef-variable message;
Claus Gittinger <cg@exept.de>
parents:
988
diff
changeset
|
2980 |
^ names |
141 | 2981 |
]. |
2982 |
^ nil |
|
450 | 2983 |
|
480
e4ac7e62ca9a
better block-var name detection in debugger
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
2984 |
"Modified: 11.1.1997 / 21:28:28 / cg" |
141 | 2985 |
! |
2986 |
||
2987 |
selectorCheck:aSelectorString for:receiver position:pos1 to:pos2 |
|
1439 | 2988 |
^ self selectorCheck:aSelectorString for:receiver positions:(Array with:(pos1 to:pos2)). |
2989 |
! |
|
2990 |
||
2991 |
selectorCheck:aSelectorString for:receiver positions:posVector |
|
141 | 2992 |
"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
|
2993 |
has the same name as a variable, cannot be understood or is obsolete. |
141 | 2994 |
Simple, but catches many typos" |
2995 |
||
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2996 |
|isSyntaxHighlighter err selectorSymbol rec names recType selClass newSelector nm nowhereImplemented |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2997 |
pos1 pos2 canDefine| |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2998 |
|
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
2999 |
isSyntaxHighlighter := self isSyntaxHighlighter. |
141 | 3000 |
|
3001 |
" |
|
3002 |
if compiling lazy, or errors are to be ignored, or there |
|
3003 |
is no requestor, do not check |
|
3004 |
" |
|
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3005 |
isSyntaxHighlighter ifFalse:[ |
1545 | 3006 |
(LazyCompilation == true) ifTrue:[^ aSelectorString]. |
1022 | 3007 |
(ignoreErrors or:[ignoreWarnings]) ifTrue:[^ aSelectorString]. |
3008 |
(requestor isNil or:[requestor isStream]) ifTrue:[^ aSelectorString]. |
|
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
3009 |
]. |
141 | 3010 |
|
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3011 |
canDefine := false. |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3012 |
|
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3013 |
pos1 := posVector first start. |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3014 |
pos2 := posVector last stop. |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3015 |
|
1301
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
3016 |
aSelectorString = '#' ifTrue:[ |
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
3017 |
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
|
3018 |
]. |
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
3019 |
|
141 | 3020 |
" |
3021 |
check if the selector is known at all |
|
3022 |
- if not, it cannot be understood |
|
3023 |
" |
|
1327 | 3024 |
nowhereImplemented := false. |
3025 |
||
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3026 |
selectorSymbol := aSelectorString asSymbolIfInterned. |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3027 |
selectorSymbol isNil ifTrue:[ |
1327 | 3028 |
nowhereImplemented := true. |
1518 | 3029 |
] ifFalse:[ |
3030 |
"/ temporarily disabled - too slow. |
|
3031 |
"/ self isSyntaxHighlighter ifTrue:[ |
|
3032 |
"/ nowhereImplemented := (self implementedInAnyClass:selectorSymbol) not. |
|
3033 |
"/ ] |
|
1327 | 3034 |
]. |
3035 |
||
3036 |
nowhereImplemented ifTrue:[ |
|
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3037 |
err := ' is currently nowhere implemented'. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3038 |
|
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3039 |
" |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3040 |
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
|
3041 |
" |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3042 |
((methodVarNames notNil and:[methodVarNames includes:aSelectorString]) |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3043 |
or:[(methodArgNames notNil and:[methodArgNames includes:aSelectorString]) |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3044 |
or:[classToCompileFor notNil |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3045 |
and:[((names := self classesInstVarNames) notNil and:[names includes:aSelectorString]) |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3046 |
or:[((names := self classesClassInstVarNames) notNil and:[names includes:aSelectorString]) |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3047 |
or:[(names := self classesClassVarNames) notNil and:[names includes:aSelectorString] |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3048 |
]]]]]) ifTrue:[ |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3049 |
err := ' is currently nowhere implemented .. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3050 |
.. but a variable with that name is defined. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3051 |
|
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3052 |
Missing ''.'' after the previous expression |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3053 |
or missing keyword/receiver before that word ?'. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3054 |
]. |
1327 | 3055 |
] ifFalse:[ |
3056 |
receiver notNil ifTrue:[ |
|
3057 |
selClass := self typeOfNode:receiver. |
|
3058 |
selClass notNil ifTrue:[ |
|
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3059 |
"this could be performed if selClass isNil, but it is too slow" |
1507 | 3060 |
err := self checkSelector:selectorSymbol for:receiver inClass:selClass. |
1327 | 3061 |
]. |
3062 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
3063 |
(receiver isConstant or:[receiver isBlock]) ifTrue:[ |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3064 |
err notNil ifTrue:[ |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
3065 |
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
|
3066 |
]. |
1327 | 3067 |
] ifFalse:[(((recType := receiver type) == #GlobalVariable) |
3068 |
or:[recType == #PrivateClass]) ifTrue:[ |
|
3069 |
rec := receiver evaluate. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
3070 |
"/ dont check autoloaded classes - it may work after loading |
1327 | 3071 |
(rec isNil |
3072 |
or:[rec isBehavior and:[rec isLoaded not]]) ifTrue:[ |
|
3073 |
^ aSelectorString |
|
3074 |
]. |
|
3075 |
||
3076 |
err notNil ifTrue:[ |
|
3077 |
(rec isBehavior |
|
3078 |
and:[rec theNonMetaclass name = receiver name]) ifTrue:[ |
|
3079 |
err := err, ' in ' , rec theNonMetaclass name. |
|
3080 |
] ifFalse:[ |
|
3081 |
err := err, ' in currently assigned value (is currently ' , rec classNameWithArticle , ')'. |
|
3082 |
] |
|
3083 |
]. |
|
3084 |
] ifFalse:[receiver isSuper ifTrue:[ |
|
3085 |
receiver isHere ifFalse:[ |
|
3086 |
err notNil ifTrue:[ |
|
3087 |
err := err, ' in superclass chain'. |
|
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3088 |
]. |
1327 | 3089 |
] ifTrue:[ |
3090 |
err notNil ifTrue:[ |
|
3091 |
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
|
3092 |
]. |
1327 | 3093 |
] |
3094 |
] ifFalse:[receiver isSelf ifTrue:[ |
|
3095 |
err notNil ifTrue:[ |
|
3096 |
|subErr| |
|
3097 |
||
3098 |
"/ understood by all subclasses ? |
|
3099 |
classToCompileFor allSubclassesDo:[:eachSubclass | |
|
3100 |
subErr isNil ifTrue:[ |
|
3101 |
selClass := eachSubclass. |
|
1507 | 3102 |
subErr := self checkSelector:selectorSymbol for:receiver inClass:selClass. |
1327 | 3103 |
]. |
3104 |
]. |
|
3105 |
subErr notNil ifTrue:[ |
|
3106 |
err := subErr, ' in this class, superclass chain or all subclasses' |
|
3107 |
] ifFalse:[ |
|
3108 |
err := err, ' in this class or superclass chain'. |
|
1440 | 3109 |
]. |
3110 |
canDefine := true. |
|
1327 | 3111 |
]. |
3112 |
] ifFalse:[(receiver isUnaryMessage |
|
3113 |
and:[receiver selector == #class |
|
3114 |
and:[receiver receiver isSelf]]) ifTrue:[ |
|
3115 |
"its a message to self class - can check this too ..." |
|
3116 |
err notNil ifTrue:[ |
|
3117 |
classToCompileFor isMeta ifTrue:[ |
|
3118 |
err := err, ' for the classes class'. |
|
1507 | 3119 |
(self checkSelector:selectorSymbol for:receiver inClass:classToCompileFor) isNil ifTrue:[ |
1327 | 3120 |
err := err, '...\\...but its implemented for the class itself. You probably do not want the #class message here.'. |
3121 |
err := err withCRs. |
|
3122 |
]. |
|
3123 |
] ifFalse:[ |
|
3124 |
err := err, ' for my class'. |
|
1507 | 3125 |
(self checkSelector:selectorSymbol for:receiver inClass:classToCompileFor) isNil ifTrue:[ |
1327 | 3126 |
err := err, '...\\...but its implemented for instances. You may want to remove the #class message.'. |
3127 |
err := err withCRs. |
|
3128 |
]. |
|
1203
2bd6633eced0
better error message for 'class foo', where foo is implemented in the instance.
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
3129 |
]. |
2bd6633eced0
better error message for 'class foo', where foo is implemented in the instance.
Claus Gittinger <cg@exept.de>
parents:
1202
diff
changeset
|
3130 |
]. |
1327 | 3131 |
] ifFalse:[(receiver isMethodVariable and:[receiver token type isNil]) ifTrue:[ |
3132 |
"if it is an uninitialized variable ..." |
|
3133 |
((modifiedLocalVars isNil or:[(modifiedLocalVars includes:receiver name) not]) |
|
1441 | 3134 |
and:[hasPrimitiveCode not |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3135 |
and:[currentBlock isNil |
1327 | 3136 |
and:[alreadyWarnedUninitializedVars isNil |
1442 | 3137 |
or:[(alreadyWarnedUninitializedVars includes:receiver name) not]]]]) |
1327 | 3138 |
ifTrue:[ |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3139 |
((#(at: at:put: basicAt: basicAt:put:) includes:selectorSymbol) |
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3140 |
or:[(nil respondsTo:selectorSymbol) not])ifTrue:[ |
1327 | 3141 |
"/ avoid trouble in miniTalk |
3142 |
"/ during bootstrap |
|
3143 |
nm := receiver name. |
|
3144 |
Text notNil ifTrue:[ |
|
3145 |
nm := nm allItalic |
|
3146 |
]. |
|
3147 |
err := 'sent to possibly uninitialized variable ''' , nm , ''' here (?)'. |
|
3148 |
alreadyWarnedUninitializedVars isNil ifTrue:[ |
|
3149 |
alreadyWarnedUninitializedVars := Set new |
|
3150 |
]. |
|
3151 |
alreadyWarnedUninitializedVars add:receiver name |
|
3152 |
] |
|
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3153 |
] |
1327 | 3154 |
] ifFalse:[ |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3155 |
(err notNil and:[selClass notNil]) ifTrue:[ |
1327 | 3156 |
err := err, ' (message to ' , selClass nameWithArticle , ')'. |
3157 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
3158 |
]]]]]]. |
1327 | 3159 |
] |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3160 |
]. |
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3161 |
|
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3162 |
err notNil ifTrue:[ |
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3163 |
(receiver notNil |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3164 |
and:[((recType := receiver type) == #GlobalVariable) |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3165 |
or:[recType == #PrivateClass]]) ifTrue:[ |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3166 |
"/ dont check autoloaded classes |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3167 |
"/ - it may work after loading |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3168 |
|
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3169 |
rec := receiver evaluate. |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3170 |
(rec notNil |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3171 |
and:[rec isBehavior |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3172 |
and:[rec isLoaded not]]) ifTrue:[ |
1022 | 3173 |
^ aSelectorString |
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3174 |
]. |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3175 |
rec class == UndefinedVariable ifTrue:[ |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3176 |
"/ dont check undefined vars; |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3177 |
"/ it may work after loading/defining |
1022 | 3178 |
^ aSelectorString |
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3179 |
]. |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3180 |
]. |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3181 |
Text notNil ifTrue:[ |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3182 |
err := '"' , aSelectorString allBold, '" ', err |
1052
0a1e613468f5
avoid trouble if Text class is not present (in mini-image)
Claus Gittinger <cg@exept.de>
parents:
1043
diff
changeset
|
3183 |
] ifFalse:[ |
1158
f2cbdb21e0b0
Check for obsolete methods, if possible.
Stefan Vogel <sv@exept.de>
parents:
1157
diff
changeset
|
3184 |
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
|
3185 |
]. |
1157
122be9201878
selectorCheck (do not complain for new selector being recursively invoked)
Claus Gittinger <cg@exept.de>
parents:
1156
diff
changeset
|
3186 |
"/ 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
|
3187 |
(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
|
3188 |
^ aSelectorString |
122be9201878
selectorCheck (do not complain for new selector being recursively invoked)
Claus Gittinger <cg@exept.de>
parents:
1156
diff
changeset
|
3189 |
]. |
1499
69439abfdb93
Warn when using subclassResponsibility or shouldNotImplememt methods
Stefan Vogel <sv@exept.de>
parents:
1495
diff
changeset
|
3190 |
isSyntaxHighlighter ifTrue:[ |
1439 | 3191 |
posVector do:[:p | |
3192 |
self markUnknownIdentifierFrom:(p start) to:(p stop). |
|
3193 |
]. |
|
3194 |
]. |
|
1440 | 3195 |
err := err , '\\This is a warning from the compiler - the code has not yet been executed/compiled.'. |
1022 | 3196 |
newSelector := self correctSelector:aSelectorString |
1439 | 3197 |
message:err withCRs positions:posVector in:selClass for:receiver. |
1022 | 3198 |
"/ self warning:('#' , aSelectorString , '\\' , err) withCRs position:pos1 to:pos2. |
3199 |
^ newSelector. |
|
141 | 3200 |
]. |
1022 | 3201 |
^ aSelectorString |
141 | 3202 |
|
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
3203 |
"Modified: / 5.9.1995 / 17:02:11 / claus" |
1022 | 3204 |
"Modified: / 19.1.2000 / 16:34:03 / cg" |
1327 | 3205 |
! |
3206 |
||
3207 |
typeOfNode:aNode |
|
3208 |
|nodeVal nodeType| |
|
3209 |
||
3210 |
aNode isConstant ifTrue:[ |
|
3211 |
" |
|
3212 |
if the receiver is a constant, we can check if it responds |
|
3213 |
to this selector |
|
3214 |
" |
|
3215 |
nodeVal := aNode evaluate. |
|
3216 |
^ nodeVal class. |
|
3217 |
]. |
|
3218 |
||
3219 |
"/ this should help with typos, sending #ifTrue to blocks ... |
|
3220 |
aNode isBlock ifTrue:[ |
|
3221 |
^ Block |
|
3222 |
]. |
|
3223 |
||
3224 |
(((nodeType := aNode type) == #GlobalVariable) |
|
3225 |
or:[nodeType == #PrivateClass]) ifTrue:[ |
|
3226 |
"if the receiver is a global, we check it too ..." |
|
3227 |
||
3228 |
nodeVal := aNode evaluate. |
|
3229 |
"/ dont check autoloaded classes |
|
3230 |
"/ - it may work after loading |
|
3231 |
(nodeVal isNil |
|
3232 |
or:[nodeVal isBehavior and:[nodeVal isLoaded not]]) ifTrue:[ |
|
3233 |
^ nil |
|
3234 |
]. |
|
3235 |
||
3236 |
^ nodeVal class. |
|
3237 |
]. |
|
3238 |
||
3239 |
aNode isSuper ifTrue:[ |
|
3240 |
"if its a super- or here-send, we can do more checking" |
|
3241 |
aNode isHere ifFalse:[ |
|
3242 |
^ classToCompileFor superclass ? UndefinedObject. |
|
3243 |
]. |
|
3244 |
^ classToCompileFor. |
|
3245 |
]. |
|
3246 |
aNode isSelf ifTrue:[ |
|
3247 |
^ classToCompileFor. |
|
3248 |
]. |
|
3249 |
||
3250 |
(aNode isUnaryMessage) ifTrue:[ |
|
3251 |
(aNode selector == #class) ifTrue:[ |
|
3252 |
aNode receiver isSelf ifTrue:[ |
|
3253 |
"its a message to self class - can check this too ..." |
|
3254 |
^ classToCompileFor class. |
|
3255 |
]. |
|
3256 |
]. |
|
3257 |
( #(#'isNil' #'notNil') includes:aNode selector) ifTrue:[ |
|
3258 |
^ Boolean. |
|
3259 |
] |
|
3260 |
]. |
|
3261 |
aNode isBinaryMessage ifTrue:[ |
|
3262 |
( #(#'<' #'>' #'>=' #'<=' #'=' #'==' #'~=' #'~~') includes:aNode selector) ifTrue:[ |
|
3263 |
^ Boolean. |
|
3264 |
] |
|
3265 |
]. |
|
3266 |
||
3267 |
^ nil |
|
0 | 3268 |
! ! |
3269 |
||
3270 |
!Parser methodsFor:'error handling'! |
|
3271 |
||
1259 | 3272 |
blockArgRedefined:tokenName from:pos1 to:pos2 |
3273 |
"argname reuse" |
|
3274 |
||
3275 |
self isSyntaxHighlighter ifTrue:[ |
|
3276 |
self markBadIdentifierFrom:pos1 to:pos2. |
|
3277 |
] ifFalse:[ |
|
3278 |
self |
|
3279 |
syntaxError:'redefinition of ''' , tokenName , ''' in argument list.' |
|
3280 |
position:pos1 to:pos2 |
|
3281 |
]. |
|
3282 |
! |
|
3283 |
||
1495 | 3284 |
errorMessageForUndefined:aName |
3285 |
|idx implementors| |
|
3286 |
||
3287 |
classToCompileFor notNil ifTrue:[ |
|
3288 |
"/ is it an instance-variable marked inaccessable ? |
|
3289 |
||
3290 |
idx := (self classesInstVarNames) indexOf:(aName , '*') startingAt:1. |
|
3291 |
idx ~~ 0 ifTrue:[ |
|
3292 |
^ '''%1'' is a hidden instvar (not accessable from ST-code)'. |
|
3293 |
]. |
|
3294 |
||
3295 |
"/ is it an instance variable, while evaluateing for the class ? |
|
3296 |
classToCompileFor isMeta ifTrue:[ |
|
3297 |
(classToCompileFor soleInstance allInstVarNames includes:aName) ifTrue:[ |
|
3298 |
^ 'Warning: ''%1'' is an instvar\(hint: you are evaluating/compiling in the classes context)'. |
|
3299 |
] |
|
3300 |
] |
|
3301 |
]. |
|
3302 |
self isDoIt ifTrue:[ |
|
3303 |
implementors := SystemBrowser |
|
3304 |
findImplementorsOf:aName |
|
3305 |
in:(Smalltalk allClasses) |
|
3306 |
ignoreCase:false. |
|
3307 |
implementors size > 0 ifTrue:[ |
|
3308 |
^ '''%1'' is undefined but known as a message selector.\(hint: did you forget to select the receiver ?)'. |
|
3309 |
]. |
|
3310 |
]. |
|
3311 |
^ '''%1'' is undefined'. |
|
3312 |
! |
|
3313 |
||
141 | 3314 |
exitWith:something |
3315 |
"this is the longjump out of evaluation via a return expression" |
|
3316 |
||
3317 |
evalExitBlock value:something |
|
3318 |
! |
|
3319 |
||
3320 |
identifierExpectedIn:what |
|
3321 |
|msg| |
|
3322 |
||
3323 |
(#(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
|
3324 |
msg := 'Reserved keyword in ' |
141 | 3325 |
] ifFalse:[ |
1260
50e4668049aa
identifier expected - better error message
Claus Gittinger <cg@exept.de>
parents:
1259
diff
changeset
|
3326 |
msg := 'Identifier expected in ' |
50e4668049aa
identifier expected - better error message
Claus Gittinger <cg@exept.de>
parents:
1259
diff
changeset
|
3327 |
]. |
50e4668049aa
identifier expected - better error message
Claus Gittinger <cg@exept.de>
parents:
1259
diff
changeset
|
3328 |
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
|
3329 |
position:tokenPosition to:source position1Based - 1. |
141 | 3330 |
^ #Error |
3331 |
! |
|
3332 |
||
1259 | 3333 |
methodArgRedefined:tokenName from:pos1 to:pos2 |
3334 |
"argname reuse" |
|
3335 |
||
3336 |
self isSyntaxHighlighter ifTrue:[ |
|
3337 |
self markBadIdentifierFrom:pos1 to:pos2. |
|
3338 |
] ifFalse:[ |
|
3339 |
self |
|
3340 |
syntaxError:'redefinition of ''' , tokenName , ''' in argument list.' |
|
3341 |
position:pos1 to:pos2 |
|
3342 |
]. |
|
3343 |
! |
|
3344 |
||
0 | 3345 |
showErrorMessage:aMessage position:pos |
19 | 3346 |
"redefined since parser can give more detailed info about |
3347 |
the class & selector where the error occured." |
|
3348 |
||
1534 | 3349 |
|msg| |
71 | 3350 |
|
19 | 3351 |
ignoreErrors ifFalse:[ |
1160 | 3352 |
Smalltalk silentLoading == true ifFalse:[ |
1534 | 3353 |
msg := ''. |
1160 | 3354 |
pos notNil ifTrue:[ |
1534 | 3355 |
msg := msg , (pos printString). |
3356 |
msg := msg , ' '. |
|
1160 | 3357 |
]. |
1534 | 3358 |
msg := msg , aMessage. |
1160 | 3359 |
selector notNil ifTrue:[ |
1534 | 3360 |
msg := msg , ' in '. |
1160 | 3361 |
classToCompileFor notNil ifTrue:[ |
1534 | 3362 |
msg := msg , classToCompileFor name , '>>' |
3363 |
]. |
|
3364 |
msg := msg , selector. |
|
1160 | 3365 |
] ifFalse:[ |
3366 |
classToCompileFor notNil ifTrue:[ |
|
1534 | 3367 |
msg := msg , ' (' , classToCompileFor name , ')' |
1160 | 3368 |
] |
3369 |
]. |
|
1534 | 3370 |
|
3371 |
UserInformation isHandled ifTrue:[ |
|
3372 |
UserInformation raiseErrorString:msg |
|
3373 |
] ifFalse:[ |
|
3374 |
Transcript showCR:msg. |
|
3375 |
] |
|
1160 | 3376 |
] |
0 | 3377 |
] |
273 | 3378 |
|
3379 |
"Modified: 18.5.1996 / 15:44:15 / cg" |
|
0 | 3380 |
! |
3381 |
||
171 | 3382 |
showErrorMessageForClass:aClass |
3383 |
"/ compiler parseError:'syntax error'. |
|
3384 |
Transcript show:' '. |
|
3385 |
aClass notNil ifTrue:[ |
|
619 | 3386 |
Transcript show:aClass name , '>>' |
171 | 3387 |
]. |
3388 |
selector notNil ifTrue:[ |
|
619 | 3389 |
Transcript show:(selector) |
171 | 3390 |
]. |
273 | 3391 |
Transcript showCR:' -> Error'. |
171 | 3392 |
|
3393 |
"Created: 13.12.1995 / 20:24:34 / cg" |
|
273 | 3394 |
"Modified: 18.5.1996 / 15:44:17 / cg" |
171 | 3395 |
! |
3396 |
||
0 | 3397 |
undefError:aName position:pos1 to:pos2 |
3 | 3398 |
"report an undefined variable error - return true, if it should be |
86 | 3399 |
corrected. If not corrected, only one warning is made per undefined |
3400 |
variable." |
|
3401 |
||
1495 | 3402 |
|ex doCorrect boldName| |
1400 | 3403 |
|
3404 |
ex := UndefinedVariableNotification newException. |
|
3405 |
ex parser:self. |
|
3406 |
ex parameter:aName. |
|
3407 |
ex suspendedContext:thisContext. |
|
3408 |
doCorrect := ex raiseRequest. |
|
1399
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
3409 |
doCorrect notNil ifTrue:[ |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
3410 |
^ doCorrect |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
3411 |
]. |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
3412 |
|
607 | 3413 |
warnUndeclared ifFalse:[^ false]. |
915
d3add8c1bb04
dont rewarn for same missing namespace
Claus Gittinger <cg@exept.de>
parents:
903
diff
changeset
|
3414 |
ignoreWarnings ifTrue:[^ false]. |
607 | 3415 |
|
86 | 3416 |
" |
3417 |
alredy warned about this one ? |
|
3418 |
" |
|
3419 |
warnedUndefVars notNil ifTrue:[ |
|
877 | 3420 |
(warnedUndefVars includes:aName) ifTrue:[ |
3421 |
"already warned about this one" |
|
3422 |
^ false |
|
3423 |
]. |
|
86 | 3424 |
]. |
3425 |
||
131 | 3426 |
"/ (classToCompileFor notNil |
3427 |
"/ and:[classToCompileFor superclass notNil |
|
3428 |
"/ and:[classToCompileFor superclass instanceVariableString isNil]]) ifTrue:[ |
|
132
5be56a5e90b7
added methods for silent parsing (parseMethod / parseMethodSpec)
Claus Gittinger <cg@exept.de>
parents:
131
diff
changeset
|
3429 |
"/ 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
|
3430 |
"/ ^ false |
131 | 3431 |
"/ ]. |
3432 |
||
1285 | 3433 |
boldName := aName allBold. |
3434 |
||
131 | 3435 |
(requestor isNil or:[requestor isStream]) ifTrue:[ |
877 | 3436 |
aName first isUppercase ifFalse:[ |
1285 | 3437 |
self showErrorMessage:('Error: ''' , boldName , ''' is undefined') position:pos1. |
877 | 3438 |
]. |
3439 |
doCorrect := false. |
|
86 | 3440 |
] ifFalse:[ |
877 | 3441 |
" |
3442 |
ask requestor for correct/continue/abort ... |
|
3443 |
it is supposed to raise abort or return true/false. |
|
3444 |
True return means that correction is wanted. |
|
3445 |
" |
|
1495 | 3446 |
doCorrect := self |
3447 |
correctableError:((self errorMessageForUndefined:aName) bindWith:boldName) withCRs |
|
3448 |
position:pos1 to:pos2 |
|
86 | 3449 |
]. |
3450 |
||
877 | 3451 |
doCorrect == false ifTrue:[ |
3452 |
warnedUndefVars isNil ifTrue:[ |
|
3453 |
warnedUndefVars := Set new. |
|
3454 |
]. |
|
3455 |
warnedUndefVars add:aName. |
|
3 | 3456 |
]. |
0 | 3457 |
|
86 | 3458 |
^ doCorrect |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
3459 |
|
607 | 3460 |
"Modified: 7.9.1997 / 02:14:36 / cg" |
1160 | 3461 |
! |
3462 |
||
3463 |
warnUnused:aNameCollection |
|
3464 |
"report an unused method variable" |
|
3465 |
||
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
3466 |
|s msg answer| |
1160 | 3467 |
|
3468 |
(ignoreErrors not and:[ignoreWarnings not and:[warnUnusedVars]]) ifTrue:[ |
|
3469 |
s := '' writeStream. |
|
1167 | 3470 |
s nextPutAll:'Unused method variable(s): '. |
1160 | 3471 |
aNameCollection asSortedCollection do:[:name| |
1427
ec344fd520ba
no need for asText when sending allBold
Claus Gittinger <cg@exept.de>
parents:
1423
diff
changeset
|
3472 |
s nextPutAll:' '; nextPutAll:name allBold. |
1160 | 3473 |
]. |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3474 |
msg := s contents. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3475 |
|
1160 | 3476 |
(requestor isNil or:[requestor isStream]) ifTrue:[ |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3477 |
self showErrorMessage:('Warning: ', msg) position:nil. |
1160 | 3478 |
] ifFalse:[ |
1167 | 3479 |
answer := requestor |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3480 |
unusedVariableWarning:msg |
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
3481 |
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
|
3482 |
|
1167 | 3483 |
answer == true ifTrue:[ |
3484 |
"/ delete the definitions ... |
|
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
3485 |
aNameCollection do:[:eachName | |
1432
a85ce0ec6ee4
deleting multiple local variables
Claus Gittinger <cg@exept.de>
parents:
1427
diff
changeset
|
3486 |
self deleteDefinitionOf:eachName in:(localVarDefPosition first) to:(localVarDefPosition last). |
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
3487 |
]. |
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
3488 |
RestartCompilationSignal raise |
1167 | 3489 |
]. |
1160 | 3490 |
]. |
3491 |
]. |
|
1221
2768cbe3be2b
finished remove unused vars;
Claus Gittinger <cg@exept.de>
parents:
1220
diff
changeset
|
3492 |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3493 |
"Modified: / 17.11.2001 / 10:30:47 / cg" |
0 | 3494 |
! ! |
3495 |
||
1363 | 3496 |
!Parser methodsFor:'evaluating expressions'! |
3497 |
||
3498 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile |
|
3499 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
3500 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
3501 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
3502 |
is non-nil, it is evaluated if an error occurs. |
|
3503 |
Finally, compile specifies if the string should be compiled down to |
|
3504 |
bytecode or instead be interpreted from the parseTree. |
|
3505 |
The first should be done for doIts etc, where a readable walkback is |
|
3506 |
required. |
|
3507 |
The latter is better done for constants, styleSheet and resource |
|
3508 |
reading and simple sends, where the overhead of compilation is bigger |
|
3509 |
than the interpretation overhead." |
|
3510 |
||
1548 | 3511 |
^ self |
3512 |
evaluate:aStringOrStream |
|
3513 |
in:aContext |
|
3514 |
receiver:anObject |
|
3515 |
notifying:requestor |
|
3516 |
logged:logged |
|
3517 |
ifFail:failBlock |
|
3518 |
compile:compile |
|
3519 |
checkForEndOfInput:true |
|
3520 |
! |
|
3521 |
||
3522 |
evaluate:aStringOrStream in:aContext receiver:anObject notifying:requestor logged:logged ifFail:failBlock compile:compile checkForEndOfInput:checkForEndOfInput |
|
3523 |
"return the result of evaluating aStringOrStream, errors are reported to requestor. |
|
3524 |
Allow access to anObject as self and to its instVars (used in the inspector). |
|
3525 |
If logged is true, an entry is added to the change-file. If the failBlock argument |
|
3526 |
is non-nil, it is evaluated if an error occurs. |
|
3527 |
Finally, compile specifies if the string should be compiled down to |
|
3528 |
bytecode or instead be interpreted from the parseTree. |
|
3529 |
The first should be done for doIts etc, where a readable walkback is |
|
3530 |
required. |
|
3531 |
The latter is better done for constants, styleSheet and resource |
|
3532 |
reading and simple sends, where the overhead of compilation is bigger |
|
3533 |
than the interpretation overhead." |
|
3534 |
||
1363 | 3535 |
|tree mustBackup loggedString chgStream value s sReal spc |
3536 |
nameSpaceQuerySignal compiler| |
|
3537 |
||
3538 |
aStringOrStream isNil ifTrue:[ |
|
3539 |
EmptySourceNotificationSignal raiseRequest. |
|
3540 |
^ nil |
|
3541 |
]. |
|
3542 |
(mustBackup := aStringOrStream isStream) ifTrue:[ |
|
3543 |
s := aStringOrStream. |
|
3544 |
] ifFalse:[ |
|
3545 |
loggedString := aStringOrStream. |
|
3546 |
s := ReadStream on:aStringOrStream. |
|
3547 |
]. |
|
3548 |
||
3549 |
self source:s. |
|
3550 |
||
3551 |
self parseForCode. |
|
3552 |
self foldConstants:nil. |
|
3553 |
self setSelf:anObject. |
|
3554 |
self setContext:aContext. |
|
3555 |
aContext notNil ifTrue:[ |
|
3556 |
self setSelf:(aContext receiver). |
|
3557 |
"/ aContext method notNil ifTrue:[ |
|
3558 |
"/ cls := aContext method mclass |
|
3559 |
"/ ]. |
|
3560 |
"/ self setClassToCompileFor:(cls ? aContext receiver class). |
|
3561 |
self setClassToCompileFor:(aContext receiver class). |
|
3562 |
]. |
|
3563 |
self notifying:requestor. |
|
3564 |
self nextToken. |
|
3565 |
self evalExitBlock:[:value | self release. ^ value]. |
|
3566 |
tree := self parseMethodBodyOrEmpty. |
|
3567 |
||
1548 | 3568 |
checkForEndOfInput ifTrue:[self checkForEndOfInput]. |
1363 | 3569 |
|
3570 |
"if reading from a stream, backup for next expression" |
|
3571 |
mustBackup ifTrue:[ |
|
3572 |
self backupPosition |
|
3573 |
]. |
|
3574 |
||
3575 |
(self errorFlag or:[tree == #Error]) ifTrue:[ |
|
3576 |
failBlock notNil ifTrue:[ |
|
3577 |
^ failBlock value |
|
3578 |
]. |
|
3579 |
^ #Error |
|
3580 |
]. |
|
3581 |
||
3582 |
tree isNil ifTrue:[ |
|
3583 |
EmptySourceNotificationSignal raiseRequest. |
|
3584 |
^ nil |
|
3585 |
]. |
|
3586 |
||
3587 |
(logged |
|
3588 |
and:[loggedString notNil |
|
3589 |
and:[Smalltalk logDoits]]) ifTrue:[ |
|
3590 |
Class updateChangeFileQuerySignal query ifTrue:[ |
|
3591 |
chgStream := Class changesStream. |
|
3592 |
chgStream notNil ifTrue:[ |
|
3593 |
chgStream nextChunkPut:loggedString. |
|
3594 |
chgStream cr. |
|
3595 |
chgStream close |
|
3596 |
] |
|
3597 |
]. |
|
3598 |
Project notNil ifTrue:[ |
|
3599 |
Class updateChangeListQuerySignal query ifTrue:[ |
|
3600 |
Project addDoIt:loggedString |
|
3601 |
] |
|
3602 |
] |
|
3603 |
]. |
|
3604 |
||
3605 |
" |
|
3606 |
during the evaluation, handle nameSpace queries |
|
3607 |
from the value as defined by any namespace directive. |
|
3608 |
This, if its a class definition expression, the class will |
|
3609 |
be installed there. |
|
3610 |
" |
|
3611 |
nameSpaceQuerySignal := Class nameSpaceQuerySignal. |
|
3612 |
||
3613 |
spc := self getNameSpace. |
|
3614 |
spc isNil ifTrue:[ |
|
3615 |
(requestor respondsTo:#currentNameSpace) ifTrue:[ |
|
3616 |
spc := requestor currentNameSpace |
|
3617 |
] ifFalse:[ |
|
3618 |
spc := nameSpaceQuerySignal query. |
|
3619 |
] |
|
3620 |
]. |
|
3621 |
||
3622 |
nameSpaceQuerySignal answer:spc |
|
3623 |
do:[ |
|
3624 |
|method| |
|
3625 |
||
3626 |
" |
|
3627 |
if compile is false, or the parse tree is that of a constant, |
|
3628 |
or a variable, quickly return its value. |
|
3629 |
This is used for example, when reading simple objects |
|
3630 |
via #readFrom:. |
|
3631 |
The overhead of compiling a method is avoided in this case. |
|
3632 |
" |
|
3633 |
((SuppressDoItCompilation == true) |
|
3634 |
or:[compile not |
|
3635 |
or:[tree isConstant |
|
3636 |
or:[tree isVariable |
|
3637 |
or:[aStringOrStream isStream |
|
3638 |
or:[aContext notNil]]]]]) ifTrue:[ |
|
3639 |
^ tree evaluate |
|
3640 |
]. |
|
3641 |
||
3642 |
" |
|
3643 |
if I am the ByteCodeCompiler, |
|
3644 |
generate a dummy method, execute it and return the value. |
|
3645 |
otherwise, just evaluate the tree; slower, but not too bad ... |
|
3646 |
||
3647 |
This allows systems to be delivered without the ByteCodeCompiler, |
|
3648 |
and still evaluate expressions |
|
3649 |
(needed to read resource files or to process .rc files). |
|
3650 |
" |
|
3651 |
self == Parser ifTrue:[ |
|
3652 |
self evalExitBlock:[:value | self release. ^ value]. |
|
3653 |
value := tree evaluate. |
|
3654 |
self evalExitBlock:nil. |
|
3655 |
] ifFalse:[ |
|
3656 |
s := self correctedSource. |
|
3657 |
s isNil ifTrue:[ |
|
3658 |
aStringOrStream isStream ifTrue:[ |
|
3659 |
s := self collectedSource. "/ does not work yet ... |
|
3660 |
] ifFalse:[ |
|
3661 |
s := aStringOrStream |
|
3662 |
]. |
|
3663 |
]. |
|
3664 |
||
3665 |
"/ actually, its a block, to allow |
|
3666 |
"/ easy return ... |
|
3667 |
||
1421
dcdc178254f0
preserve lineNumbers in compiled code (evaluate)
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
3668 |
sReal := 'doIt ^[ ' , s , '\] value' withCRs. |
1363 | 3669 |
|
1366
f91f6a0a56d5
when required to compile, use Compiler instead of self class.
Claus Gittinger <cg@exept.de>
parents:
1365
diff
changeset
|
3670 |
compiler := ByteCodeCompiler new. |
1363 | 3671 |
compiler initializeFlagsFrom:self. |
3672 |
method := compiler |
|
3673 |
compile:sReal |
|
3674 |
forClass:anObject class |
|
3675 |
inCategory:'_temporary_' |
|
3676 |
notifying:requestor |
|
3677 |
install:false |
|
3678 |
skipIfSame:false |
|
3679 |
silent:true |
|
3680 |
foldConstants:false. |
|
3681 |
||
3682 |
method notNil ifTrue:[ |
|
3683 |
method ~~ #Error ifTrue:[ |
|
3684 |
" |
|
3685 |
fake: patch the source string, to what the user expects |
|
3686 |
in the browser |
|
3687 |
" |
|
1421
dcdc178254f0
preserve lineNumbers in compiled code (evaluate)
Claus Gittinger <cg@exept.de>
parents:
1420
diff
changeset
|
3688 |
method source:"' ' , "s string. |
1363 | 3689 |
" |
3690 |
dont do any just-in-time compilation on it. |
|
3691 |
" |
|
3692 |
method checked:true. |
|
3693 |
||
3694 |
value := method |
|
3695 |
valueWithReceiver:anObject |
|
3696 |
arguments:nil "/ (Array with:m) |
|
1440 | 3697 |
selector:(requestor isNil ifTrue:#'doItX' ifFalse:#'doIt') "/ #doIt: |
1363 | 3698 |
search:nil |
3699 |
sender:nil. |
|
3700 |
] ifFalse:[ |
|
3701 |
self evalExitBlock:[:value | self release. ^ value]. |
|
3702 |
value := tree evaluate. |
|
3703 |
self evalExitBlock:nil. |
|
3704 |
] |
|
3705 |
]. |
|
3706 |
] |
|
3707 |
]. |
|
3708 |
self release. |
|
3709 |
^ value |
|
3710 |
||
3711 |
"Created: / 8.2.1997 / 19:34:44 / cg" |
|
3712 |
"Modified: / 18.3.1999 / 18:25:40 / stefan" |
|
3713 |
"Modified: / 6.2.2000 / 15:01:57 / cg" |
|
3714 |
! ! |
|
3715 |
||
0 | 3716 |
!Parser methodsFor:'parsing'! |
3717 |
||
141 | 3718 |
block |
3719 |
"parse a block; return a node-tree, nil or #Error" |
|
3720 |
||
883 | 3721 |
|node args argNames arg pos pos2 lno| |
141 | 3722 |
|
3723 |
lno := tokenLineNr. |
|
3724 |
self nextToken. |
|
3725 |
(tokenType == $: ) ifTrue:[ |
|
663 | 3726 |
[tokenType == $:] whileTrue:[ |
3727 |
pos := tokenPosition. |
|
3728 |
self nextToken. |
|
1394
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3729 |
|
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3730 |
(pos == (tokenPosition - 1)) ifFalse:[ |
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3731 |
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
|
3732 |
]. |
883 | 3733 |
(tokenType ~~ #Identifier) ifTrue:[ |
663 | 3734 |
^ self identifierExpectedIn:'block-arg declaration' |
3735 |
]. |
|
883 | 3736 |
|
3737 |
pos2 := tokenPosition + tokenName size - 1. |
|
3738 |
self markArgumentIdentifierFrom:tokenPosition to:pos2. |
|
1519 | 3739 |
self checkBlockArgumentNameConventionsFor:tokenName. |
663 | 3740 |
arg := Variable name:tokenName. |
3741 |
args isNil ifTrue:[ |
|
3742 |
args := Array with:arg. |
|
3743 |
argNames := Array with:tokenName. |
|
3744 |
] ifFalse:[ |
|
3745 |
(argNames includes:tokenName) ifTrue:[ |
|
1259 | 3746 |
self blockArgRedefined:tokenName from:tokenPosition to:pos2 |
663 | 3747 |
]. |
3748 |
args := args copyWith:arg. |
|
3749 |
argNames := argNames copyWith:tokenName. |
|
3750 |
]. |
|
1394
93e75cb62f4f
incompatibility warning with space between colon and id in blockArgs.
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
3751 |
self nextToken. |
663 | 3752 |
]. |
3753 |
(tokenType ~~ $| ) ifTrue:[ |
|
3754 |
"ST-80 allows [:arg ]" |
|
3755 |
(tokenType == $] ) ifTrue:[ |
|
3756 |
node := BlockNode arguments:args home:currentBlock variables:nil. |
|
3757 |
node lineNumber:lno. |
|
3758 |
^ node |
|
3759 |
]. |
|
3760 |
self syntaxError:'| expected after block-arg declaration'. |
|
3761 |
^ #Error |
|
3762 |
]. |
|
3763 |
self nextToken |
|
141 | 3764 |
]. |
3765 |
node := self blockBody:args. |
|
3766 |
(node notNil and:[node ~~ #Error]) ifTrue:[ |
|
663 | 3767 |
node lineNumber:lno. |
141 | 3768 |
]. |
3769 |
^ node |
|
663 | 3770 |
|
3771 |
"Modified: / 31.3.1998 / 17:31:34 / cg" |
|
141 | 3772 |
! |
3773 |
||
3774 |
blockBody:args |
|
3775 |
"parse a blocks body; return a node-tree, nil or #Error" |
|
3776 |
||
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
3777 |
|stats node var vars lno pos2| |
141 | 3778 |
|
3779 |
lno := tokenLineNr. |
|
3780 |
(tokenType == $| ) ifTrue:[ |
|
668 | 3781 |
self nextToken. |
3782 |
[tokenType == $|] whileFalse:[ |
|
3783 |
(tokenType == #Identifier) ifFalse:[ |
|
3784 |
^ self identifierExpectedIn:'block-var declaration' |
|
3785 |
]. |
|
883 | 3786 |
pos2 := tokenPosition + tokenName size - 1. |
3787 |
self markLocalIdentifierFrom:tokenPosition to:pos2. |
|
1519 | 3788 |
self checkBlockVariableNameConventionsFor:tokenName. |
668 | 3789 |
var := Variable name:tokenName. |
3790 |
vars isNil ifTrue:[ |
|
3791 |
vars := Array with:var. |
|
3792 |
] 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
|
3793 |
(vars contains:[:var | var name = tokenName]) ifTrue:[ |
883 | 3794 |
"/ varname reuse |
3795 |
self isSyntaxHighlighter ifTrue:[ |
|
3796 |
self markBadIdentifierFrom:tokenPosition to:pos2. |
|
3797 |
] ifFalse:[ |
|
3798 |
self |
|
3799 |
parseError:'redefinition of ''' , tokenName , ''' in local variables' |
|
3800 |
position:tokenPosition to:pos2. |
|
3801 |
] |
|
668 | 3802 |
] ifFalse:[ |
3803 |
vars := vars copyWith:var. |
|
3804 |
] |
|
3805 |
]. |
|
3806 |
self nextToken. |
|
1471 | 3807 |
|
3808 |
AllowLocalVariableDeclarationWithInitializerExpression == true ifTrue:[ |
|
3809 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
3810 |
self nextToken. |
|
3811 |
"/ Q: should we allow literals only, or arbitrary expressions ? |
|
3812 |
self halt:'unimplemented feature'. |
|
3813 |
] |
|
3814 |
]. |
|
3815 |
AllowDomainVariables == true ifTrue:[ |
|
3816 |
(tokenType == $() ifTrue:[ |
|
3817 |
self variableTypeDeclarationFor:var. |
|
3818 |
]. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3819 |
]. |
668 | 3820 |
]. |
3821 |
self nextToken |
|
141 | 3822 |
]. |
382 | 3823 |
|
141 | 3824 |
node := BlockNode arguments:args home:currentBlock variables:vars. |
3825 |
node lineNumber:lno. |
|
3826 |
currentBlock := node. |
|
3827 |
stats := self blockStatementList. |
|
1169
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3828 |
(stats == #Error) ifTrue:[^ #Error]. |
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3829 |
|
382 | 3830 |
lineNumberInfo == #full ifTrue:[ |
668 | 3831 |
node endLineNumber:tokenLineNr |
382 | 3832 |
]. |
141 | 3833 |
node statements:stats. |
3834 |
currentBlock := node home. |
|
3835 |
^ node |
|
382 | 3836 |
|
668 | 3837 |
"Modified: / 31.3.1998 / 22:46:09 / cg" |
141 | 3838 |
! |
3839 |
||
3840 |
blockExpression |
|
3841 |
"parse a blockExpression; return a node-tree, nil or #Error. |
|
3842 |
Not used by ST/X's parser, but added for ST-80 compatibility." |
|
3843 |
||
3844 |
tokenType ~~ $[ ifTrue:[ |
|
3845 |
self syntaxError:'[ expected'. |
|
3846 |
^ #Error. |
|
3847 |
]. |
|
3848 |
^ self block |
|
3849 |
! |
|
3850 |
||
3851 |
blockStatementList |
|
3852 |
"parse a blocks statementlist; return a node-tree, nil or #Error" |
|
3853 |
||
743
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
3854 |
|thisStatement prevStatement firstStatement eMsg| |
141 | 3855 |
|
3856 |
(tokenType == $] ) ifTrue:[^ nil]. |
|
3857 |
thisStatement := self statement. |
|
3858 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
3859 |
firstStatement := thisStatement. |
|
3860 |
[tokenType == $] ] whileFalse:[ |
|
673 | 3861 |
(tokenType == $.) ifFalse:[ |
1169
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3862 |
(tokenType == #EOF) ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
3863 |
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
|
3864 |
^ #Error. |
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3865 |
]. |
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3866 |
|
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3867 |
(tokenType == $) ) ifTrue:[ |
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3868 |
eMsg := 'missing '']'' or bad '')'' in block' |
673 | 3869 |
] ifFalse:[ |
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3870 |
eMsg := 'missing ''.'' between statements (i.e. ''' , tokenType printString , '''-token unexpected)' |
673 | 3871 |
]. |
1169
7204e72c7c3c
better error message with bad parentNesting in a block.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
3872 |
self syntaxError:eMsg position:tokenPosition to:tokenPosition. |
673 | 3873 |
^ #Error |
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3874 |
]. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3875 |
prevStatement := thisStatement. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3876 |
self nextToken. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3877 |
|
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3878 |
tokenType == $] ifTrue:[ |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3879 |
" |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3880 |
*** 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
|
3881 |
*** 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
|
3882 |
*** 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
|
3883 |
*** became annoying |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3884 |
|
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3885 |
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
|
3886 |
" |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3887 |
self markBracketAt:tokenPosition. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3888 |
^ firstStatement |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3889 |
]. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3890 |
thisStatement := self statement. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3891 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
3892 |
prevStatement nextStatement:thisStatement |
141 | 3893 |
]. |
673 | 3894 |
self markBracketAt:tokenPosition. |
141 | 3895 |
^ firstStatement |
743
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
3896 |
|
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
3897 |
"Modified: / 16.7.1998 / 20:38:25 / cg" |
141 | 3898 |
! |
3899 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3900 |
checkForEndOfInput |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3901 |
|what| |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3902 |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3903 |
(tokenType ~~ #EOF) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3904 |
"/ just for the nicer error message |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3905 |
(#(Self Nil True False Super Here) includes:tokenType) ifTrue:[ |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3906 |
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
|
3907 |
position:tokenPosition to:(tokenPosition + tokenName size - 1) |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3908 |
] ifFalse:[ |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3909 |
tokenType isCharacter ifTrue:[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3910 |
what := '''' , tokenType , ''''. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3911 |
] ifFalse:[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3912 |
what := tokenType printString. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3913 |
]. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
3914 |
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
|
3915 |
position:tokenPosition to:source position1Based-1. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3916 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3917 |
^#Error |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3918 |
] |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3919 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
3920 |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3921 |
checkReturnedValues |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3922 |
| returnsSelf returnsBoolean returnsNonBooleanLiteral| |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3923 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3924 |
ignoreWarnings ifTrue:[^ self]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3925 |
returnedValues isNil ifTrue:[^ self]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3926 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3927 |
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
|
3928 |
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
|
3929 |
returnsSelf := returnedValues contains:[:node | node isSelf]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3930 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3931 |
returnsBoolean ifTrue:[ |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3932 |
(returnsNonBooleanLiteral or:[returnsSelf]) ifTrue:[ |
1455 | 3933 |
self |
3934 |
warning:'Possible Error Warning:\\Method returns both boolean and non-boolean values.' withCRs |
|
3935 |
position:1 to:tokenPosition |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3936 |
] |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3937 |
]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3938 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3939 |
"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
|
3940 |
"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
|
3941 |
! |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3942 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3943 |
checkUnusedMethodVars |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3944 |
| unused| |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3945 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3946 |
ignoreWarnings ifFalse:[ |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3947 |
methodVars notNil ifTrue:[ |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3948 |
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
|
3949 |
]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3950 |
unused size > 0 ifTrue:[ |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3951 |
self warnUnused:unused. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3952 |
]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3953 |
]. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3954 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3955 |
"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
|
3956 |
! |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
3957 |
|
1224
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3958 |
parseExceptionOrContextPragma |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3959 |
|pragmaType| |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3960 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3961 |
"/ < resource: has already been parsed. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3962 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3963 |
pragmaType := tokenName. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3964 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3965 |
self nextToken. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3966 |
(tokenType ~~ #Symbol) ifTrue:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3967 |
self parseError:'symbol expected'. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3968 |
^ #Error |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3969 |
]. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3970 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3971 |
((pragmaType = 'exception:' |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3972 |
and:[tokenValue == #'handle' |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3973 |
or:[tokenValue == #'raise' |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3974 |
or:[tokenValue == #'unwind']]]) |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3975 |
or:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3976 |
pragmaType = 'context:' |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3977 |
and:[(tokenValue == #'return')]]) |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3978 |
|
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3979 |
ifTrue:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3980 |
primitiveContextInfo isNil ifTrue:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3981 |
primitiveContextInfo := Set new. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3982 |
]. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3983 |
primitiveContextInfo add:(pragmaType->tokenValue). |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3984 |
] ifFalse:[ |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3985 |
self parseError:'unrecognized exception pragma: ' , tokenValue. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3986 |
]. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3987 |
self nextToken. |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3988 |
! |
b4d80bd993f9
parse ST/C api pragma (as dummy)
Claus Gittinger <cg@exept.de>
parents:
1222
diff
changeset
|
3989 |
|
1006 | 3990 |
parseExpressionWithSelf:anObject notifying:someOne ignoreErrors:ignoreErrors ignoreWarnings:ignoreWarnings inNameSpace:aNameSpaceOrNil |
3991 |
"parse aString as an expression with self set to anObject; |
|
3992 |
Return the parseTree (if ok), nil (for an empty string |
|
3993 |
or comment only ) or #Error (syntactic error). |
|
3994 |
||
3995 |
Errors and warnings are forwarded to someOne (usually some |
|
3996 |
codeView) which can highlight it and show a popup box, |
|
3997 |
iff ignoreErrors/ignoreWarnings is true respectively." |
|
3998 |
||
3999 |
|tree token| |
|
4000 |
||
4001 |
aNameSpaceOrNil notNil ifTrue:[ |
|
4002 |
self currentNameSpace:aNameSpaceOrNil |
|
4003 |
]. |
|
4004 |
self setSelf:anObject. |
|
4005 |
self notifying:someOne. |
|
1365 | 4006 |
self ignoreErrors:ignoreErrors. |
4007 |
self ignoreWarnings:ignoreWarnings. |
|
1006 | 4008 |
token := self nextToken. |
4009 |
(token == $^) ifTrue:[ |
|
4010 |
self nextToken. |
|
4011 |
]. |
|
4012 |
tree := self expression. |
|
4013 |
(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
|
4014 |
"/ tokenType ~~ #EOF ifTrue:[ |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
4015 |
"/ 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
|
4016 |
"/ ]. |
1006 | 4017 |
^ tree |
4018 |
||
4019 |
"Created: / 14.12.1999 / 15:11:37 / cg" |
|
4020 |
! |
|
4021 |
||
1259 | 4022 |
parseExtendedMethodSpec |
4023 |
|pos1 pos2 var| |
|
4024 |
||
4025 |
"/ EXPERIMENTAL |
|
4026 |
false ifTrue:[ |
|
4027 |
(tokenType == #Symbol) ifTrue:[ |
|
4028 |
pos1 := tokenPosition. |
|
4029 |
selector := token asSymbol. |
|
4030 |
self nextToken. |
|
4031 |
self markMethodSelectorFrom:pos1 to:(tokenPosition-1). |
|
4032 |
endOfSelectorPosition := tokenPosition. |
|
4033 |
||
4034 |
tokenType == $( ifTrue:[ |
|
4035 |
self nextToken. |
|
4036 |
[ tokenType ~~ $) ] whileTrue:[ |
|
4037 |
||
4038 |
(tokenType ~~ #Identifier) ifTrue:[^ #Error]. |
|
4039 |
pos2 := tokenPosition+tokenName size-1. |
|
4040 |
self markArgumentIdentifierFrom:tokenPosition to:pos2. |
|
4041 |
var := Variable name:tokenName. |
|
4042 |
methodArgs isNil ifTrue:[ |
|
4043 |
methodArgs := Array with:var. |
|
4044 |
methodArgNames := Array with:tokenName |
|
4045 |
] ifFalse:[ |
|
4046 |
(methodArgNames includes:tokenName) ifTrue:[ |
|
4047 |
self methodArgRedefined:tokenName from:tokenPosition to:pos2 |
|
4048 |
]. |
|
4049 |
methodArgs := methodArgs copyWith:var. |
|
4050 |
methodArgNames := methodArgNames copyWith:tokenName |
|
4051 |
]. |
|
4052 |
self nextToken. |
|
4053 |
]. |
|
4054 |
self nextToken. |
|
4055 |
]. |
|
4056 |
||
4057 |
^ self |
|
4058 |
]. |
|
4059 |
]. |
|
4060 |
^ #Error |
|
4061 |
! |
|
4062 |
||
0 | 4063 |
parseMethod |
19 | 4064 |
"parse a method. |
4065 |
Return the parseTree or #Error. |
|
4066 |
||
4067 |
method ::= methodSpec methodBody |
|
4068 |
" |
|
0 | 4069 |
|
4070 |
|parseTree| |
|
4071 |
||
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4072 |
"/ self nextToken. |
0 | 4073 |
(self parseMethodSpec == #Error) ifTrue:[^ #Error]. |
4074 |
parseTree := self parseMethodBody. |
|
4075 |
(parseTree == #Error) ifFalse:[ |
|
1171
0c43ce981f1b
oops - remove unused vars does not work (yet)
Claus Gittinger <cg@exept.de>
parents:
1169
diff
changeset
|
4076 |
self tree:parseTree |
0 | 4077 |
]. |
1186
014c3db76517
oops - end of input check should not be done when simply evaluating
Claus Gittinger <cg@exept.de>
parents:
1182
diff
changeset
|
4078 |
self checkForEndOfInput. |
0 | 4079 |
^ parseTree |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4080 |
|
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4081 |
"Modified: 20.4.1996 / 20:09:26 / cg" |
0 | 4082 |
! |
4083 |
||
19 | 4084 |
parseMethodBody |
4085 |
"parse a methods body (locals & statements). |
|
4086 |
No more tokens may follow. |
|
4087 |
Return a node-tree, or #Error |
|
4088 |
||
4089 |
methodBody ::= '<' st80Primitive '>' #EOF |
|
883 | 4090 |
| '<' st80Primitive '>' methodBodyVarSpec statementList #EOF |
19 | 4091 |
|
4092 |
" |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4093 |
|stats| |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4094 |
|
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4095 |
stats := self parseMethodBodyOrEmpty. |
19 | 4096 |
(stats == #Error) ifFalse:[ |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4097 |
self checkForEndOfInput. |
19 | 4098 |
]. |
1160 | 4099 |
ignoreWarnings ifFalse:[ |
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4100 |
self checkUnusedMethodVars. |
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4101 |
self checkReturnedValues. |
1160 | 4102 |
]. |
19 | 4103 |
^ stats |
165
213e3f12fc56
better error message when selector is missing
Claus Gittinger <cg@exept.de>
parents:
148
diff
changeset
|
4104 |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4105 |
"Modified: / 17.11.2001 / 10:31:12 / cg" |
19 | 4106 |
! |
4107 |
||
79 | 4108 |
parseMethodBodyOrEmpty |
0 | 4109 |
"parse a methods body (locals & statements); |
19 | 4110 |
return a node-tree, nil or #Error. |
4111 |
empty (or comment only) input is accepted and returns nil. |
|
4112 |
||
4113 |
methodBodyOrNil ::= '<' st80Primitive '>' |
|
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
4114 |
| '<' st80Primitive '>' methodBodyVarSpec statementList |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
4115 |
| <empty> |
19 | 4116 |
" |
0 | 4117 |
|
265 | 4118 |
|stats| |
0 | 4119 |
|
4120 |
(self parseMethodBodyVarSpec == #Error) ifTrue:[^ #Error]. |
|
4121 |
||
4122 |
(tokenType ~~ #EOF) ifTrue:[ |
|
1182
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
4123 |
stats := self statementList |
34aac67e6e72
care for unexpected stuff at the end (in a doit)
Claus Gittinger <cg@exept.de>
parents:
1180
diff
changeset
|
4124 |
]. |
1186
014c3db76517
oops - end of input check should not be done when simply evaluating
Claus Gittinger <cg@exept.de>
parents:
1182
diff
changeset
|
4125 |
"/ (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
|
4126 |
"/ 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
|
4127 |
"/ ^ #Error |
014c3db76517
oops - end of input check should not be done when simply evaluating
Claus Gittinger <cg@exept.de>
parents:
1182
diff
changeset
|
4128 |
"/ ]. |
1231 | 4129 |
(stats notNil |
4130 |
and:[stats ~~ #Error]) ifTrue:[ |
|
1512
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
4131 |
(self isStatementAnUnconditionalReturn:stats last) ifFalse:[ |
1231 | 4132 |
"/ remember a returned self here. |
1262 | 4133 |
self rememberReturnedValue:(self selfNode) |
1231 | 4134 |
]. |
4135 |
]. |
|
1551 | 4136 |
tree notNil ifTrue:[ |
4137 |
tree last nextStatement:stats. |
|
4138 |
^ tree. |
|
4139 |
]. |
|
0 | 4140 |
^ stats |
265 | 4141 |
|
4142 |
"Modified: 27.4.1996 / 16:57:56 / cg" |
|
0 | 4143 |
! |
4144 |
||
19 | 4145 |
parseMethodBodyVarSpec |
265 | 4146 |
"parse a methods local variable specification, handling |
4147 |
possible primitive or resourceSpecs. |
|
4148 |
. |
|
19 | 4149 |
Leave spec of locals in methodLocals as a side effect. |
4150 |
Return #Error or nil. |
|
0 | 4151 |
|
19 | 4152 |
methodBodyVarSpec ::= '|' { IDENTIFIER } '|' |
663 | 4153 |
| <empty> |
19 | 4154 |
" |
0 | 4155 |
|
883 | 4156 |
|var pos pos2 msg| |
0 | 4157 |
|
265 | 4158 |
((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[ |
663 | 4159 |
self parsePrimitiveOrResourceSpecOrEmpty. |
265 | 4160 |
]. |
4161 |
||
0 | 4162 |
(tokenType == $|) ifTrue:[ |
663 | 4163 |
"memorize position for declaration in correction" |
883 | 4164 |
|
663 | 4165 |
localVarDefPosition := tokenPosition. |
4166 |
self nextToken. |
|
4167 |
pos := tokenPosition. |
|
4168 |
[tokenType == #Identifier] whileTrue:[ |
|
883 | 4169 |
pos2 := tokenPosition + tokenName size - 1. |
4170 |
self markLocalIdentifierFrom:tokenPosition to:pos2. |
|
1519 | 4171 |
self checkMethodVariableNameConventionsFor:tokenName. |
663 | 4172 |
var := Variable name:tokenName. |
883 | 4173 |
|
663 | 4174 |
methodVars isNil ifTrue:[ |
4175 |
methodVars := OrderedCollection with:var. |
|
4176 |
methodVarNames := OrderedCollection with:tokenName |
|
4177 |
] ifFalse:[ |
|
4178 |
(methodVarNames includes:tokenName) ifTrue:[ |
|
883 | 4179 |
"/ redefinition |
4180 |
self isSyntaxHighlighter ifTrue:[ |
|
4181 |
self markBadIdentifierFrom:tokenPosition to:pos2. |
|
4182 |
] ifFalse:[ |
|
4183 |
self |
|
4184 |
parseError:'redefinition of ''' , tokenName , ''' in local variables' |
|
4185 |
position:tokenPosition to:pos2. |
|
4186 |
] |
|
663 | 4187 |
] ifFalse:[ |
4188 |
methodVars add:var. |
|
4189 |
methodVarNames add:tokenName |
|
4190 |
] |
|
4191 |
]. |
|
883 | 4192 |
|
663 | 4193 |
methodArgNames notNil ifTrue:[ |
4194 |
(methodArgNames includes:tokenName) ifTrue:[ |
|
883 | 4195 |
self |
4196 |
warning:'local variable ''' , tokenName , ''' hides argument.' |
|
4197 |
position:tokenPosition to:pos2 |
|
663 | 4198 |
] |
4199 |
]. |
|
4200 |
self nextToken. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4201 |
|
1471 | 4202 |
AllowLocalVariableDeclarationWithInitializerExpression == true ifTrue:[ |
4203 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
|
4204 |
self nextToken. |
|
4205 |
"/ Q: should we allow literals only, or arbitrary expressions ? |
|
4206 |
self halt:'unimplemented feature'. |
|
4207 |
] |
|
4208 |
]. |
|
4209 |
AllowDomainVariables == true ifTrue:[ |
|
4210 |
(tokenType == $() ifTrue:[ |
|
4211 |
self variableTypeDeclarationFor:var. |
|
4212 |
]. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4213 |
]. |
663 | 4214 |
pos := tokenPosition |
4215 |
]. |
|
883 | 4216 |
|
663 | 4217 |
(tokenType ~~ $|) ifTrue:[ |
4218 |
(#(True False Self Nil Super ThisContext) includes:tokenType) ifTrue:[ |
|
883 | 4219 |
msg := 'Reserved keyword in local var declaration'. |
4220 |
pos2 := tokenPosition + tokenName size - 1. |
|
4221 |
self markBadIdentifierFrom:tokenPosition to:pos2. |
|
663 | 4222 |
] ifFalse:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
4223 |
pos2 := source position1Based-1. |
663 | 4224 |
msg := 'Identifier or | expected in local var declaration' |
4225 |
]. |
|
883 | 4226 |
self syntaxError:msg position:tokenPosition to:pos2. |
663 | 4227 |
^ #Error |
4228 |
]. |
|
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
4229 |
localVarDefPosition := Array with:localVarDefPosition with:tokenPosition. |
663 | 4230 |
self nextToken |
0 | 4231 |
]. |
984 | 4232 |
|
1363 | 4233 |
allowSqueakExtensions ifTrue:[ |
984 | 4234 |
"/ allow for primitiveSpec after local-var decl. |
4235 |
||
4236 |
((tokenType == #BinaryOperator) and:[tokenName = '<']) ifTrue:[ |
|
4237 |
self parsePrimitiveOrResourceSpecOrEmpty. |
|
4238 |
] |
|
4239 |
]. |
|
4240 |
||
0 | 4241 |
^ nil |
139
65eaf1a009f5
warn if method local hides method arg
Claus Gittinger <cg@exept.de>
parents:
135
diff
changeset
|
4242 |
|
663 | 4243 |
"Modified: / 31.3.1998 / 17:30:33 / cg" |
0 | 4244 |
! |
4245 |
||
141 | 4246 |
parseMethodSpec |
4247 |
"parse a methods selector & arg specification; |
|
4248 |
Set selector and methodArgs in the receiver as a side effect. |
|
4249 |
Return the receiver or #Error. |
|
4250 |
||
4251 |
methodSpec ::= { KEYWORD IDENTIFIER } |
|
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4252 |
| binaryOperator IDENTIFIER |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4253 |
| IDENTIFIER |
141 | 4254 |
" |
4255 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4256 |
|arg pos2| |
141 | 4257 |
|
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4258 |
tokenType isNil ifTrue:[ |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4259 |
self nextToken. |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4260 |
]. |
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4261 |
|
141 | 4262 |
(tokenType == #Keyword) ifTrue:[ |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4263 |
selector := ''. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4264 |
[tokenType == #Keyword] whileTrue:[ |
663 | 4265 |
self markMethodSelectorFrom:tokenPosition to:(tokenPosition+tokenName size-1). |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4266 |
selector := selector , tokenName. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4267 |
self nextToken. |
883 | 4268 |
|
1259 | 4269 |
(tokenType ~~ #Identifier) ifTrue:[ |
4270 |
"/ ^ #Error]. |
|
4271 |
^ self identifierExpectedIn:'method-arg declaration' |
|
4272 |
]. |
|
4273 |
||
883 | 4274 |
pos2 := tokenPosition+tokenName size-1. |
4275 |
self markArgumentIdentifierFrom:tokenPosition to:pos2. |
|
1519 | 4276 |
self checkMethodArgumentNameConventionsFor:tokenName. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4277 |
arg := Variable name:tokenName. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4278 |
methodArgs isNil ifTrue:[ |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4279 |
methodArgs := Array with:arg. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4280 |
methodArgNames := Array with:tokenName |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4281 |
] ifFalse:[ |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4282 |
(methodArgNames includes:tokenName) ifTrue:[ |
1259 | 4283 |
self methodArgRedefined:tokenName from:tokenPosition to:pos2 |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4284 |
]. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4285 |
methodArgs := methodArgs copyWith:arg. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4286 |
methodArgNames := methodArgNames copyWith:tokenName |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4287 |
]. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4288 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4289 |
"/ ((tokenType == #BinaryOperator) and:[token = '#']) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4290 |
"/ self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4291 |
"/ arg domain:nil. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4292 |
"/ ]. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4293 |
]. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4294 |
selector := selector asSymbol. |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
4295 |
endOfSelectorPosition := tokenPosition. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4296 |
^ self |
141 | 4297 |
]. |
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
4298 |
|
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
4299 |
(self isValidUnarySelector:tokenType) ifTrue:[ |
663 | 4300 |
self markMethodSelectorFrom:tokenPosition to:(tokenPosition+tokenName size-1). |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4301 |
selector := tokenName asSymbol. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4302 |
self nextToken. |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
4303 |
endOfSelectorPosition := tokenPosition. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4304 |
^ self |
141 | 4305 |
]. |
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
4306 |
|
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
4307 |
"/ 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
|
4308 |
tokenType == $| ifTrue:[ |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4309 |
tokenType := #BinaryOperator. |
1103
b75a71996388
ensure that token follows tomeName & tokenValue
Claus Gittinger <cg@exept.de>
parents:
1100
diff
changeset
|
4310 |
token := tokenName := '|' |
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
4311 |
]. |
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
4312 |
|
141 | 4313 |
(tokenType == #BinaryOperator) ifTrue:[ |
663 | 4314 |
self markMethodSelectorFrom:tokenPosition to:(tokenPosition+tokenName size-1). |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4315 |
selector := tokenName asSymbol. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4316 |
self nextToken. |
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4317 |
(tokenType ~~ #Identifier) ifTrue:[^ #Error]. |
663 | 4318 |
self markArgumentIdentifierFrom:tokenPosition to:(tokenPosition+tokenName size-1). |
1519 | 4319 |
self checkMethodArgumentNameConventionsFor:tokenName. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4320 |
arg := Variable name:tokenName. |
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 |
methodArgs := Array with:arg. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4323 |
methodArgNames := Array with:tokenName. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4324 |
|
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4325 |
self nextToken. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4326 |
"/ ((tokenType == #BinaryOperator) and:[token = '#']) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4327 |
"/ self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4328 |
"/ arg domain:nil. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4329 |
"/ ]. |
878
f9c8d2544909
added declare-as (local, global or workspace-war)
Claus Gittinger <cg@exept.de>
parents:
877
diff
changeset
|
4330 |
endOfSelectorPosition := tokenPosition. |
660
f68ddffc6921
support for syntaxHighlighting
Claus Gittinger <cg@exept.de>
parents:
647
diff
changeset
|
4331 |
^ self |
141 | 4332 |
]. |
461
1d24cc165fac
oops - did not allow | as method-selector
Claus Gittinger <cg@exept.de>
parents:
457
diff
changeset
|
4333 |
|
1259 | 4334 |
^ self parseExtendedMethodSpec |
255
13a059f6569d
no need to send nextToken when parsing a method
Claus Gittinger <cg@exept.de>
parents:
229
diff
changeset
|
4335 |
|
663 | 4336 |
"Modified: / 31.3.1998 / 17:31:59 / cg" |
141 | 4337 |
! |
4338 |
||
713 | 4339 |
statement |
4340 |
"parse a statement; return a node-tree or #Error. |
|
4341 |
||
4342 |
statement ::= '^' expression |
|
4343 |
| PRIMITIVECODE |
|
4344 |
| expression |
|
4345 |
" |
|
4346 |
||
1276
f7f6e0c1aff9
code could be wrong in a primitive node
Claus Gittinger <cg@exept.de>
parents:
1275
diff
changeset
|
4347 |
|expr node lnr code| |
713 | 4348 |
|
4349 |
(tokenType == $^) ifTrue:[ |
|
837 | 4350 |
self markReturnAt:tokenPosition. |
713 | 4351 |
lnr := tokenLineNr. |
4352 |
self nextToken. |
|
4353 |
expr := self expression. |
|
4354 |
(expr == #Error) ifTrue:[^ #Error]. |
|
4355 |
node := ReturnNode expression:expr. |
|
4356 |
node home:self blockHome:currentBlock. |
|
4357 |
(lineNumberInfo == #full) ifTrue:[node lineNumber:lnr]. |
|
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4358 |
|
1231 | 4359 |
self rememberReturnedValue:expr. |
713 | 4360 |
^ node |
4361 |
]. |
|
4362 |
||
4363 |
(tokenType == #Primitive) ifTrue:[ |
|
1276
f7f6e0c1aff9
code could be wrong in a primitive node
Claus Gittinger <cg@exept.de>
parents:
1275
diff
changeset
|
4364 |
code := tokenValue. |
713 | 4365 |
self nextToken. |
1276
f7f6e0c1aff9
code could be wrong in a primitive node
Claus Gittinger <cg@exept.de>
parents:
1275
diff
changeset
|
4366 |
node := PrimitiveNode code:code. |
713 | 4367 |
node isOptional ifFalse:[ |
4368 |
hasNonOptionalPrimitiveCode := true |
|
4369 |
]. |
|
4370 |
hasPrimitiveCode := true. |
|
4371 |
^ node |
|
4372 |
]. |
|
4373 |
||
4374 |
(tokenType == #EOF) ifTrue:[ |
|
733
6859b56d5bd2
better error message for missing ']' at end of block.
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
4375 |
currentBlock notNil ifTrue:[ |
6859b56d5bd2
better error message for missing ']' at end of block.
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
4376 |
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
|
4377 |
] ifFalse:[ |
6859b56d5bd2
better error message for missing ']' at end of block.
Claus Gittinger <cg@exept.de>
parents:
732
diff
changeset
|
4378 |
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
|
4379 |
]. |
713 | 4380 |
^ #Error |
4381 |
]. |
|
4382 |
||
984 | 4383 |
(tokenType == $.) ifTrue:[ |
1363 | 4384 |
allowSqueakExtensions == true ifTrue:[ |
984 | 4385 |
"/ allow empty statement |
4386 |
^ StatementNode expression:nil. |
|
4387 |
]. |
|
4388 |
]. |
|
4389 |
||
713 | 4390 |
expr := self expression. |
4391 |
(expr == #Error) ifTrue:[^ #Error]. |
|
4392 |
||
4393 |
"/ classToCompileFor notNil ifTrue:[ |
|
4394 |
"/ currentBlock isNil ifTrue:[ |
|
4395 |
"/ expr isPrimary ifTrue:[ |
|
4396 |
"/ self warning:'useless computation - missing ^ ?' |
|
4397 |
"/ ] |
|
4398 |
"/ ] |
|
4399 |
"/ ]. |
|
4400 |
||
4401 |
node := StatementNode expression:expr. |
|
4402 |
(lineNumberInfo == #full) ifTrue:[node lineNumber:lnr]. |
|
4403 |
^ node |
|
4404 |
||
1222
f3f602267070
check if returning both boolean / non-boolean
Claus Gittinger <cg@exept.de>
parents:
1221
diff
changeset
|
4405 |
"Modified: / 17.11.2001 / 10:22:33 / cg" |
713 | 4406 |
! |
4407 |
||
4408 |
statementList |
|
4409 |
"parse a statementlist; return a node-tree, nil or #Error. |
|
4410 |
Statements must be separated by periods. |
|
4411 |
||
4412 |
statementList ::= <statement> |
|
988 | 4413 |
| <statementList> . <statement> |
713 | 4414 |
" |
4415 |
||
4416 |
|thisStatement prevStatement firstStatement correctIt periodPos |
|
4417 |
prevExpr| |
|
4418 |
||
4419 |
thisStatement := self statement. |
|
4420 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
4421 |
firstStatement := thisStatement. |
|
4422 |
[tokenType == $.] whileTrue:[ |
|
988 | 4423 |
prevExpr := thisStatement expression. |
4424 |
(prevExpr notNil |
|
4425 |
and:[prevExpr isMessage |
|
4426 |
and:[thisStatement isReturnNode not]]) ifTrue:[ |
|
4427 |
(#(#'=' #'==') includes:prevExpr selector) ifTrue:[ |
|
1487 | 4428 |
self warning:'useless computation - mistyped assignment (i.e. did you mean '':='') ?' position:prevExpr selectorPosition |
988 | 4429 |
]. |
4430 |
]. |
|
4431 |
||
4432 |
periodPos := tokenPosition. |
|
4433 |
self nextToken. |
|
4434 |
(tokenType == $]) ifTrue:[ |
|
4435 |
currentBlock isNil ifTrue:[ |
|
4436 |
self parseError:'block nesting error'. |
|
4437 |
errorFlag := true |
|
713 | 4438 |
" |
988 | 4439 |
*** I had a warning here (since it was not defined |
4440 |
*** in the blue-book; but PD-code contains a lot of |
|
4441 |
*** code with periods at the end so that the warnings |
|
4442 |
*** became annoying |
|
4443 |
||
4444 |
] ifFalse:[ |
|
4445 |
self warning:'period after last statement' position:periodPos |
|
713 | 4446 |
" |
988 | 4447 |
]. |
4448 |
^ firstStatement |
|
4449 |
]. |
|
4450 |
(tokenType == #EOF) ifTrue:[ |
|
4451 |
currentBlock notNil ifTrue:[ |
|
4452 |
self parseError:'block nesting error (expected '']'')'. |
|
4453 |
errorFlag := true |
|
713 | 4454 |
" |
988 | 4455 |
*** I had a warning here (since it was not defined |
4456 |
*** in the blue-book; but PD-code contains a lot of |
|
4457 |
*** code with periods at the end so that the warnings |
|
4458 |
*** became annoying |
|
4459 |
||
4460 |
] ifFalse:[ |
|
4461 |
self warning:'period after last statement' position:periodPos |
|
713 | 4462 |
" |
988 | 4463 |
]. |
4464 |
^ firstStatement |
|
4465 |
]. |
|
4466 |
||
4467 |
prevStatement := thisStatement. |
|
4468 |
prevStatement isReturnNode ifTrue:[ |
|
4469 |
self warning:'statements after return' position:tokenPosition |
|
4470 |
]. |
|
713 | 4471 |
" |
988 | 4472 |
periodPos := tokenPosition. |
4473 |
self nextToken. |
|
713 | 4474 |
" |
4475 |
||
988 | 4476 |
((tokenType == $]) or:[tokenType == #EOF]) ifTrue:[ |
4477 |
(currentBlock isNil and:[tokenType == $]]) ifTrue:[ |
|
4478 |
self parseError:'block nesting error'. |
|
4479 |
errorFlag := true |
|
4480 |
] ifFalse:[ |
|
4481 |
correctIt := self correctableError:'period after last statement in block' |
|
4482 |
position:periodPos to:(periodPos + 1). |
|
4483 |
correctIt ifTrue:[ |
|
4484 |
(self correctByDeleting == #Error) ifTrue:[ |
|
4485 |
errorFlag := true |
|
4486 |
] |
|
4487 |
] |
|
4488 |
]. |
|
4489 |
^ firstStatement |
|
4490 |
]. |
|
4491 |
thisStatement := self statement. |
|
4492 |
(thisStatement == #Error) ifTrue:[^ #Error]. |
|
4493 |
prevStatement nextStatement:thisStatement |
|
713 | 4494 |
]. |
4495 |
^ firstStatement |
|
4496 |
||
4497 |
"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
|
4498 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4499 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4500 |
variableTypeDeclarationFor:aVariable |
1471 | 4501 |
"experimental support for Domain variables (constraint programming support): |
4502 |
a variable-declaration of the form |
|
4503 |
|var (domain) ... | |
|
4504 |
declares var as a domainVariable. |
|
4505 |
Valid domains are: |
|
4506 |
min %% max - integer range domain |
|
4507 |
Bool - boolean domain |
|
4508 |
Nat - positive integer domain |
|
4509 |
Int - integer domain |
|
4510 |
#sym1 ... #sym2 - enumerated symbolic domain |
|
4511 |
" |
|
4512 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4513 |
|min max domain enumValues| |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4514 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4515 |
(tokenType == $() ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4516 |
self syntaxError:'''('' expected' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4517 |
^ #Error |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4518 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4519 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4520 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4521 |
(tokenType == #Integer) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4522 |
min := token. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4523 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4524 |
((tokenType == #BinaryOperator) and:[token = '%%']) ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4525 |
self syntaxError:'''%%'' expected' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4526 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4527 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4528 |
(tokenType == #Integer) ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4529 |
self syntaxError:'Integer (upper bound) expected' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4530 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4531 |
max := token. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4532 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4533 |
domain := IntegerDomain min:min max:max. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4534 |
] ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4535 |
((tokenType == #Identifier) and:[token first isUppercase]) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4536 |
token = 'Bool' ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4537 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4538 |
domain := BooleanDomain new. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4539 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4540 |
token = 'Nat' ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4541 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4542 |
domain := IntegerDomain min:0 max:(SmallInteger maxVal). |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4543 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4544 |
token = 'Int' ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4545 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4546 |
domain := IntegerDomain min:(SmallInteger minVal) max:(SmallInteger maxVal). |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4547 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4548 |
] ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4549 |
((tokenType == #Symbol) or:[(tokenType == #Identifier)]) ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4550 |
enumValues := OrderedCollection new. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4551 |
[((tokenType == #Symbol) or:[(tokenType == #Identifier)])] whileTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4552 |
enumValues add:token. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4553 |
self nextToken. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4554 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4555 |
domain := EnumeratedDomain new values:enumValues. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4556 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4557 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4558 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4559 |
domain isNil ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4560 |
self syntaxError:'invalid domain' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4561 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4562 |
aVariable domain:domain. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4563 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4564 |
(tokenType == $)) ifFalse:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4565 |
self syntaxError:''')'' expected' position:tokenPosition. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4566 |
^ #Error |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4567 |
]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
4568 |
self nextToken. |
713 | 4569 |
! ! |
4570 |
||
4571 |
!Parser methodsFor:'parsing-expressions'! |
|
4572 |
||
4573 |
array |
|
4574 |
|arr elements elem pos1| |
|
4575 |
||
4576 |
pos1 := tokenPosition. |
|
4577 |
elements := OrderedCollection new:20. |
|
4578 |
[tokenType ~~ $) ] whileTrue:[ |
|
1165
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
4579 |
elem := self arrayConstant. |
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
4580 |
|
1062 | 4581 |
"/ (elem == #Error) ifTrue:[ |
4582 |
"/ (tokenType == #EOF) ifTrue:[ |
|
4583 |
"/ self syntaxError:'unterminated array-constant; '')'' expected' |
|
4584 |
"/ position:pos1 to:tokenPosition |
|
4585 |
"/ ]. |
|
4586 |
"/ ^ #Error |
|
4587 |
"/ ]. |
|
713 | 4588 |
elem isSymbol ifTrue:[ |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
4589 |
self markSymbolFrom:tokenPosition to:(source position1Based-1). |
713 | 4590 |
]. |
4591 |
elements add:elem. |
|
4592 |
self nextToken |
|
4593 |
]. |
|
4594 |
arr := Array withAll:elements. |
|
4595 |
||
4596 |
(ArraysAreImmutable and:[ImmutableArray notNil]) ifTrue:[ |
|
4597 |
arr changeClassTo:ImmutableArray. |
|
4598 |
]. |
|
4599 |
^ arr |
|
4600 |
||
4601 |
"Modified: / 14.4.1998 / 17:03:29 / cg" |
|
4602 |
! |
|
4603 |
||
4604 |
arrayConstant |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4605 |
|val| |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4606 |
|
713 | 4607 |
(tokenType == #Nil) ifTrue:[ |
4608 |
^ nil |
|
4609 |
]. |
|
4610 |
((tokenType == #Integer) |
|
4611 |
or:[tokenType == #Float]) ifTrue:[ |
|
4612 |
^ tokenValue |
|
4613 |
]. |
|
4614 |
((tokenType == #String) |
|
4615 |
or:[tokenType == #Character]) ifTrue:[ |
|
4616 |
^ tokenValue |
|
4617 |
]. |
|
4618 |
(tokenType == #True) ifTrue:[ |
|
4619 |
^ true |
|
4620 |
]. |
|
4621 |
(tokenType == #False) ifTrue:[ |
|
4622 |
^ false |
|
4623 |
]. |
|
4624 |
(tokenType == #Error) ifTrue:[ |
|
1062 | 4625 |
^ ParseErrorSignal raise. |
713 | 4626 |
]. |
4627 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
4628 |
^ tokenName asSymbol |
|
4629 |
]. |
|
4630 |
||
4631 |
"/ some more special symbol consts ... |
|
4632 |
(tokenType == $| ) ifTrue:[ |
|
4633 |
^ #| |
|
4634 |
]. |
|
4635 |
(tokenType == #Self ) ifTrue:[ |
|
4636 |
^ #'self' |
|
4637 |
]. |
|
4638 |
(tokenType == #Super ) ifTrue:[ |
|
4639 |
^ #'super' |
|
4640 |
]. |
|
4641 |
(tokenType == #Here ) ifTrue:[ |
|
4642 |
^ #'here' |
|
4643 |
]. |
|
4644 |
(tokenType == #ThisContext ) ifTrue:[ |
|
4645 |
^ #'thisContext' |
|
4646 |
]. |
|
4647 |
||
4648 |
((tokenType == #Keyword) |
|
4649 |
or:[tokenType == #Identifier]) ifTrue:[ |
|
4650 |
^ tokenName asSymbol |
|
4651 |
]. |
|
4652 |
((tokenType == $() |
|
4653 |
or:[tokenType == #HashLeftParen]) ifTrue:[ |
|
4654 |
self nextToken. |
|
4655 |
^ self array |
|
4656 |
]. |
|
4657 |
((tokenType == $[) |
|
4658 |
or:[tokenType == #HashLeftBrack]) ifTrue:[ |
|
4659 |
self nextToken. |
|
4660 |
^ self byteArray |
|
4661 |
]. |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4662 |
(tokenType == #HashLeftBrace) ifTrue:[ |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4663 |
val := self qualifiedName. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4664 |
val := QualifiedName for:val name. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4665 |
^ val |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
4666 |
]. |
713 | 4667 |
(tokenType == #Symbol) ifTrue:[ |
1066
ba626f00f709
remember symbols used in arrayConstant
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
4668 |
parseForCode ifFalse:[ |
ba626f00f709
remember symbols used in arrayConstant
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
4669 |
self rememberSymbolUsed:tokenValue. |
ba626f00f709
remember symbols used in arrayConstant
Claus Gittinger <cg@exept.de>
parents:
1065
diff
changeset
|
4670 |
]. |
713 | 4671 |
^ tokenValue |
4672 |
]. |
|
4673 |
(tokenType == #EOF) ifTrue:[ |
|
4674 |
"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
|
4675 |
self syntaxError:'error in array-constant; EOF unexpected'. |
1062 | 4676 |
^ ParseErrorSignal raise. |
713 | 4677 |
]. |
4678 |
self syntaxError:('error in array-constant; ' |
|
4679 |
, tokenType printString |
|
4680 |
, ' unexpected'). |
|
1062 | 4681 |
^ ParseErrorSignal raise. |
713 | 4682 |
|
4683 |
"Modified: / 14.4.1998 / 18:22:54 / cg" |
|
4684 |
! |
|
4685 |
||
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4686 |
arrayIndexingExpression |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4687 |
"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
|
4688 |
foo[idx] is syntactic sugar for foo matrixAt:x |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4689 |
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
|
4690 |
|
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4691 |
|receiver argList selectorStream valNode| |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4692 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4693 |
receiver := self functionCallExpression. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4694 |
tokenType == $[ ifFalse:[^ receiver]. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4695 |
AllowArrayIndexSyntaxExtension == true ifFalse:[^ receiver.]. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4696 |
(receiver == #Error) ifTrue:[^ #Error]. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4697 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4698 |
selectorStream := WriteStream on: (String new: 32). |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4699 |
argList := OrderedCollection new. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4700 |
|
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4701 |
[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4702 |
[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4703 |
|indexNode| |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4704 |
|
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4705 |
self nextToken. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4706 |
indexNode := self primary. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4707 |
argList isEmpty ifTrue:[selectorStream nextPutAll:'_']. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4708 |
selectorStream nextPutAll:'at:'. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4709 |
argList add: indexNode. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4710 |
(tokenType == #BinaryOperator ) and:[ token = ','] |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4711 |
] whileTrue. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4712 |
|
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4713 |
tokenType == $] ifFalse:[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4714 |
self parseError:''']'' expected'. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4715 |
^ #Error |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4716 |
]. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4717 |
self nextToken. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4718 |
|
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4719 |
tokenType == $[ ifTrue:[ |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4720 |
receiver := MessageNode |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4721 |
receiver:receiver |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4722 |
selector:(selectorStream contents) |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4723 |
args:argList. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4724 |
selectorStream := WriteStream on: (String new: 32). |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4725 |
]. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4726 |
tokenType == $[ |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4727 |
] whileTrue. |
1411 | 4728 |
|
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4729 |
tokenType == #':=' ifTrue:[ |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4730 |
self nextToken. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4731 |
selectorStream nextPutAll:'put:'. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4732 |
valNode := self expression. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4733 |
valNode == #Error ifTrue:[ |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4734 |
^ valNode |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4735 |
]. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4736 |
"/ 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
|
4737 |
"/ (valNode isKindOf: BlockNode) ifFalse:[ |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4738 |
"/ valNode _ BlockNode new |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4739 |
"/ arguments: #() |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4740 |
"/ statements: (OrderedCollection with: valNode) |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4741 |
"/ returns: false |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4742 |
"/ from: encoder. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4743 |
"/ ]. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4744 |
argList add: valNode |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4745 |
]. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4746 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4747 |
^ MessageNode |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4748 |
receiver:receiver |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4749 |
selector:selectorStream contents |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4750 |
args:argList. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4751 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4752 |
" |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4753 |
AllowArrayIndexSyntaxExtension := true. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4754 |
AllowArrayIndexSyntaxExtension := false. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4755 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4756 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4757 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4758 |
|foo| |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4759 |
|
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4760 |
foo := Array new:10 withAll:2. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4761 |
1 + foo[1]. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4762 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4763 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4764 |
|foo| |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4765 |
|
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4766 |
foo := Array new:10. |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4767 |
foo[1] := 'hello'. |
1412
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4768 |
foo[2]. |
af3ec9f24a38
array indexing extension (experimental)
Claus Gittinger <cg@exept.de>
parents:
1411
diff
changeset
|
4769 |
foo[1]. |
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4770 |
" |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4771 |
! |
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
4772 |
|
713 | 4773 |
binaryExpression |
4774 |
"parse a binary-expression; return a node-tree, nil or #Error" |
|
4775 |
||
1328 | 4776 |
|receiver| |
713 | 4777 |
|
4778 |
receiver := self unaryExpression. |
|
4779 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
1328 | 4780 |
^ self binaryExpressionFor:receiver |
4781 |
! |
|
4782 |
||
4783 |
binaryExpressionFor:receiverArg |
|
4784 |
"parse a binary-expression; return a node-tree, nil or #Error" |
|
4785 |
||
1547 | 4786 |
|receiver expr arg sel pos1 pos2 lno note| |
1328 | 4787 |
|
4788 |
receiver := receiverArg. |
|
4789 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
713 | 4790 |
|
4791 |
"special kludge: since Scanner cannot know if -digit is a binary |
|
4792 |
expression or a negative constant, handle cases here" |
|
4793 |
||
4794 |
[(tokenType == #BinaryOperator) |
|
4795 |
or:[(tokenType == $|) |
|
4796 |
or:[((tokenType == #Integer) or:[tokenType == #Float]) |
|
4797 |
and:[tokenValue < 0]]] |
|
4798 |
] whileTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4799 |
"/ 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
|
4800 |
inFunctionCallArgument == true ifTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4801 |
((tokenType == #BinaryOperator) and:[tokenName = ',']) ifTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4802 |
^ receiver |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4803 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4804 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4805 |
|
1547 | 4806 |
pos1 := tokenPosition. |
713 | 4807 |
lno := tokenLineNr. |
4808 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4809 |
"/ kludge alarm: bar and minus are not scanned as binop |
713 | 4810 |
(tokenType == $|) ifTrue:[ |
4811 |
sel := '|'. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
4812 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:tokenPosition. |
713 | 4813 |
self nextToken |
4814 |
] ifFalse:[ |
|
4815 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
4816 |
sel := tokenName. |
1022 | 4817 |
sel := self selectorCheck:sel for:receiver position:tokenPosition to:(tokenPosition + tokenName size - 1). |
713 | 4818 |
self nextToken |
4819 |
] ifFalse:[ |
|
4820 |
sel := '-'. |
|
1103
b75a71996388
ensure that token follows tomeName & tokenValue
Claus Gittinger <cg@exept.de>
parents:
1100
diff
changeset
|
4821 |
token := tokenValue := tokenValue negated |
713 | 4822 |
] |
4823 |
]. |
|
1547 | 4824 |
|
4825 |
pos2 := pos1 + sel size - 1. |
|
4826 |
self markSelector:sel from:pos1 to:pos2 receiverNode:receiver. |
|
713 | 4827 |
|
4828 |
arg := self unaryExpression. |
|
4829 |
(arg == #Error) ifTrue:[^ #Error]. |
|
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4830 |
|
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4831 |
expr := BinaryNode receiver:receiver selector:sel arg:arg fold:foldConstants. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4832 |
expr isErrorNode ifTrue:[ |
1547 | 4833 |
self parseError:(expr errorString) position:pos1 to:tokenPosition. |
713 | 4834 |
errorFlag := false. "ok, user wants it - so he'll get it" |
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4835 |
expr := BinaryNode receiver:receiver selector:sel arg:arg fold:nil. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4836 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4837 |
note := self plausibilityCheck:expr. |
903
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
4838 |
note notNil ifTrue:[ |
1547 | 4839 |
self warning:note position:pos1 to:pos2 |
903
038c2c447dcf
always do plausibility checks
Claus Gittinger <cg@exept.de>
parents:
897
diff
changeset
|
4840 |
]. |
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4841 |
expr lineNumber:lno. |
1547 | 4842 |
expr selectorPosition:pos1. |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4843 |
parseForCode ifFalse:[ |
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4844 |
self rememberSelectorUsed:sel receiver:receiver |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4845 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4846 |
receiver := expr. "/ for next message |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
4847 |
|
713 | 4848 |
]. |
4849 |
^ receiver |
|
4850 |
||
4851 |
"Modified: / 9.1.1998 / 19:05:18 / stefan" |
|
1022 | 4852 |
"Modified: / 19.1.2000 / 16:22:04 / cg" |
713 | 4853 |
! |
4854 |
||
4855 |
byteArray |
|
4856 |
"started with ST-80 R4 - allow byteArray constants as #[ ... ]" |
|
4857 |
||
4858 |
|bytes index limit newArray elem pos1 pos2| |
|
4859 |
||
4860 |
pos1 := tokenPosition. |
|
4861 |
bytes := ByteArray uninitializedNew:5000. |
|
4862 |
index := 0. limit := 5000. |
|
4863 |
[tokenType ~~ $] ] whileTrue:[ |
|
4864 |
pos2 := tokenPosition. |
|
4865 |
" |
|
4866 |
this is not good programming style, but speeds up |
|
4867 |
reading of huge byte arrays (i.e. stored Images ...) |
|
4868 |
" |
|
4869 |
(tokenType == #Integer) ifTrue:[ |
|
4870 |
elem := tokenValue |
|
4871 |
] ifFalse:[ |
|
4872 |
elem := self arrayConstant. |
|
4873 |
(elem == #Error) ifTrue:[ |
|
4874 |
(tokenType == #EOF) ifTrue:[ |
|
4875 |
self syntaxError:'unterminated bytearray-constant; '']'' expected' |
|
4876 |
position:pos1 to:tokenPosition |
|
4877 |
]. |
|
4878 |
^ #Error |
|
4879 |
]. |
|
4880 |
]. |
|
4881 |
((elem isMemberOf:SmallInteger) and:[elem between:0 and:255]) ifTrue:[ |
|
4882 |
index := index + 1. |
|
4883 |
bytes at:index put:elem. |
|
4884 |
index == limit ifTrue:[ |
|
4885 |
newArray := ByteArray uninitializedNew:(limit * 2). |
|
4886 |
newArray replaceFrom:1 to:limit with:bytes startingAt:1. |
|
4887 |
limit := limit * 2. |
|
4888 |
bytes := newArray |
|
4889 |
]. |
|
4890 |
] ifFalse:[ |
|
4891 |
self parseError:'invalid ByteArray element' position:pos2 to:tokenPosition - 1 |
|
4892 |
]. |
|
4893 |
self nextToken. |
|
4894 |
]. |
|
4895 |
newArray := ByteArray uninitializedNew:index. |
|
4896 |
newArray replaceFrom:1 to:index with:bytes startingAt:1. |
|
4897 |
^ newArray |
|
4898 |
! |
|
4899 |
||
4900 |
degeneratedKeywordExpressionForSelector |
|
1406 | 4901 |
"parse a keyword-expression without receiver - for the selector only. |
4902 |
Return the selector or nil (if it cannot be determined). |
|
4903 |
This is not used in normal parsing, but instead to extract the selector from a code fragment. |
|
4904 |
(for example, the system browsers 'implementors'-function uses this to extract a selector from |
|
4905 |
the selection)" |
|
713 | 4906 |
|
4907 |
|sel arg rec| |
|
4908 |
||
4909 |
(tokenType == #Keyword) ifTrue:[ |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4910 |
sel := tokenName. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4911 |
self nextToken. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4912 |
arg := self binaryExpression. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4913 |
(arg == #Error) ifTrue:[^ sel]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4914 |
[tokenType == #Keyword] whileTrue:[ |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4915 |
sel := sel , tokenName. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4916 |
self nextToken. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4917 |
arg := self binaryExpression. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4918 |
(arg == #Error) ifTrue:[^ sel]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4919 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4920 |
^ sel |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4921 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
4922 |
|
1406 | 4923 |
(rec := self arrayIndexingExpression) == #Error ifTrue:[ ^ nil]. |
4924 |
sel := self degeneratedKeywordExpressionForSelector. |
|
4925 |
sel notNil ifTrue:[ ^ sel]. |
|
4926 |
||
1407 | 4927 |
rec isAssignment ifTrue:[ |
4928 |
rec := rec expression |
|
4929 |
]. |
|
1406 | 4930 |
rec isMessage ifTrue:[ |
4931 |
^ rec selector |
|
4932 |
]. |
|
4933 |
^ nil |
|
1524 | 4934 |
|
4935 |
" |
|
4936 |
(self new source:'hello:world:') nextToken; degeneratedKeywordExpressionForSelector |
|
4937 |
(self new source:'hello:world') nextToken; degeneratedKeywordExpressionForSelector |
|
4938 |
(self new source:'hello:') nextToken; degeneratedKeywordExpressionForSelector |
|
4939 |
" |
|
713 | 4940 |
! |
4941 |
||
4942 |
expression |
|
4943 |
"parse a cascade-expression; return a node-tree, nil or #Error. |
|
4944 |
||
4945 |
expression ::= keywordExpression |
|
4946 |
| keywordExpression cascade |
|
4947 |
||
4948 |
cascade ::= ';' expressionSendPart |
|
4949 |
| cascade ';' expressionSendPart |
|
4950 |
||
4951 |
expressionSendPart ::= { KEYWORD binaryExpression } |
|
4952 |
| BINARYOPERATOR unaryExpression |
|
4953 |
| IDENTIFIER |
|
4954 |
" |
|
4955 |
||
864 | 4956 |
|receiver arg sel args pos pos2 lno tokenEnd realReceiver positions| |
713 | 4957 |
|
4958 |
pos := tokenPosition. |
|
4959 |
receiver := self keywordExpression. |
|
4960 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
4961 |
(tokenType == $;) ifTrue:[ |
|
743
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4962 |
receiver isMessage ifFalse:[ |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4963 |
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
|
4964 |
position:pos to:tokenPosition. |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4965 |
realReceiver := receiver. "/ only to allow continuing. |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4966 |
] ifTrue:[ |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4967 |
realReceiver := receiver receiver. |
3ced4791090c
changes for cascades to super/here semantics.
Claus Gittinger <cg@exept.de>
parents:
739
diff
changeset
|
4968 |
]. |
713 | 4969 |
[tokenType == $;] whileTrue:[ |
4970 |
self nextToken. |
|
4971 |
(tokenType == #Identifier) ifTrue:[ |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4972 |
tokenEnd := tokenPosition + tokenName size - 1. |
864 | 4973 |
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
|
4974 |
sel := tokenName. |
1022 | 4975 |
sel := self selectorCheck:tokenName for:realReceiver position:tokenPosition to:tokenEnd. |
713 | 4976 |
receiver := CascadeNode receiver:receiver selector:sel. |
4977 |
receiver lineNumber:tokenLineNr. |
|
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4978 |
parseForCode ifFalse:[ |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4979 |
self rememberSelectorUsed:sel |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4980 |
]. |
713 | 4981 |
self nextToken. |
4982 |
] ifFalse:[ |
|
4983 |
(tokenType == #BinaryOperator) ifTrue:[ |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4984 |
tokenEnd := tokenPosition + tokenName size - 1. |
864 | 4985 |
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
|
4986 |
sel := tokenName. |
1022 | 4987 |
sel := self selectorCheck:tokenName for:realReceiver position:tokenPosition to:tokenEnd. |
713 | 4988 |
lno := tokenLineNr. |
4989 |
self nextToken. |
|
4990 |
arg := self unaryExpression. |
|
4991 |
(arg == #Error) ifTrue:[^ #Error]. |
|
4992 |
receiver := CascadeNode receiver:receiver selector:sel arg:arg. |
|
4993 |
receiver lineNumber:lno. |
|
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4994 |
parseForCode ifFalse:[ |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4995 |
self rememberSelectorUsed:sel |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
4996 |
]. |
713 | 4997 |
] ifFalse:[ |
4998 |
(tokenType == #Keyword) ifTrue:[ |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
4999 |
tokenEnd := tokenPosition + tokenName size - 1. |
864 | 5000 |
positions := OrderedCollection with:(tokenPosition to:tokenEnd). |
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
5001 |
pos := tokenPosition. |
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
5002 |
pos2 := tokenEnd. |
713 | 5003 |
lno := tokenLineNr. |
5004 |
sel := tokenName. |
|
5005 |
self nextToken. |
|
5006 |
arg := self binaryExpression. |
|
5007 |
(arg == #Error) ifTrue:[^ #Error]. |
|
5008 |
args := Array with:arg. |
|
5009 |
[tokenType == #Keyword] whileTrue:[ |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
5010 |
tokenEnd := tokenPosition + tokenName size - 1. |
864 | 5011 |
positions add:(tokenPosition to:tokenEnd). |
713 | 5012 |
sel := sel , tokenName. |
5013 |
self nextToken. |
|
5014 |
arg := self binaryExpression. |
|
5015 |
(arg == #Error) ifTrue:[^ #Error]. |
|
5016 |
args := args copyWith:arg. |
|
739
18bce3ea44f5
fixed syntax-highlight for cascade-selectors.
Claus Gittinger <cg@exept.de>
parents:
738
diff
changeset
|
5017 |
pos2 := tokenEnd |
713 | 5018 |
]. |
1022 | 5019 |
sel := self selectorCheck:sel for:realReceiver position:pos to:pos2. |
864 | 5020 |
|
5021 |
positions do:[:p | |
|
5022 |
self markSelector:sel from:p start to:p stop receiverNode:realReceiver. |
|
5023 |
]. |
|
713 | 5024 |
receiver := CascadeNode receiver:receiver selector:sel args:args. |
5025 |
receiver lineNumber:lno. |
|
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
5026 |
parseForCode ifFalse:[ |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
5027 |
self rememberSelectorUsed:sel |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
5028 |
]. |
713 | 5029 |
] ifFalse:[ |
5030 |
(tokenType == #Error) ifTrue:[^ #Error]. |
|
5031 |
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
|
5032 |
position:tokenPosition to:source position1Based - 1. |
713 | 5033 |
^ #Error |
5034 |
] |
|
5035 |
] |
|
5036 |
] |
|
5037 |
]. |
|
5038 |
||
5039 |
"obscure (unspecified ?) if selector follows; Question: |
|
5040 |
||
5041 |
is |
|
5042 |
'expr sel1; sel2 sel3' |
|
5043 |
||
5044 |
to be parsed as: |
|
5045 |
(t := expr. |
|
5046 |
t sel1. |
|
5047 |
t sel2) sel3 |
|
5048 |
||
5049 |
or: |
|
5050 |
(t := expr. |
|
5051 |
t sel1. |
|
5052 |
t sel2 sel3) |
|
5053 |
" |
|
5054 |
((tokenType == #Identifier) |
|
5055 |
or:[(tokenType == #BinaryOperator) |
|
5056 |
or:[tokenType == #Keyword]]) ifTrue:[ |
|
1328 | 5057 |
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
|
5058 |
position:tokenPosition to:source position1Based - 1. |
713 | 5059 |
^ #Error |
1328 | 5060 |
"/ self warning: "syntaxError:" 'possibly ambigous cascade - please group using (...)' |
5061 |
"/ position:tokenPosition to:source position - 1. |
|
5062 |
"/ tokenType == #Identifier ifTrue:[ |
|
5063 |
"/ ^ self unaryExpressionFor:receiver |
|
5064 |
"/ ]. |
|
5065 |
"/ tokenType == #BinaryOperator ifTrue:[ |
|
5066 |
"/ ^ self binaryExpressionFor:receiver |
|
5067 |
"/ ]. |
|
5068 |
"/ ^ self keywordExpressionFor:receiver |
|
713 | 5069 |
] |
5070 |
]. |
|
5071 |
^ receiver |
|
5072 |
||
1022 | 5073 |
"Modified: / 19.1.2000 / 16:22:16 / cg" |
713 | 5074 |
! |
5075 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5076 |
functionCallArgList |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5077 |
|argList arg prevInFunctionCallArgument| |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5078 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5079 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5080 |
tokenType == $) ifTrue:[ self nextToken. ^ #() ]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5081 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5082 |
argList := OrderedCollection new. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5083 |
[ true ] whileTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5084 |
prevInFunctionCallArgument := inFunctionCallArgument. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5085 |
inFunctionCallArgument := true. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5086 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5087 |
arg := self expression. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5088 |
argList add:arg. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5089 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5090 |
inFunctionCallArgument := prevInFunctionCallArgument. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5091 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5092 |
tokenType == $) ifTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5093 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5094 |
^ argList |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5095 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5096 |
((tokenType == #BinaryOperator) and:[tokenName = ',']) ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5097 |
self parseError:'"," or ")" expected'. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5098 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5099 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5100 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5101 |
! |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5102 |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5103 |
functionCallExpression |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5104 |
"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
|
5105 |
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
|
5106 |
|
1342
65f8f4d0ce09
only autoDefine workspace vars on the top level (i.e. not within blocks)
Claus Gittinger <cg@exept.de>
parents:
1341
diff
changeset
|
5107 |
|receiver numArgs argList evalSelectors evalSelector| |
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5108 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5109 |
receiver := self primary. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5110 |
tokenType == $( ifFalse:[^ receiver]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5111 |
AllowFunctionCallSyntaxForBlockEvaluation == true ifFalse:[^ receiver.]. |
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5112 |
(receiver == #Error) ifTrue:[^ #Error]. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5113 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5114 |
receiver isVariable ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5115 |
((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
|
5116 |
receiver isBlock ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5117 |
^ receiver |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5118 |
] |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5119 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5120 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5121 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5122 |
argList := self functionCallArgList. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5123 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5124 |
"/ make it a block evaluation |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5125 |
numArgs := argList size. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5126 |
numArgs == 0 ifTrue:[ |
1341 | 5127 |
^ UnaryNode receiver:receiver selector:#value |
5128 |
]. |
|
5129 |
evalSelectors := #( #'value:' |
|
5130 |
#'value:value:' |
|
5131 |
#'value:value:value:' |
|
5132 |
#'value:value:value:value:' |
|
5133 |
#'value:value:value:value:value:' |
|
5134 |
#'value:value:value:value:value:value:' |
|
5135 |
#'value:value:value:value:value:value:value:' |
|
5136 |
#'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
|
5137 |
). |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5138 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5139 |
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
|
5140 |
evalSelector := evalSelectors at:numArgs. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5141 |
^ MessageNode |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5142 |
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
|
5143 |
selector:evalSelector |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5144 |
args:argList. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5145 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5146 |
"/ gen argument vector |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5147 |
^ MessageNode |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5148 |
receiver:receiver |
1341 | 5149 |
selector:#valueWithArguments: |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5150 |
args:(self genMakeArrayWith:argList). |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5151 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5152 |
" |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5153 |
AllowFunctionCallSyntaxForBlockEvaluation := true. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5154 |
" |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5155 |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5156 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5157 |
|foo| |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5158 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5159 |
foo := [:x | x + 1]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5160 |
1 + foo(1). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5161 |
foo(1). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5162 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5163 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5164 |
|addN add1| |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5165 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5166 |
addN := [:n | [:x | x + n]]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5167 |
add1 := addN(1). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5168 |
add1(10). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5169 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5170 |
"AllowFunctionCallSyntaxForBlockEvaluation := false." |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5171 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5172 |
|addN add1| |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5173 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5174 |
addN := [:n | [:x | x + n]]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5175 |
add1 := addN value:1. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5176 |
add1 value:10 |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5177 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5178 |
! |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5179 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5180 |
genMakeArrayWith:elementExpressions |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5181 |
"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
|
5182 |
Will generate: |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5183 |
Array with:el1 ... with:elN (if N <= 5) |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5184 |
or: |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5185 |
(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
|
5186 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5187 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5188 |
|numEl arrRec sel expr| |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5189 |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5190 |
arrRec := VariableNode globalNamed:#Array. |
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5191 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5192 |
numEl := elementExpressions size. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5193 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5194 |
(numEl between:1 and:8) ifTrue:[ |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5195 |
sel := #( |
1275
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
5196 |
#'with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
5197 |
#'with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
5198 |
#'with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
5199 |
#'with:with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
5200 |
#'with:with:with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
5201 |
#'with:with:with:with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
5202 |
#'with:with:with:with:with:with:with:' |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
5203 |
#'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
|
5204 |
) at:numEl. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5205 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5206 |
^ MessageNode |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5207 |
receiver:arrRec |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5208 |
selector:sel |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5209 |
args:elementExpressions. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5210 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5211 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5212 |
"/ array creation expression ... |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5213 |
expr := MessageNode |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5214 |
receiver:arrRec |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5215 |
selector:#new: |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5216 |
arg:(ConstantNode type:#Integer value:numEl). |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5217 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5218 |
numEl == 0 ifTrue:[ |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5219 |
^ expr. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5220 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5221 |
"/ followed by a bunch of #at:put: messages... |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5222 |
elementExpressions keysAndValuesDo:[:idx :e | |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5223 |
expr := (idx == 1 ifTrue:[MessageNode] ifFalse:[CascadeNode]) |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5224 |
receiver:expr |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5225 |
selector:#at:put: |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5226 |
arg1:(ConstantNode type:#Integer value:idx) |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5227 |
arg2:e |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5228 |
fold:false. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5229 |
]. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5230 |
"/ followed by a #yourself: message... |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5231 |
expr := CascadeNode |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5232 |
receiver:expr |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5233 |
selector:#yourself. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5234 |
^ expr |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5235 |
! |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
5236 |
|
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5237 |
isValidUnarySelector:tokenType |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5238 |
tokenType == #Identifier ifTrue:[^true]. |
1373 | 5239 |
tokenType == #Here ifTrue:[^true]. |
5240 |
||
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5241 |
AllowReservedWordsAsSelectors == true ifTrue:[ |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5242 |
tokenType == #Self ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5243 |
tokenType == #Nil ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5244 |
tokenType == #True ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5245 |
tokenType == #False ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5246 |
tokenType == #Super ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5247 |
tokenType == #ThisContext ifTrue:[^true]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5248 |
]. |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5249 |
^ false |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5250 |
|
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5251 |
" |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5252 |
AllowReservedWordsAsSelectors := true |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5253 |
AllowReservedWordsAsSelectors := false |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5254 |
" |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5255 |
|
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5256 |
" |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5257 |
1234 self |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5258 |
1234 nil |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5259 |
1234 true |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5260 |
1234 false |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5261 |
1234 here |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5262 |
1234 super |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5263 |
1234 thisContext |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5264 |
" |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5265 |
! |
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
5266 |
|
713 | 5267 |
keywordExpression |
5268 |
"parse a keyword-expression; return a node-tree, nil or #Error. |
|
5269 |
||
5270 |
keywordExpression ::= binaryexpression |
|
5271 |
| { KEYWORD-PART binaryExpression } |
|
5272 |
" |
|
5273 |
||
1328 | 5274 |
|receiver| |
5275 |
||
713 | 5276 |
receiver := self binaryExpression. |
5277 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
1328 | 5278 |
^ self keywordExpressionFor:receiver |
5279 |
! |
|
5280 |
||
5281 |
keywordExpressionFor:receiverArg |
|
5282 |
"parse a keyword-expression; return a node-tree, nil or #Error. |
|
5283 |
||
5284 |
keywordExpression ::= binaryexpression |
|
5285 |
| { KEYWORD-PART binaryExpression } |
|
5286 |
" |
|
5287 |
||
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5288 |
|expr receiver sel arg args posR1 posR2 pos1 pos2 lno note positions| |
1328 | 5289 |
|
5290 |
receiver := receiverArg. |
|
5291 |
posR1 := tokenPosition. |
|
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5292 |
(tokenType == #Keyword) ifFalse:[^ receiver]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5293 |
|
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5294 |
pos1 := posR2 := tokenPosition. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5295 |
pos2 := tokenPosition + tokenName size - 1. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5296 |
positions := OrderedCollection with:(pos1 to:pos2). |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5297 |
sel := tokenName. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5298 |
lno := tokenLineNr. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5299 |
self nextToken. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5300 |
arg := self binaryExpression. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5301 |
(arg == #Error) ifTrue:[^ #Error]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5302 |
args := Array with:arg. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5303 |
[tokenType == #Keyword] whileTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5304 |
sel := sel , tokenName. |
713 | 5305 |
pos2 := tokenPosition + tokenName size - 1. |
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5306 |
positions add:(tokenPosition to:pos2). |
713 | 5307 |
self nextToken. |
5308 |
arg := self binaryExpression. |
|
5309 |
(arg == #Error) ifTrue:[^ #Error]. |
|
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5310 |
args := args copyWith:arg. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5311 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5312 |
|
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5313 |
positions do:[:p | |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5314 |
self markSelector:sel from:p start to:p stop receiverNode:receiver. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5315 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5316 |
sel := self selectorCheck:sel for:receiver positions:positions. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5317 |
|
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5318 |
ignoreErrors ifFalse:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5319 |
(Class definitionSelectors includes:sel) ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5320 |
receiver isVariable ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5321 |
receiver isUndeclared ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5322 |
self parseError:('undefined superclass: ' , receiver name) position:pos1 to:pos2. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5323 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5324 |
] |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5325 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5326 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5327 |
|
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5328 |
expr := MessageNode receiver:receiver selector:sel args:args fold:foldConstants. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5329 |
expr isErrorNode ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5330 |
self parseError:(expr errorString) position:pos1 to:pos2. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5331 |
errorFlag := false. "ok, user wants it - so he'll get it" |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5332 |
expr := MessageNode receiver:receiver selector:sel args:args fold:nil. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5333 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5334 |
expr lineNumber:lno. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5335 |
note := self plausibilityCheck:expr. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5336 |
note notNil ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5337 |
self warning:note position:pos1 to:pos2 |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5338 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5339 |
parseForCode ifFalse:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5340 |
self rememberSelectorUsed:sel receiver:receiver |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5341 |
]. |
713 | 5342 |
|
1193 | 5343 |
"/ (contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[ "/ do not check this for doits |
5344 |
"/ receiver isSuper ifTrue:[ |
|
5345 |
"/ sel ~= selector ifTrue:[ |
|
5346 |
"/ self warnCommonMistake:'possible bad super message (selector should be same as in current method) ?' |
|
5347 |
"/ position:posR1 to:posR2-1 |
|
5348 |
"/ ]. |
|
5349 |
"/ ]. |
|
5350 |
"/ ]. |
|
5351 |
"/ |
|
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5352 |
(sel = #and: or:[sel = #or:]) ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5353 |
expr arg1 isBlock ifFalse:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5354 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5355 |
position:pos2+1 to:tokenPosition-1 |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5356 |
] |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5357 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5358 |
(sel = #whileTrue: or:[sel = #whileFalse:]) ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5359 |
expr receiver isBlock ifFalse:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5360 |
self warnCommonMistake:'(possible common mistake) missing block brackets ?' |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5361 |
position:posR1 to:posR2-1 |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5362 |
] |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5363 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
5364 |
^ expr. |
713 | 5365 |
|
1022 | 5366 |
"Modified: / 19.1.2000 / 16:22:22 / cg" |
713 | 5367 |
! |
5368 |
||
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5369 |
nodeForMethodArg:varName |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5370 |
|varIndex var| |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5371 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5372 |
methodArgNames isNil ifTrue:[^ nil]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5373 |
varIndex := methodArgNames indexOf:varName. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5374 |
varIndex == 0 ifTrue:[^ nil]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5375 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5376 |
var := methodArgs at:varIndex. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5377 |
"/ var used:true. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5378 |
^ VariableNode type:#MethodArg |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5379 |
name:varName |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5380 |
token:var |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5381 |
index:varIndex |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5382 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5383 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5384 |
nodeForMethodVariable:varName |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5385 |
|varIndex var| |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5386 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5387 |
methodVarNames isNil ifTrue:[^ nil]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5388 |
varIndex := methodVarNames indexOf:varName. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5389 |
varIndex == 0 ifTrue:[^ nil]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5390 |
|
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5391 |
var := methodVars at:varIndex. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5392 |
var used:true. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5393 |
parseForCode ifFalse:[self rememberLocalUsed:varName]. |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5394 |
^ VariableNode type:#MethodVariable |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5395 |
name:varName |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5396 |
token:var |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5397 |
index:varIndex |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5398 |
! |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5399 |
|
0 | 5400 |
primary |
1028 | 5401 |
"parse a primary-expression; return a node-tree, nil or #Error. |
5402 |
This also cares for namespace-access-pathes." |
|
0 | 5403 |
|
1227 | 5404 |
|val pos node eMsg| |
924 | 5405 |
|
44 | 5406 |
(tokenType == #Self) ifTrue:[ |
1227 | 5407 |
^ self primary_self. |
5408 |
]. |
|
5409 |
||
5410 |
pos := tokenPosition. |
|
0 | 5411 |
(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
|
5412 |
" |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5413 |
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
|
5414 |
with other smalltalks. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5415 |
" |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5416 |
tokenName = 'here' ifTrue:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5417 |
(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
|
5418 |
tokenType := #Here. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5419 |
warnSTXHereExtensionUsed ifTrue:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5420 |
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
|
5421 |
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
|
5422 |
" |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5423 |
only warn once |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5424 |
" |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5425 |
warnSTXHereExtensionUsed := false |
663 | 5426 |
]. |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5427 |
^ 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
|
5428 |
] |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5429 |
]. |
1227 | 5430 |
^ self primary_identifier |
0 | 5431 |
]. |
49 | 5432 |
|
44 | 5433 |
((tokenType == #Integer) |
120 | 5434 |
or:[(tokenType == #String) |
44 | 5435 |
or:[(tokenType == #Character) |
5436 |
or:[(tokenType == #Float) |
|
5437 |
or:[(tokenType == #Symbol)]]]]) ifTrue:[ |
|
1227 | 5438 |
^ self primary_simpleLiteral. |
0 | 5439 |
]. |
924 | 5440 |
|
1347
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5441 |
(tokenType == #FixedPoint) ifTrue:[ |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5442 |
AllowFixedPointLiterals == true ifFalse:[ |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5443 |
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
|
5444 |
^ #Error |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5445 |
]. |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5446 |
^ self primary_simpleLiteral. |
6168b045f2ef
preps for fixedPoint literals
Claus Gittinger <cg@exept.de>
parents:
1342
diff
changeset
|
5447 |
]. |
0 | 5448 |
(tokenType == #Nil) ifTrue:[ |
1227 | 5449 |
^ self primary_nil. |
5450 |
]. |
|
0 | 5451 |
(tokenType == #True) ifTrue:[ |
1227 | 5452 |
^ self primary_true |
0 | 5453 |
]. |
5454 |
(tokenType == #False) ifTrue:[ |
|
1227 | 5455 |
^ self primary_false |
5456 |
]. |
|
0 | 5457 |
(tokenType == #Super) ifTrue:[ |
1227 | 5458 |
^ self primary_super. |
5459 |
]. |
|
924 | 5460 |
|
0 | 5461 |
(tokenType == #ThisContext) ifTrue:[ |
1262 | 5462 |
^ self primary_thisContext |
0 | 5463 |
]. |
924 | 5464 |
|
0 | 5465 |
(tokenType == #HashLeftParen) ifTrue:[ |
1538
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5466 |
self nextToken. |
1202
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
5467 |
self inArrayLiteral:true. |
1165
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5468 |
ParseErrorSignal handle:[:ex | |
1202
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
5469 |
self inArrayLiteral:false. |
1165
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5470 |
^ #Error |
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5471 |
] do:[ |
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5472 |
val := self array. |
09d40e1ff75d
oops - invalid literal array const was not signalling an error
Claus Gittinger <cg@exept.de>
parents:
1164
diff
changeset
|
5473 |
]. |
1202
95abdd4272cd
scanning of keyword symbols in array consts fixed
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
5474 |
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
|
5475 |
self nextToken. |
1003
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5476 |
(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
|
5477 |
^ #Error |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5478 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5479 |
^ ConstantNode type:#Array value:val |
0 | 5480 |
]. |
924 | 5481 |
|
5482 |
(tokenType == #HashLeftBrace) ifTrue:[ |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
5483 |
val := self qualifiedName. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
5484 |
self nextToken. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
5485 |
^ val. |
924 | 5486 |
]. |
5487 |
||
0 | 5488 |
(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
|
5489 |
self nextToken. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5490 |
val := self byteArray. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5491 |
self nextToken. |
1003
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5492 |
(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
|
5493 |
^ #Error |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5494 |
]. |
924 | 5495 |
^ ConstantNode type:#ByteArray value:val |
0 | 5496 |
]. |
432 | 5497 |
|
0 | 5498 |
(tokenType == $() ifTrue:[ |
1227 | 5499 |
^ self primary_expression. |
0 | 5500 |
]. |
924 | 5501 |
|
0 | 5502 |
(tokenType == $[ ) ifTrue:[ |
673 | 5503 |
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
|
5504 |
val := self block. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5505 |
self nextToken. |
1003
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
5506 |
(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
|
5507 |
^ #Error |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5508 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5509 |
^ val |
0 | 5510 |
]. |
19 | 5511 |
|
1262 | 5512 |
"/ EXPERIMENTAL - may be in next release |
1295 | 5513 |
AllowVariableReferences == true ifTrue:[ |
5514 |
((tokenType == #BinaryOperator) and:[token = '&']) ifTrue:[ |
|
5515 |
self nextToken. |
|
5516 |
node := self primary_identifier. |
|
5517 |
"/ generate a Reference |
|
5518 |
^ self makeReferenceFor:node |
|
5519 |
]. |
|
5520 |
]. |
|
5521 |
||
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5522 |
(tokenType == ${ ) ifTrue:[ |
1363 | 5523 |
allowSqueakExtensions == true ifFalse:[ |
1335 | 5524 |
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
|
5525 |
errorFlag := false. |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5526 |
]. |
1227 | 5527 |
^ self primary_squeakComputedArray. |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5528 |
]. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
5529 |
|
502
410af1c0df1d
parse primitive-primary expression
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
5530 |
(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
|
5531 |
self nextToken. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5532 |
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
|
5533 |
hasNonOptionalPrimitiveCode := true. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5534 |
hasPrimitiveCode := true. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5535 |
^ node |
502
410af1c0df1d
parse primitive-primary expression
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
5536 |
]. |
410af1c0df1d
parse primitive-primary expression
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
5537 |
|
1227 | 5538 |
tokenType == #HashHashLeftParen ifTrue:[ |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5539 |
self halt. |
1295 | 5540 |
self nextToken. |
5541 |
AllowDolphinExtensions == true ifFalse:[ |
|
1335 | 5542 |
self parseError:'non-Standard Dolphin extension: ##(..). Enable in settings.' position:pos to:tokenPosition. |
1227 | 5543 |
^ #Error |
5544 |
]. |
|
5545 |
^ self primary_dolphinComputedLiteral. |
|
5546 |
]. |
|
1299 | 5547 |
tokenType == #ExclaLeftBrack ifTrue:[ |
1295 | 5548 |
self nextToken. |
5549 |
AllowLazyValueExtension == true ifFalse:[ |
|
1335 | 5550 |
self parseError:'non-Standard LazyValue extension. Enable in classVariable.' position:pos to:tokenPosition. |
1295 | 5551 |
^ #Error |
5552 |
]. |
|
5553 |
^ self primary_lazyValue. |
|
5554 |
]. |
|
5555 |
tokenType == #HashHash ifTrue:[ |
|
1301
677ca6e364d4
+ warnPossible incompatibility
Claus Gittinger <cg@exept.de>
parents:
1299
diff
changeset
|
5556 |
self warnPossibleIncompatibility:'''##'' might be interpreted differently in other smalltalk systems' position:pos to:tokenPosition. |
1295 | 5557 |
tokenType := #Symbol. |
5558 |
token := tokenValue := tokenName := '#'. |
|
5559 |
^ self primary_simpleLiteral. |
|
5560 |
]. |
|
1227 | 5561 |
|
1538
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5562 |
allowSqueakExtensions == true ifTrue:[ |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5563 |
((tokenType == #BinaryOperator) and:[token = '#']) ifTrue:[ |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5564 |
self nextToken. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5565 |
(tokenType == $( ) ifFalse:[ |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5566 |
self parseError:'''('' expected after #.' position:pos to:tokenPosition. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5567 |
^ self. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5568 |
]. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5569 |
self nextToken. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5570 |
self inArrayLiteral:true. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5571 |
ParseErrorSignal handle:[:ex | |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5572 |
self inArrayLiteral:false. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5573 |
^ #Error |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5574 |
] do:[ |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5575 |
val := self array. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5576 |
]. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5577 |
self inArrayLiteral:false. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5578 |
self nextToken. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5579 |
(self noAssignmentAllowed:'assignment to a constant' at:pos) ifFalse:[ |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5580 |
^ #Error |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5581 |
]. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5582 |
^ ConstantNode type:#Array value:val |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5583 |
]. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5584 |
]. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5585 |
|
1537
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5586 |
((tokenType == #BinaryOperator) and:[token = '-']) ifTrue:[ |
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5587 |
self nextToken. |
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5588 |
((tokenType == #Integer) |
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5589 |
or:[(tokenType == #Float)]) ifFalse:[ |
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5590 |
self parseError:'number expected after sign.' position:pos to:tokenPosition. |
1539 | 5591 |
^ #Error. |
1537
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5592 |
]. |
1538
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5593 |
allowSqueakExtensions == true ifFalse:[ |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5594 |
self parseError:'non-Standard Squeak extension: space between sign and number. Enable in settings.' position:pos to:tokenPosition. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5595 |
errorFlag := false. |
c55990043eb6
squeak allow space between '#" and '('
Claus Gittinger <cg@exept.de>
parents:
1537
diff
changeset
|
5596 |
]. |
1537
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5597 |
|
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5598 |
node := self primary_simpleLiteral. |
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5599 |
node isConstant ifFalse:[ |
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5600 |
self parseError:'number expected after sign.' position:pos to:tokenPosition. |
1539 | 5601 |
^ #Error. |
1537
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5602 |
]. |
1557
311e94185248
oops - parser clobbered Const1Node (negated)
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
5603 |
^ ConstantNode type:(node type) value:(node value negated). |
1537
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5604 |
]. |
de5fc45c2f10
squeak allows whiteSpace between sign and number
Claus Gittinger <cg@exept.de>
parents:
1535
diff
changeset
|
5605 |
|
0 | 5606 |
(tokenType == #Error) ifTrue:[^ #Error]. |
44 | 5607 |
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
|
5608 |
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
|
5609 |
, tokenType printString , |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5610 |
' unexpected') position:tokenPosition to:tokenPosition |
0 | 5611 |
] ifFalse:[ |
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5612 |
(#(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
|
5613 |
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
|
5614 |
, tokenType printString , '(' , tokenName , ') ' , |
805 | 5615 |
' 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
|
5616 |
] ifFalse:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5617 |
eMsg := ('error in primary; ' |
1295 | 5618 |
, (token ? '') , ' (', tokenType printString , |
5619 |
') unexpected') |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5620 |
]. |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
5621 |
self syntaxError:eMsg position:tokenPosition to:source position1Based - 1 |
0 | 5622 |
]. |
5623 |
^ #Error |
|
120 | 5624 |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
5625 |
"Created: / 13.9.1995 / 12:50:50 / claus" |
1068 | 5626 |
"Modified: / 18.8.2000 / 20:51:22 / cg" |
0 | 5627 |
! |
5628 |
||
1227 | 5629 |
primary_dolphinComputedLiteral |
1273
3a9541cd8fef
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
5630 |
"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
|
5631 |
In dolphin, these are written as: ##( expression ) |
3a9541cd8fef
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1272
diff
changeset
|
5632 |
and create a literal constant for the expressions value. |
1274 | 5633 |
Right now, only a subset is supported - Strings, ByteArrays and Characters. |
5634 |
WARNING: this is only supported to allow filing in dolphin code. |
|
5635 |
since stc cannot handle this (at the moment), you should rewrite the code |
|
5636 |
if you ever plan to stc-compile it into a shared library" |
|
1227 | 5637 |
|
5638 |
|pos expr val| |
|
5639 |
||
5640 |
pos := tokenPosition. |
|
5641 |
||
5642 |
expr := self expression. |
|
5643 |
||
5644 |
tokenType ~~ $) ifTrue:[ |
|
5645 |
self parseError:''')'' expected' position:tokenPosition. |
|
5646 |
^ #Error |
|
5647 |
]. |
|
5648 |
self nextToken. |
|
5649 |
||
5650 |
(self noAssignmentAllowed:'invalid assignment' at:pos) ifFalse:[ |
|
5651 |
^ #Error |
|
5652 |
]. |
|
5653 |
||
5654 |
val := expr evaluate. |
|
5655 |
||
5656 |
val isLiteral ifTrue:[ |
|
1272
2a429e2293d1
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1271
diff
changeset
|
5657 |
val isString ifTrue:[ |
2a429e2293d1
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1271
diff
changeset
|
5658 |
^ ConstantNode type:#String value:val |
2a429e2293d1
dolphin compile-time constant strings
Claus Gittinger <cg@exept.de>
parents:
1271
diff
changeset
|
5659 |
]. |
1227 | 5660 |
val isByteArray ifTrue:[ |
5661 |
^ ConstantNode type:#ByteArray value:val |
|
5662 |
]. |
|
1234 | 5663 |
val isCharacter ifTrue:[ |
5664 |
^ ConstantNode type:#Character value:val |
|
5665 |
]. |
|
1295 | 5666 |
val isInteger ifTrue:[ |
5667 |
^ ConstantNode type:#Integer value:val |
|
5668 |
]. |
|
1328 | 5669 |
val isLimitedPrecisionReal ifTrue:[ |
5670 |
^ ConstantNode type:#Float value:val |
|
5671 |
]. |
|
1295 | 5672 |
val isArray ifTrue:[ |
5673 |
^ ConstantNode type:#Array value:val |
|
5674 |
]. |
|
1227 | 5675 |
] ifFalse:[ |
5676 |
self parseError:'must be representable as a literal (for now)' position:pos. |
|
5677 |
^ #Error |
|
5678 |
]. |
|
1326 | 5679 |
self halt:'unimplemented'. |
1227 | 5680 |
"/ "/ make it an array creation expression ... |
5681 |
"/ expr := MessageNode |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5682 |
"/ receiver:(VariableNode globalNamed:#Array) |
1227 | 5683 |
"/ selector:#new: |
5684 |
"/ arg:(ConstantNode type:#Integer value:(exprList size)). |
|
5685 |
"/ |
|
5686 |
"/ exprList size == 0 ifTrue:[ |
|
5687 |
"/ ^ expr. |
|
5688 |
"/ ]. |
|
5689 |
"/ exprList keysAndValuesDo:[:idx :e | |
|
5690 |
"/ expr := (idx == 1 ifTrue:[MessageNode] ifFalse:[CascadeNode]) |
|
5691 |
"/ receiver:expr |
|
5692 |
"/ selector:#at:put: |
|
5693 |
"/ arg1:(ConstantNode type:#Integer value:idx) |
|
5694 |
"/ arg2:e |
|
5695 |
"/ fold:false. |
|
5696 |
"/ ]. |
|
5697 |
"/ expr := CascadeNode |
|
5698 |
"/ receiver:expr |
|
5699 |
"/ selector:#yourself. |
|
5700 |
"/ ^ expr |
|
5701 |
! |
|
5702 |
||
5703 |
primary_expression |
|
5704 |
"parse a parentized expression primary; return a node-tree, or raise an Error." |
|
5705 |
||
5706 |
|pos val eMsg| |
|
5707 |
||
5708 |
pos := tokenPosition. |
|
5709 |
||
5710 |
self nextToken. |
|
5711 |
val := self expression. |
|
5712 |
(val == #Error) ifTrue:[^ #Error]. |
|
5713 |
(tokenType ~~ $) ) ifTrue:[ |
|
5714 |
tokenType isCharacter ifTrue:[ |
|
5715 |
eMsg := 'missing '')'' (i.e. ''' , tokenType asString , ''' unexpected)'. |
|
5716 |
] ifFalse:[ |
|
5717 |
eMsg := 'missing '')'''. |
|
5718 |
]. |
|
5719 |
self syntaxError:eMsg withCRs position:pos to:tokenPosition. |
|
5720 |
^ #Error |
|
5721 |
]. |
|
5722 |
self nextToken. |
|
5723 |
(self noAssignmentAllowed:'invalid assignment' at:pos) ifFalse:[ |
|
5724 |
^ #Error |
|
5725 |
]. |
|
5726 |
val parenthized:true. |
|
5727 |
^ val |
|
5728 |
! |
|
5729 |
||
5730 |
primary_false |
|
5731 |
"parse a false primary; return a node-tree, or raise an Error." |
|
5732 |
||
5733 |
|pos| |
|
5734 |
||
5735 |
pos := tokenPosition. |
|
5736 |
||
5737 |
self nextToken. |
|
5738 |
(self noAssignmentAllowed:'assignment to ''false''' at:pos) ifFalse:[ |
|
5739 |
^ #Error |
|
5740 |
]. |
|
5741 |
self markBooleanConstantFrom:pos to:pos+4. |
|
5742 |
^ ConstantNode type:#False value:false |
|
5743 |
! |
|
5744 |
||
5745 |
primary_here |
|
5746 |
"parse a here primary; return a node-tree, nil or #Error." |
|
5747 |
||
5748 |
|pos| |
|
5749 |
||
5750 |
pos := tokenPosition. |
|
5751 |
||
5752 |
self nextToken. |
|
5753 |
(self noAssignmentAllowed:'assignment to pseudo variable ''here''' at:pos) ifFalse:[ |
|
5754 |
^ #Error |
|
5755 |
]. |
|
5756 |
classToCompileFor isNil ifTrue:[ |
|
5757 |
self warning:'in which class are you ?' position:pos to:(pos + 3). |
|
5758 |
]. |
|
5759 |
self markSelfFrom:pos to:pos+3. |
|
5760 |
^ SuperNode value:selfValue inClass:classToCompileFor here:true |
|
5761 |
! |
|
5762 |
||
5763 |
primary_identifier |
|
5764 |
"parse a false primary; return a node-tree, or raise an Error." |
|
5765 |
||
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5766 |
|pos1 pos2 expr varName rawName var globlName nameSpace nameSpaceGlobal |
1551 | 5767 |
t cls lnr node holder autoHow assignmentAllowed| |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5768 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5769 |
pos1 := tokenPosition. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5770 |
pos2 := tokenPosition + tokenName size - 1. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5771 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5772 |
varName := tokenName. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5773 |
|
1440 | 5774 |
(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
|
5775 |
and:[currentBlock isNil |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5776 |
and:[(requestor askFor:#isWorkspace) |
1359 | 5777 |
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
|
5778 |
var := self variableOrError:varName. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5779 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5780 |
(var == #Error) ifTrue:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5781 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
1359 | 5782 |
autoHow == #workspace ifTrue:[ |
5783 |
holder := Workspace addWorkspaceVariable:varName. |
|
5784 |
var := VariableNode type:#WorkspaceVariable holder:holder name:varName |
|
5785 |
] ifFalse:[ |
|
5786 |
holder := self addDoItTemporary:varName. |
|
5787 |
var := VariableNode type:#DoItTemporary holder:holder name:varName |
|
5788 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5789 |
] ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5790 |
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
|
5791 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5792 |
] |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5793 |
] ifFalse:[ |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5794 |
var := self variable. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5795 |
self nextToken. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5796 |
]. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5797 |
|
1227 | 5798 |
"/ errorFlag == true ifTrue:[self halt]. |
5799 |
(var == #Error) ifTrue:[ |
|
5800 |
errorFlag := true |
|
5801 |
]. |
|
5802 |
||
5803 |
(tokenType == #'::') ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5804 |
globlName := rawName := varName. |
1227 | 5805 |
|
5806 |
"is it in a namespace ?" |
|
5807 |
nameSpace := self findNameSpaceWith:globlName. |
|
5808 |
nameSpace notNil ifTrue:[ |
|
5809 |
globlName := nameSpace name , '::' , globlName |
|
5810 |
]. |
|
5811 |
||
5812 |
[tokenType == #'::'] whileTrue:[ |
|
5813 |
nameSpace := globlName. |
|
5814 |
||
5815 |
self nextToken. |
|
5816 |
(tokenType == #Identifier) ifTrue:[ |
|
5817 |
ignoreWarnings ifFalse:[ |
|
5818 |
warnSTXNameSpaceUse ifTrue:[ |
|
5819 |
self warning:'nameSpaces are a nonstandard feature of ST/X' |
|
1458 | 5820 |
doNotShowAgainAction:[ WarnSTXSpecials := false ] |
1371
de4c37ac12fc
code rewritten to be independent of stream zero-base
Claus Gittinger <cg@exept.de>
parents:
1369
diff
changeset
|
5821 |
position:pos1 to:(source position1Based). |
1227 | 5822 |
" |
5823 |
only warn once |
|
5824 |
" |
|
5825 |
warnSTXNameSpaceUse := false |
|
5826 |
] |
|
5827 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5828 |
varName := tokenName. |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5829 |
|
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5830 |
globlName := (nameSpace , '::' , varName). |
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5831 |
rawName := (rawName , '::' , varName). |
1227 | 5832 |
|
5833 |
nameSpaceGlobal := Smalltalk at:nameSpace asSymbol ifAbsent:nil. |
|
5834 |
nameSpaceGlobal isNil ifTrue:[ |
|
5835 |
warnedUnknownNamespaces isNil ifTrue:[ |
|
5836 |
warnedUnknownNamespaces := Set new. |
|
5837 |
]. |
|
5838 |
(warnedUnknownNamespaces includes:nameSpace) ifFalse:[ |
|
5839 |
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
|
5840 |
position:pos1 to:tokenPosition-1. |
1227 | 5841 |
"/ self parseError:('unknown nameSpace: ', nameSpace) position:pos to:tokenPosition-1. |
5842 |
warnedUnknownNamespaces add:nameSpace. |
|
5843 |
] |
|
5844 |
] ifFalse:[ |
|
5845 |
nameSpaceGlobal isNameSpace ifTrue:[ |
|
5846 |
"/ for now: only Smalltalk is allowed |
|
5847 |
nameSpaceGlobal ~~ Smalltalk ifTrue:[ |
|
5848 |
"/ self parseError:('(currently) the only valid nameSpace is `Smalltalk''') position:pos to:tokenPosition-1. |
|
5849 |
] ifFalse:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5850 |
globlName := varName |
1227 | 5851 |
]. |
5852 |
] ifFalse:[ |
|
5853 |
nameSpaceGlobal isBehavior ifFalse:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5854 |
self parseError:('invalid nameSpace: ' , nameSpace) position:pos1 to:tokenPosition-1. |
1227 | 5855 |
] ifTrue:[ |
1391 | 5856 |
nameSpaceGlobal isLoaded ifTrue:[ |
5857 |
(nameSpaceGlobal privateClassesAt:varName asSymbol) isNil ifTrue:[ |
|
5858 |
self warning:('no private class: ' , varName , ' in class: ' , nameSpace) |
|
5859 |
position:pos1 to:tokenPosition-1. |
|
5860 |
"/ self parseError:('no private class: ' , name , ' in class: ' , nameSpace) position:pos to:tokenPosition-1. |
|
5861 |
] |
|
1227 | 5862 |
] |
5863 |
] |
|
5864 |
]. |
|
5865 |
]. |
|
5866 |
self nextToken. |
|
5867 |
]. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
5868 |
var := VariableNode globalNamed:globlName. |
1227 | 5869 |
parseForCode ifFalse:[self rememberGlobalUsed:globlName]. |
5870 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5871 |
self markVariable:var from:pos1 to:pos1 + rawName size - 1. |
1227 | 5872 |
]. |
5873 |
||
5874 |
var == #Error ifTrue:[ |
|
5875 |
^ #Error |
|
5876 |
]. |
|
5877 |
||
5878 |
errorFlag ~~ true ifTrue:[ |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5879 |
self markVariable:var from:pos1 to:pos1 + varName size - 1. |
1227 | 5880 |
]. |
5881 |
(ignoreErrors or:[ignoreWarnings or:[parseForCode not]]) ifTrue:[ |
|
5882 |
errorFlag := false. |
|
5883 |
]. |
|
5884 |
||
5885 |
((tokenType ~~ $_) and:[tokenType ~~ #':=']) ifTrue:[ |
|
5886 |
parseForCode ifFalse:[ |
|
5887 |
var isInstanceVariable ifTrue:[ self rememberInstVarRead:var name]. |
|
5888 |
var isClassVariable ifTrue:[ self rememberClassVarRead:var name]. |
|
5889 |
]. |
|
5890 |
^ var |
|
5891 |
]. |
|
5892 |
||
1551 | 5893 |
"/ assignment... |
5894 |
||
1227 | 5895 |
"/ careful: it could already be an implicit self send |
5896 |
ImplicitSelfSends ifTrue:[ |
|
5897 |
var isMessage ifTrue:[ |
|
5898 |
self nextToken. |
|
5899 |
expr := self expression. |
|
5900 |
self isSyntaxHighlighter ifFalse:[ |
|
5901 |
(errorFlag or:[expr == #Error]) ifTrue:[^ #Error]. |
|
5902 |
]. |
|
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
5903 |
^ MessageNode receiver:(self selfNode) selector:('__' , varName , ':') asSymbol arg:expr. |
1227 | 5904 |
]. |
5905 |
]. |
|
5906 |
||
1551 | 5907 |
assignmentAllowed := true. |
5908 |
||
1227 | 5909 |
(var ~~ #Error) ifTrue:[ |
5910 |
t := var type. |
|
5911 |
t == #MethodVariable ifTrue:[ |
|
5912 |
modifiedLocalVars isNil ifTrue:[ |
|
5913 |
modifiedLocalVars := Set new. |
|
5914 |
]. |
|
5915 |
modifiedLocalVars add:var name. |
|
1551 | 5916 |
] ifFalse:[ (t == #InstanceVariable) ifTrue:[ |
5917 |
varName := self classesInstVarNames at:(var index). |
|
5918 |
||
5919 |
"/ ca once did this to "name" and wondered what happened to his class ... |
|
5920 |
"/ (not really a beginners bug, but may happen as a typo or missing local variable; |
|
5921 |
"/ and is hard to track down later) |
|
5922 |
||
5923 |
warnCommonMistakes ifTrue:[ |
|
5924 |
classToCompileFor isMeta ifTrue:[ |
|
5925 |
(classToCompileFor isSubclassOf:Class) ifTrue:[ |
|
5926 |
(Class allInstVarNames includes:(var name)) ifTrue:[ |
|
5927 |
self warning:'assignment to a classInstanceVariable\(see hierarchy of "Class")' withCRs position:pos1 to:pos2. |
|
5928 |
] |
|
5929 |
] |
|
5930 |
] |
|
5931 |
]. |
|
5932 |
parseForCode ifFalse:[ |
|
5933 |
modifiedInstVars isNil ifTrue:[ |
|
5934 |
modifiedInstVars := Set new |
|
5935 |
]. |
|
5936 |
modifiedInstVars add:varName |
|
5937 |
] |
|
5938 |
] ifFalse:[ (t == #ClassVariable) ifTrue:[ |
|
5939 |
varName := var name. |
|
5940 |
varName := varName copyFrom:((varName indexOf:$:) + 1). |
|
5941 |
parseForCode ifFalse:[ |
|
5942 |
modifiedClassVars isNil ifTrue:[ |
|
5943 |
modifiedClassVars := Set new |
|
5944 |
]. |
|
5945 |
modifiedClassVars add:varName |
|
5946 |
] |
|
5947 |
] ifFalse:[ (t == #GlobalVariable) ifTrue:[ |
|
5948 |
(cls := Smalltalk classNamed:var name) notNil ifTrue:[ |
|
5949 |
cls name = var name ifTrue:[ |
|
5950 |
self warning:'assignment to global which refers to a class' position:pos1 to:pos2. |
|
5951 |
] |
|
5952 |
]. |
|
5953 |
parseForCode ifFalse:[ |
|
5954 |
modifiedGlobals isNil ifTrue:[ |
|
5955 |
modifiedGlobals := Set new |
|
5956 |
]. |
|
5957 |
modifiedGlobals add:var name |
|
5958 |
] |
|
5959 |
] ifFalse:[ |
|
5960 |
(t == #PrivateClass) ifTrue:[ |
|
5961 |
assignmentAllowed := false. |
|
5962 |
self parseError:'assignment to private class' position:pos1 to:pos2. |
|
5963 |
] ifFalse:[ (t == #MethodArg) ifTrue:[ |
|
5964 |
assignmentAllowed := false. |
|
5965 |
self parseError:'assignment to method argument' position:pos1 to:pos2. |
|
5966 |
] ifFalse:[ (t == #BlockArg) ifTrue:[ |
|
5967 |
assignmentAllowed := false. |
|
5968 |
self parseError:'assignment to block argument' position:pos1 to:pos2. |
|
5969 |
] ifFalse:[ (t == #PoolVariable) ifTrue:[ |
|
5970 |
self isDoIt ifTrue:[ |
|
5971 |
self warning:'assignment to pool variable' position:pos1 to:pos2. |
|
5972 |
assignmentAllowed := true. |
|
5973 |
] ifFalse:[ |
|
5974 |
self parseError:'assignment to pool variable' position:pos1 to:pos2. |
|
5975 |
] |
|
5976 |
]]]]]]] |
|
1227 | 5977 |
]. |
5978 |
]. |
|
5979 |
||
5980 |
lnr := tokenLineNr. |
|
5981 |
||
5982 |
self nextToken. |
|
5983 |
pos2 := tokenPosition. |
|
5984 |
expr := self expression. |
|
5985 |
||
5986 |
"/ a typical beginner error: |
|
5987 |
"/ expr ifTrue:[ |
|
5988 |
"/ var := super |
|
5989 |
"/ ] ifFalse:[ |
|
5990 |
"/ var := something-else |
|
5991 |
"/ ]. |
|
5992 |
"/ var messageSend |
|
5993 |
"/ |
|
5994 |
"/ does not what a beginner might think. |
|
5995 |
||
5996 |
self isSyntaxHighlighter ifTrue:[ |
|
5997 |
(expr == #Error) ifTrue:[^ #Error]. |
|
5998 |
] ifFalse:[ |
|
5999 |
warnCommonMistakes ifTrue:[ |
|
6000 |
(expr ~~ #Error and:[expr isSuper]) ifTrue:[ |
|
1551 | 6001 |
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 | 6002 |
]. |
6003 |
]. |
|
6004 |
||
6005 |
(errorFlag or:[expr == #Error]) ifTrue:[^ #Error]. |
|
6006 |
expr isVariable ifTrue:[ |
|
6007 |
expr name = var name ifTrue:[ |
|
1551 | 6008 |
self warning:('useless assignment to "' , var name, '"' ) position:pos1 to:pos2-1. |
1227 | 6009 |
]. |
6010 |
]. |
|
6011 |
]. |
|
1551 | 6012 |
assignmentAllowed ifTrue:[ |
6013 |
node := AssignmentNode variable:var expression:expr. |
|
6014 |
(lineNumberInfo == #full) ifTrue:[node lineNumber:lnr]. |
|
6015 |
] ifFalse:[ |
|
6016 |
self parseError:('assignment to "' , var name, '" suppressed' ) position:pos1 to:pos2-1. |
|
6017 |
node := expr. |
|
6018 |
]. |
|
1227 | 6019 |
^ node |
6020 |
! |
|
6021 |
||
1295 | 6022 |
primary_lazyValue |
6023 |
|pos block expr| |
|
6024 |
||
6025 |
pos := tokenPosition. |
|
6026 |
||
6027 |
(tokenType == $: ) ifTrue:[ |
|
6028 |
self parseError:'lazyValues have no arguments' position:tokenPosition. |
|
6029 |
^ #Error |
|
6030 |
]. |
|
6031 |
||
6032 |
block := self blockBody:#(). |
|
6033 |
self nextToken. |
|
6034 |
||
6035 |
expr := MessageNode |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6036 |
receiver:(VariableNode globalNamed:#LazyValue) |
1295 | 6037 |
selector:#'block:' |
6038 |
arg:block. |
|
6039 |
^ expr |
|
6040 |
! |
|
6041 |
||
1227 | 6042 |
primary_nil |
6043 |
"parse a nil primary; return a node-tree, nil or #Error." |
|
6044 |
||
6045 |
|pos| |
|
6046 |
||
6047 |
pos := tokenPosition. |
|
6048 |
||
6049 |
self nextToken. |
|
6050 |
(self noAssignmentAllowed:'assignment to ''nil''' at:pos) ifFalse:[ |
|
6051 |
^ #Error |
|
6052 |
]. |
|
6053 |
"/ self markConstantFrom:pos to:pos+2. |
|
6054 |
nilNode isNil ifTrue:[ |
|
6055 |
nilNode := ConstantNode type:#Nil value:nil |
|
6056 |
]. |
|
6057 |
^ nilNode |
|
6058 |
! |
|
6059 |
||
6060 |
primary_self |
|
6061 |
"parse a self primary; return a node-tree, nil or #Error." |
|
6062 |
||
6063 |
|pos| |
|
6064 |
||
6065 |
pos := tokenPosition. |
|
6066 |
||
6067 |
self nextToken. |
|
6068 |
(self noAssignmentAllowed:'assignment to pseudo variable ''self''' at:pos) ifFalse:[ |
|
6069 |
^ ParseError raise |
|
6070 |
]. |
|
6071 |
self markSelfFrom:pos to:pos+3. |
|
1262 | 6072 |
^ self selfNode |
1227 | 6073 |
! |
6074 |
||
6075 |
primary_simpleLiteral |
|
6076 |
"parse a simple literal primary; return a node-tree, or raise an Error." |
|
6077 |
||
6078 |
|pos val| |
|
6079 |
||
6080 |
pos := tokenPosition. |
|
6081 |
||
6082 |
"/ |
|
6083 |
"/ ImmutableStrings are experimental |
|
6084 |
"/ |
|
6085 |
((tokenType == #String) |
|
6086 |
and:[(StringsAreImmutable == true) |
|
6087 |
and:[ImmutableString notNil]]) ifTrue:[ |
|
6088 |
tokenValue := tokenValue copy. |
|
6089 |
tokenValue changeClassTo:ImmutableString. |
|
6090 |
token := tokenValue |
|
6091 |
]. |
|
6092 |
(tokenType == #Symbol) ifTrue:[ |
|
6093 |
parseForCode ifFalse:[ |
|
6094 |
self rememberSymbolUsed:tokenValue |
|
6095 |
]. |
|
6096 |
]. |
|
6097 |
val := ConstantNode type:tokenType value:tokenValue. |
|
6098 |
||
6099 |
tokenValue isSymbol ifTrue:[ |
|
6100 |
self markSymbolFrom:tokenPosition to:tokenPosition+tokenValue size-1. |
|
6101 |
]. |
|
6102 |
||
6103 |
self nextToken. |
|
6104 |
(self noAssignmentAllowed:'assignment to a constant' at:pos) ifFalse:[ |
|
6105 |
^ #Error |
|
6106 |
]. |
|
6107 |
^ val |
|
6108 |
! |
|
6109 |
||
6110 |
primary_squeakComputedArray |
|
1274 | 6111 |
"parse a squeak computed array literal; return a node-tree, or raise an Error. |
6112 |
In squeak, these are written as: { expr1 . expr2 . ... exprN ) |
|
6113 |
and create a literalArray containing the exprI values. |
|
6114 |
WARNING: this is only supported to allow filing in squeak code. |
|
6115 |
since stc cannot handle this (at the moment), you should rewrite the code |
|
6116 |
if you ever plan to stc-compile it into a shared library" |
|
6117 |
||
1227 | 6118 |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6119 |
|pos exprList| |
1227 | 6120 |
|
6121 |
pos := tokenPosition. |
|
6122 |
||
6123 |
self nextToken. |
|
6124 |
exprList := self squeakComputedArray. |
|
1277
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6125 |
(exprList == #Error) ifTrue:[ ^ #Error ]. |
1227 | 6126 |
|
6127 |
tokenType ~~ $} ifTrue:[ |
|
6128 |
self parseError:'''}'' expected' position:tokenPosition. |
|
6129 |
^ #Error |
|
6130 |
]. |
|
6131 |
self nextToken. |
|
6132 |
(self noAssignmentAllowed:'invalid assignment' at:pos) ifFalse:[ |
|
6133 |
^ #Error |
|
6134 |
]. |
|
6135 |
||
6136 |
"/ make it an array creation expression ... |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6137 |
^ self genMakeArrayWith:exprList |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6138 |
|
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6139 |
" |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6140 |
Compiler allowSqueakExtensions:true. |
1299 | 6141 |
" |
6142 |
||
6143 |
" |
|
6144 |
{ 1@2. 10 factorial. Date today }. |
|
6145 |
" |
|
6146 |
||
6147 |
" |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6148 |
Compiler allowSqueakExtensions:false. |
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6149 |
" |
1227 | 6150 |
! |
6151 |
||
6152 |
primary_super |
|
6153 |
"parse a super primary; return a node-tree, nil or #Error." |
|
6154 |
||
6155 |
|pos| |
|
6156 |
||
6157 |
pos := tokenPosition. |
|
6158 |
||
6159 |
usesSuper := true. |
|
6160 |
self nextToken. |
|
6161 |
(self noAssignmentAllowed:'assignment to pseudo variable ''super''' at:pos) ifFalse:[ |
|
6162 |
^ #Error |
|
6163 |
]. |
|
6164 |
(classToCompileFor isNil or:[classToCompileFor superclass isNil]) ifTrue:[ |
|
6165 |
self warning:'superclass is (currently ?) nil' position:pos to:(pos + 4). |
|
6166 |
]. |
|
6167 |
superNode isNil ifTrue:[ |
|
6168 |
superNode := SuperNode value:selfValue inClass:classToCompileFor |
|
6169 |
]. |
|
6170 |
self markSelfFrom:pos to:pos+4. |
|
6171 |
^ superNode |
|
6172 |
! |
|
6173 |
||
1262 | 6174 |
primary_thisContext |
6175 |
"parse a thisContext primary; return a node-tree, or raise an Error." |
|
6176 |
||
6177 |
|pos| |
|
6178 |
||
6179 |
pos := tokenPosition. |
|
6180 |
||
6181 |
self nextToken. |
|
6182 |
(self noAssignmentAllowed:'assignment to pseudo variable ''thisContext''' at:pos) ifFalse:[ |
|
6183 |
^ #Error |
|
6184 |
]. |
|
6185 |
self markIdentifierFrom:pos to:pos+10. |
|
6186 |
^ VariableNode type:#ThisContext context:contextToEvaluateIn. "/ often nil |
|
6187 |
! |
|
6188 |
||
1227 | 6189 |
primary_true |
6190 |
"parse a true primary; return a node-tree, or raise an Error." |
|
6191 |
||
6192 |
|pos| |
|
6193 |
||
6194 |
pos := tokenPosition. |
|
6195 |
||
6196 |
self nextToken. |
|
6197 |
(self noAssignmentAllowed:'assignment to ''true''' at:pos) ifFalse:[ |
|
6198 |
^ #Error |
|
6199 |
]. |
|
6200 |
self markBooleanConstantFrom:pos to:pos+3. |
|
6201 |
^ ConstantNode type:#True value:true |
|
6202 |
! |
|
6203 |
||
924 | 6204 |
qualifiedName |
6205 |
"a vw3.x (and later) feature: QualifiedName is #{ id ... id } |
|
6206 |
and mapped to a global variable here. |
|
6207 |
The initial #{ is supposed to be not yet skipped." |
|
6208 |
||
1436 | 6209 |
|elements elem pos1 nm| |
924 | 6210 |
|
6211 |
pos1 := tokenPosition. |
|
6212 |
self nextToken. |
|
6213 |
elements := OrderedCollection new. |
|
1436 | 6214 |
[ tokenType ~~ $} ] whileTrue:[ |
6215 |
(tokenType == #Identifier) ifFalse:[ |
|
6216 |
self syntaxError:'bad qualifiedName; Identifier expected' |
|
924 | 6217 |
position:pos1 to:tokenPosition |
6218 |
]. |
|
1436 | 6219 |
elem := tokenName. |
924 | 6220 |
elements add:elem. |
1028 | 6221 |
|
6222 |
self nextToken. |
|
1436 | 6223 |
tokenType = $} ifTrue:[ |
1028 | 6224 |
] ifFalse:[ |
1436 | 6225 |
tokenType == #'::' ifTrue:[ |
6226 |
"/ notice that Foo.Bar has already been scanned as Foo::Bar |
|
6227 |
"/(which is a kludge) |
|
6228 |
self nextToken. |
|
6229 |
] ifFalse:[ |
|
1028 | 6230 |
self syntaxError:'bad qualifiedName syntax; ''.'' or ''}'' expected' |
6231 |
position:pos1 to:tokenPosition. |
|
6232 |
]. |
|
6233 |
]. |
|
1436 | 6234 |
|
6235 |
"/ elem := self variable. |
|
6236 |
"/ (elem == #Error) ifTrue:[ |
|
6237 |
"/ (tokenType == #EOF) ifTrue:[ |
|
6238 |
"/ self syntaxError:'unterminated qualifiedName; ''}'' expected' |
|
6239 |
"/ position:pos1 to:tokenPosition |
|
6240 |
"/ ]. |
|
6241 |
"/ ^ #Error |
|
6242 |
"/ ]. |
|
6243 |
"/ errorFlag := false. |
|
6244 |
"/ (elem isVariable and:[elem isGlobal]) ifFalse:[ |
|
6245 |
"/ self warning:'elements of a qualifiedName should be globalIdentifiers' |
|
6246 |
"/ position:pos1 to:tokenPosition |
|
6247 |
"/ ]. |
|
6248 |
"/ elements add:elem. |
|
6249 |
"/ |
|
6250 |
"/ self nextToken. |
|
6251 |
"/ tokenType == #'::' ifTrue:[ |
|
6252 |
"/ "/ notice that Foo.Bar has already been scanned as Foo::Bar |
|
6253 |
"/ "/(which is a kludge) |
|
6254 |
"/ self nextToken. |
|
6255 |
"/ ] ifFalse:[ |
|
6256 |
"/ tokenType ~~ $} ifTrue:[ |
|
6257 |
"/ self syntaxError:'bad qualifiedName syntax; ''.'' or ''}'' expected' |
|
6258 |
"/ position:pos1 to:tokenPosition. |
|
6259 |
"/ ^ #Error |
|
6260 |
"/ ]. |
|
6261 |
"/ ]. |
|
6262 |
]. |
|
1437 | 6263 |
nm := (elements asStringWith:'::') asSymbol. |
1436 | 6264 |
^ ConstantNode type:#Symbol value:nm |
6265 |
||
6266 |
"/ elements size > 1 ifTrue:[ |
|
6267 |
"/ self syntaxError:'Sorry: qualified names are not yet implemented.'. |
|
6268 |
"/ ]. |
|
6269 |
"/ ^ elements first. |
|
924 | 6270 |
|
6271 |
"Modified: / 14.4.1998 / 17:03:29 / cg" |
|
6272 |
! |
|
6273 |
||
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6274 |
squeakComputedArray |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6275 |
|expressions elem pos1| |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6276 |
|
1275
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6277 |
tokenType == $} ifTrue:[ |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6278 |
^ #() |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6279 |
]. |
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6280 |
|
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6281 |
pos1 := tokenPosition. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6282 |
expressions := OrderedCollection new:20. |
1275
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6283 |
[true] whileTrue:[ |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6284 |
elem := self expression. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6285 |
(elem == #Error) ifTrue:[ |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6286 |
(tokenType == #EOF) ifTrue:[ |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6287 |
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
|
6288 |
position:pos1 to:tokenPosition |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6289 |
]. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6290 |
^ #Error |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6291 |
]. |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6292 |
expressions add:elem. |
1277
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6293 |
tokenType == $. ifFalse:[ |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6294 |
^ expressions |
1277
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6295 |
]. |
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6296 |
self nextToken. |
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6297 |
tokenType == $} ifTrue:[ |
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6298 |
^ expressions |
f7c21ebe1520
squeak computed arrays again
Claus Gittinger <cg@exept.de>
parents:
1276
diff
changeset
|
6299 |
]. |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6300 |
]. |
1275
91a0eead9e0e
oops - stc bug workaround - scans keyword selectors
Claus Gittinger <cg@exept.de>
parents:
1274
diff
changeset
|
6301 |
"/ not reached |
894
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6302 |
! |
943b6d0d26b3
changes to support loading squeak code containing computed
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
6303 |
|
141 | 6304 |
unaryExpression |
6305 |
"parse a unary-expression; return a node-tree, nil or #Error" |
|
6306 |
||
1328 | 6307 |
|receiver| |
141 | 6308 |
|
1405
f888caa1f2d8
refactored primitive-decl parsing;
Claus Gittinger <cg@exept.de>
parents:
1400
diff
changeset
|
6309 |
receiver := self arrayIndexingExpression. |
141 | 6310 |
(receiver == #Error) ifTrue:[^ #Error]. |
1328 | 6311 |
^ self unaryExpressionFor:receiver |
6312 |
! |
|
6313 |
||
6314 |
unaryExpressionFor:receiverArg |
|
6315 |
"parse a unary-expression; return a node-tree, nil or #Error" |
|
6316 |
||
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6317 |
|receiver expr sel pos pos2 note lNr arguments| |
1328 | 6318 |
|
6319 |
receiver := receiverArg. |
|
6320 |
(receiver == #Error) ifTrue:[^ #Error]. |
|
1306
90f45715a0d7
optionally allow nil, true, false etc. as unary selector
Claus Gittinger <cg@exept.de>
parents:
1304
diff
changeset
|
6321 |
[ self isValidUnarySelector:tokenType ] whileTrue:[ |
663 | 6322 |
pos := tokenPosition. |
6323 |
pos2 := pos + tokenName size - 1. |
|
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6324 |
lNr := tokenLineNr. |
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
6325 |
sel := tokenName. |
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6326 |
|
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6327 |
self markSelector:sel from:pos to:pos2 receiverNode:receiver. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6328 |
|
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6329 |
self nextToken. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6330 |
tokenType == $( ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6331 |
allowSqueakExtensions == true ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6332 |
"/ croquet/squeak extension - c/java-style arguments |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6333 |
arguments := self functionCallArgList. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6334 |
"/ synthetic selector: foo[:[with:[with:[...]]]] |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6335 |
arguments notEmpty ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6336 |
sel := sel , ':'. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6337 |
arguments size - 1 timesRepeat:[ sel := sel , 'with:' ]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6338 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6339 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6340 |
expr := MessageNode receiver:receiver selector:sel args:arguments fold:foldConstants. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6341 |
expr isErrorNode ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6342 |
self parseError:(expr errorString) position:pos to:pos2. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6343 |
errorFlag := false. "ok, user wants it - so he'll get it" |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6344 |
expr := MessageNode receiver:receiver selector:sel args:arguments fold:nil. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6345 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6346 |
expr lineNumber:lNr. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6347 |
note := self plausibilityCheck:receiver. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6348 |
note notNil ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6349 |
self warning:note position:pos to:pos2 |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6350 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6351 |
parseForCode ifFalse:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6352 |
self rememberSelectorUsed:sel receiver:receiver |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6353 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6354 |
^ expr. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6355 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6356 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6357 |
|
1022 | 6358 |
sel := self selectorCheck:sel for:receiver position:pos to:pos2. |
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6359 |
expr := UnaryNode receiver:receiver selector:sel fold:foldConstants. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6360 |
expr isErrorNode ifTrue:[ |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6361 |
self parseError:(expr errorString) position:pos to:pos2. |
663 | 6362 |
errorFlag := false. "ok, user wants it - so he'll get it" |
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6363 |
expr := UnaryNode receiver:receiver selector:sel fold:nil. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6364 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6365 |
expr lineNumber:lNr. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6366 |
|
1193 | 6367 |
note := self plausibilityCheck:receiver. |
6368 |
note notNil ifTrue:[ |
|
6369 |
self warning:note position:pos to:pos2 |
|
6370 |
]. |
|
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
6371 |
parseForCode ifFalse:[ |
1531
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6372 |
self rememberSelectorUsed:sel receiver:receiver |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6373 |
]. |
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6374 |
|
47f714bc1981
squeak extension: c/java style arguments
Claus Gittinger <cg@exept.de>
parents:
1525
diff
changeset
|
6375 |
receiver := expr. "/ for next message |
141 | 6376 |
]. |
6377 |
^ receiver |
|
210
b22f4472833b
allow enable/disable of constantFolding
Claus Gittinger <cg@exept.de>
parents:
207
diff
changeset
|
6378 |
|
1032
f97183aecb4e
oops - super-send-doIt in a debugger used receivers class
Claus Gittinger <cg@exept.de>
parents:
1028
diff
changeset
|
6379 |
"Modified: / 6.2.2000 / 14:54:20 / cg" |
141 | 6380 |
! |
6381 |
||
6382 |
variable |
|
1028 | 6383 |
"parse a simple (i.e. non-namespace-access path) variable; |
6384 |
return a node-tree, nil or #Error. |
|
6385 |
Does not advance to next token. |
|
6386 |
If undefined, notify error and correct if user wants to" |
|
141 | 6387 |
|
864 | 6388 |
|v pos1 pos2| |
687 | 6389 |
|
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
6390 |
v := self variableOrError:tokenName. |
664 | 6391 |
(v ~~ #Error) ifTrue:[ |
663 | 6392 |
(v isMemberOf:VariableNode) ifTrue:[ |
687 | 6393 |
self markVariable:v. |
663 | 6394 |
]. |
6395 |
^ v |
|
6396 |
]. |
|
865 | 6397 |
|
687 | 6398 |
pos1 := tokenPosition. |
864 | 6399 |
pos2 := pos1+tokenName size-1. |
6400 |
self markUnknownIdentifierFrom:pos1 to:pos2. |
|
664 | 6401 |
|
1089 | 6402 |
parseForCode == true ifTrue:[ |
1337
b558251f5e77
function call is now compiled into an #eval: message
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
6403 |
v := self correctVariable:tokenName atPosition:pos1 to:pos2. |
1089 | 6404 |
(v ~~ #Error) ifTrue:[^ v]. |
6405 |
]. |
|
6406 |
||
6407 |
errorFlag := true. |
|
664 | 6408 |
|
141 | 6409 |
parseForCode ifFalse:[ |
1304
ade15708e7c1
undeclared variable handling was broken (to allow reference search)
penk
parents:
1301
diff
changeset
|
6410 |
self rememberGlobalUsed:(Smalltalk undeclaredPrefix) , tokenName. |
ade15708e7c1
undeclared variable handling was broken (to allow reference search)
penk
parents:
1301
diff
changeset
|
6411 |
self rememberGlobalUsed:tokenName. |
141 | 6412 |
] ifTrue:[ |
663 | 6413 |
tokenName first isLowercase ifTrue:[ |
6414 |
ImplicitSelfSends ifTrue:[ |
|
1271
47c443af9bb9
better code for squeak computed array;
Claus Gittinger <cg@exept.de>
parents:
1262
diff
changeset
|
6415 |
^ UnaryNode receiver:(self selfNode) selector:('__' , tokenName) asSymbol. |
663 | 6416 |
]. |
6417 |
^ #Error |
|
6418 |
] |
|
141 | 6419 |
]. |
865 | 6420 |
|
869 | 6421 |
"/ self markGlobalIdentifierFrom:pos1 to:pos2. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6422 |
^ VariableNode globalNamed:tokenName |
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
6423 |
|
687 | 6424 |
"Modified: / 16.4.1998 / 18:46:45 / cg" |
141 | 6425 |
! |
6426 |
||
0 | 6427 |
variableOrError |
1028 | 6428 |
"parse a simple (i.e. non-namespace-access path) variable; |
6429 |
return a node-tree, nil or #Error. |
|
6430 |
Does not advance to next token." |
|
0 | 6431 |
|
21 | 6432 |
^ self variableOrError:tokenName |
6433 |
! |
|
6434 |
||
6435 |
variableOrError:varName |
|
1028 | 6436 |
"parse a simple (i.e. non-namespace-access path) variable; |
6437 |
return a node-tree, nil or #Error. |
|
6438 |
Does not advance to next token." |
|
21 | 6439 |
|
1551 | 6440 |
|varIndex aClass searchBlock args vars sharedPools |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6441 |
tokenSymbol space classVarIndex holder node| |
0 | 6442 |
|
6443 |
"is it a block-arg or block-var ?" |
|
6444 |
searchBlock := currentBlock. |
|
6445 |
[searchBlock notNil] whileTrue:[ |
|
628 | 6446 |
vars := searchBlock variables. |
6447 |
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
|
6448 |
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
|
6449 |
varIndex ~~ 0 ifTrue:[ |
628 | 6450 |
^ VariableNode type:#BlockVariable |
6451 |
name:varName |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6452 |
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
|
6453 |
index:varIndex |
628 | 6454 |
block:searchBlock |
6455 |
from:currentBlock |
|
6456 |
]. |
|
6457 |
]. |
|
6458 |
||
6459 |
args := searchBlock arguments. |
|
6460 |
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
|
6461 |
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
|
6462 |
varIndex ~~ 0 ifTrue:[ |
628 | 6463 |
^ VariableNode type:#BlockArg |
6464 |
name:varName |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6465 |
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
|
6466 |
index:varIndex |
628 | 6467 |
block:searchBlock |
6468 |
from:currentBlock |
|
6469 |
]. |
|
6470 |
||
6471 |
]. |
|
6472 |
||
6473 |
searchBlock := searchBlock home |
|
0 | 6474 |
]. |
6475 |
||
6476 |
"is it a method-variable ?" |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6477 |
(node := self nodeForMethodVariable:varName) notNil |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6478 |
ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6479 |
^ node |
0 | 6480 |
]. |
6481 |
||
6482 |
"is it a method-argument ?" |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6483 |
(node := self nodeForMethodArg:varName) notNil |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6484 |
ifTrue:[ |
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6485 |
^ node |
0 | 6486 |
]. |
6487 |
||
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6488 |
contextToEvaluateIn notNil ifTrue:[ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6489 |
|con varNames| |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6490 |
|
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6491 |
"/ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6492 |
"/ 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
|
6493 |
"/ |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6494 |
con := contextToEvaluateIn. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6495 |
[con notNil] whileTrue:[ |
1446
ac887ee4881a
** changed access to blockContexts source, args and vars -- please watch out
penk
parents:
1445
diff
changeset
|
6496 |
varNames := con argAndVarNames. |
690 | 6497 |
varNames size > 0 ifTrue:[ |
6498 |
varIndex := varNames lastIndexOf:varName. |
|
6499 |
varIndex ~~ 0 ifTrue:[ |
|
6500 |
^ VariableNode type:#ContextVariable |
|
6501 |
name:varName |
|
6502 |
context:con |
|
6503 |
index:varIndex |
|
6504 |
]. |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6505 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6506 |
con := con home. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6507 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6508 |
]. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6509 |
|
0 | 6510 |
classToCompileFor notNil ifTrue:[ |
628 | 6511 |
"is it an instance-variable ?" |
6512 |
||
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6513 |
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
|
6514 |
varIndex ~~ 0 ifTrue:[ |
628 | 6515 |
classToCompileFor isMeta ifTrue:[ |
6516 |
classVarIndex := (self classesClassVarNames) lastIndexOf:varName. |
|
6517 |
classVarIndex ~~ 0 ifTrue:[ |
|
6518 |
"/ give a warning - that maybe a common error |
|
825 | 6519 |
alreadyWarnedClassInstVarRefs isNil ifTrue:[ |
6520 |
alreadyWarnedClassInstVarRefs := Set new |
|
6521 |
]. |
|
6522 |
(alreadyWarnedClassInstVarRefs includes:varName) ifFalse:[ |
|
6523 |
self warning:('there is both a class variable and a class-instance variable named ''' , varName , '''.\\Refering to the class-instance variable here.') withCRs. |
|
6524 |
alreadyWarnedClassInstVarRefs add:varName. |
|
6525 |
]. |
|
628 | 6526 |
]. |
6527 |
]. |
|
6528 |
parseForCode ifFalse:[self rememberInstVarUsed:varName]. |
|
6529 |
^ VariableNode type:#InstanceVariable |
|
6530 |
name:varName |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6531 |
index:varIndex |
628 | 6532 |
selfValue:selfValue |
6533 |
]. |
|
6534 |
||
6535 |
"/ see if there is a corresponding classVar (for the warning) |
|
6536 |
classVarIndex := (self classesClassVarNames) lastIndexOf:varName. |
|
6537 |
||
6538 |
"/ "is it a class-instance-variable ?" |
|
6539 |
"/ |
|
6540 |
"/ Notice: |
|
6541 |
"/ it is no longer allowed to fetch class-instance variables |
|
6542 |
"/ from instance methods ... |
|
6543 |
"/ (used to be in previous ST/X versions) |
|
6544 |
"/ |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6545 |
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
|
6546 |
varIndex ~~ 0 ifTrue:[ |
628 | 6547 |
aClass := self inWhichClassIsClassInstVar:varName. |
6548 |
aClass notNil ifTrue:[ |
|
6549 |
classToCompileFor isMeta ifFalse:[ |
|
6550 |
classVarIndex == 0 ifTrue:[ |
|
705
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6551 |
"/ there is no corresponding classVar; |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6552 |
"/ wants to access classInstVar ? |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6553 |
contextToEvaluateIn notNil ifTrue:[ |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6554 |
"/ allow it in a doIt ... |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6555 |
|
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6556 |
^ VariableNode type:#ClassInstanceVariable |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6557 |
name:varName |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6558 |
index:varIndex |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6559 |
selfClass:aClass |
e22927413fe5
allow access to class-instVars from doIts;
Claus Gittinger <cg@exept.de>
parents:
694
diff
changeset
|
6560 |
]. |
628 | 6561 |
self parseError:'access to class-inst-var from inst method is not allowed'. |
6562 |
^ #Error. |
|
6563 |
] ifFalse:[ |
|
6564 |
"/ give a warning - that maybe a common error |
|
738 | 6565 |
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 | 6566 |
] |
6567 |
]. |
|
6568 |
||
6569 |
"/ OLD CODE: |
|
6570 |
"/ 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
|
6571 |
"/ |
628 | 6572 |
"/ parseForCode ifFalse:[self rememberClassVarUsed:varName]. |
6573 |
"/ ^ VariableNode type:#ClassInstanceVariable |
|
6574 |
"/ name:varName |
|
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6575 |
"/ index:varIndex |
628 | 6576 |
"/ selfClass:aClass |
6577 |
"/ ]. |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6578 |
] ifFalse:[ |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6579 |
"/ self halt:'oops - should not happen'. |
628 | 6580 |
] |
6581 |
]. |
|
6582 |
||
6583 |
"is it a class-variable ?" |
|
6584 |
||
640
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6585 |
varIndex := classVarIndex. |
c3be1ba89df0
handle passed-in context (for evaluation in the debuggers code-frame)
Claus Gittinger <cg@exept.de>
parents:
637
diff
changeset
|
6586 |
varIndex ~~ 0 ifTrue:[ |
628 | 6587 |
aClass := self inWhichClassIsClassVar:varName. |
6588 |
aClass notNil ifTrue:[ |
|
6589 |
parseForCode ifFalse:[self rememberClassVarUsed:varName]. |
|
6590 |
^ 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
|
6591 |
]. |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
6592 |
"/ self halt:'oops - should not happen'. |
628 | 6593 |
]. |
6594 |
||
6595 |
"is it a private-class ?" |
|
6596 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
6597 |
aClass := self classToLookForClassVars. |
1212
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6598 |
aClass := aClass theNonMetaclass. |
628 | 6599 |
(aClass privateClassesAt:varName) notNil ifTrue:[ |
6600 |
parseForCode ifFalse:[self rememberGlobalUsed:(aClass name , '::' , varName)]. |
|
6601 |
^ VariableNode type:#PrivateClass class:aClass name:varName |
|
6602 |
]. |
|
1551 | 6603 |
|
6604 |
" is it a pool-variable ?" |
|
6605 |
sharedPools := classToCompileFor theNonMetaclass sharedPools. |
|
6606 |
sharedPools notNil ifTrue:[ |
|
6607 |
sharedPools do:[:eachPoolName | |
|
6608 |
|sharedPool| |
|
6609 |
||
6610 |
sharedPool := Smalltalk classNamed:eachPoolName. |
|
1556 | 6611 |
sharedPool isNil ifTrue:[ |
6612 |
self warning:('No such pool: ' , eachPoolName). |
|
6613 |
] ifFalse:[ |
|
6614 |
(sharedPool includesKey:varName) ifTrue:[ |
|
6615 |
parseForCode ifFalse:[self rememberGlobalUsed:(sharedPool name , ':' , varName)]. |
|
6616 |
^ VariableNode type:#PoolVariable class:sharedPool name:varName |
|
6617 |
]. |
|
1551 | 6618 |
]. |
6619 |
]. |
|
6620 |
]. |
|
418 | 6621 |
]. |
6622 |
||
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6623 |
"is it in a namespace ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6624 |
space := self findNameSpaceWith:varName. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6625 |
space notNil ifTrue:[ |
628 | 6626 |
space ~~ Smalltalk ifTrue:[ |
6627 |
parseForCode ifFalse:[self rememberGlobalUsed:(space name , '::' , varName)]. |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
6628 |
space isNameSpace ifTrue:[ |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6629 |
^ VariableNode globalNamed:(space name , '::' , varName) |
1212
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6630 |
]. |
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6631 |
^ VariableNode type:#PrivateClass class:space name:varName |
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6632 |
]. |
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6633 |
parseForCode ifFalse:[self rememberGlobalUsed:varName]. |
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6634 |
^ VariableNode globalNamed:varName |
454
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
6635 |
]. |
00a079c9832f
handle uses: usedNameSpace info
Claus Gittinger <cg@exept.de>
parents:
451
diff
changeset
|
6636 |
|
0 | 6637 |
"is it a global-variable ?" |
63 | 6638 |
tokenSymbol := varName asSymbolIfInterned. |
6639 |
tokenSymbol notNil ifTrue:[ |
|
628 | 6640 |
(Smalltalk includesKey:tokenSymbol) ifTrue:[ |
6641 |
parseForCode ifFalse:[self rememberGlobalUsed:varName]. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
6642 |
^ VariableNode globalNamed:tokenSymbol |
628 | 6643 |
] |
0 | 6644 |
]. |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
6645 |
|
877 | 6646 |
"is it a workspace variable ?" |
6647 |
(requestor notNil and:[requestor isStream not]) ifTrue:[ |
|
6648 |
"/ when parsing doits, this is done twice; |
|
6649 |
"/ first, for the parse, then as a block-code |
|
6650 |
"/ for the code. |
|
6651 |
"/ We only care for WorkspaceVars in doIts |
|
1440 | 6652 |
(self isDoIt) ifTrue:[ |
1295 | 6653 |
(Workspace notNil |
6654 |
and:[(holder := Workspace workspaceVariableAt:varName) notNil]) |
|
6655 |
ifTrue:[ |
|
6656 |
^ VariableNode type:#WorkspaceVariable holder:holder name:varName |
|
877 | 6657 |
] |
6658 |
] |
|
6659 |
]. |
|
1295 | 6660 |
"is it a doIt variable ?" |
6661 |
||
6662 |
"/ (requestor notNil and:[requestor isStream not]) ifTrue:[ |
|
6663 |
"/ when parsing doits, this is done twice; |
|
6664 |
"/ first, for the parse, then as a block-code |
|
6665 |
"/ for the code. |
|
6666 |
"/ We only care for WorkspaceVars in doIts |
|
6667 |
||
1440 | 6668 |
(self isDoIt) ifTrue:[ |
1295 | 6669 |
(doItTemporaries notNil |
6670 |
and:[(holder := doItTemporaries at:varName asSymbol ifAbsent:nil) notNil]) |
|
6671 |
ifTrue:[ |
|
6672 |
^ VariableNode type:#DoItTemporary holder:holder name:varName |
|
6673 |
] |
|
6674 |
]. |
|
6675 |
"/ ]. |
|
0 | 6676 |
^ #Error |
1212
082618467e2c
isMeta/soleInstance -> theMetaclass / theNonMetaclass
Claus Gittinger <cg@exept.de>
parents:
1207
diff
changeset
|
6677 |
"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
|
6678 |
! ! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6679 |
|
1410 | 6680 |
!Parser methodsFor:'parsing-primitives & pragmas'! |
6681 |
||
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6682 |
checkForClosingAngle |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6683 |
((tokenType == #BinaryOperator) and:[tokenName = '>']) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6684 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6685 |
] ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6686 |
self parseError:'bad primitive definition (''>'' expected)'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6687 |
] |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6688 |
! |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6689 |
|
1551 | 6690 |
parseExternalFunctionCallDeclaration |
6691 |
|callType cString cStream cParser returnType |
|
6692 |
functionName argTypes moduleName fn node args sel |
|
6693 |
stmt| |
|
6694 |
||
6695 |
"/ apiType is one of C: / cdecl: / api: / apicall: |
|
6696 |
callType := tokenName. |
|
1410 | 6697 |
|
6698 |
cString := source upTo:$>. |
|
6699 |
self nextToken. |
|
6700 |
cStream := cString readStream. |
|
6701 |
||
1551 | 6702 |
CParser isNil ifTrue:[ |
6703 |
self parseError:'no parser for cdecl'. |
|
1410 | 6704 |
^ -1 |
6705 |
]. |
|
1551 | 6706 |
|
6707 |
callType = 'cdecl:' ifTrue:[ |
|
6708 |
cParser := CParser new. |
|
6709 |
cParser source:cStream scannerClass:CDeclScanner. |
|
6710 |
cParser nextToken. |
|
6711 |
returnType := cParser type. |
|
6712 |
||
6713 |
cParser tokenType ~~ #String ifTrue:[ |
|
6714 |
self parseError:'invalid cdecl - functionName expected'. |
|
6715 |
^ -1 |
|
6716 |
]. |
|
6717 |
functionName := cParser token. |
|
6718 |
cParser nextToken. |
|
6719 |
argTypes := cParser parseFunctionArgumentSpec. |
|
6720 |
||
6721 |
(cParser tokenType == #Identifier and:[cParser token = 'module']) ifTrue:[ |
|
6722 |
cParser nextToken. |
|
6723 |
cParser tokenType ~~ $: ifTrue:[ |
|
6724 |
self parseError:'colon expected'. |
|
6725 |
^ -1 |
|
6726 |
]. |
|
6727 |
cParser nextToken. |
|
6728 |
cParser tokenType ~~ #String ifTrue:[ |
|
6729 |
self parseError:'invalid cdecl - moduleName expected'. |
|
6730 |
^ -1 |
|
6731 |
]. |
|
6732 |
moduleName := cParser token. |
|
6733 |
]. |
|
6734 |
argTypes size == 1 ifTrue:[ |
|
6735 |
argTypes first isCVoid ifTrue:[ |
|
6736 |
argTypes := #() |
|
6737 |
]. |
|
6738 |
]. |
|
6739 |
argTypes size ~~ methodArgNames size ifTrue:[ |
|
6740 |
self parseError:'number of method args does not match function arg list'. |
|
6741 |
]. |
|
6742 |
fn := ExternalLibraryFunction |
|
6743 |
name:functionName |
|
6744 |
module:moduleName |
|
6745 |
callType:callType |
|
6746 |
returnType:returnType |
|
6747 |
argumentTypes:argTypes. |
|
6748 |
||
6749 |
node := ConstantNode type:nil value:fn. |
|
6750 |
args := (methodArgNames ? #()) collect:[:eachArgName | node := self nodeForMethodArg:eachArgName]. |
|
6751 |
sel := #( |
|
6752 |
#invoke |
|
6753 |
#invokeWith: |
|
6754 |
#invokeWith:with: |
|
6755 |
#invokeWith:with:with: |
|
6756 |
#invokeWith:with:with:with: |
|
6757 |
#invokeWith:with:with:with:with: |
|
6758 |
#invokeWith:with:with:with:with:with: |
|
6759 |
#invokeWith:with:with:with:with:with:with: |
|
6760 |
) at:args size+1 ifAbsent:nil. |
|
6761 |
sel isNil ifTrue:[ |
|
6762 |
sel := #'invokeWithArguments:'. |
|
6763 |
self halt. |
|
6764 |
||
6765 |
]. |
|
6766 |
node := MessageNode receiver:node selector:sel args:args fold:false. |
|
6767 |
stmt := StatementNode new expression:node. |
|
6768 |
tree := stmt. |
|
6769 |
self isSyntaxHighlighter ifFalse:[ self halt ]. |
|
6770 |
"/ TODO: generate that ffi-calling code ... |
|
6771 |
^ -1 |
|
6772 |
]. |
|
6773 |
||
6774 |
self parseError:'unsupported external function call type: ' , callType. |
|
1410 | 6775 |
^ -1 |
1551 | 6776 |
|
6777 |
" |
|
6778 |
(Parser for:'foo <cdecl: void ''glFlush'' (void) module: ''GL''>') |
|
6779 |
nextToken; |
|
6780 |
parseMethod |
|
6781 |
" |
|
1410 | 6782 |
! |
6783 |
||
6784 |
parsePrimitive |
|
6785 |
"parse an ST-80 type primitive as '< primitive: nr >'; |
|
6786 |
return primitive number or #Error. |
|
6787 |
or a Squeak-style primitive, as '< primitive: string >'; |
|
6788 |
return primitive name or #Error. |
|
6789 |
||
6790 |
Also, ST-80 style resource specs are parsed; the result is |
|
6791 |
left (as side effect) in primitiveResource. |
|
6792 |
(maybe someone else knows what to do with it ...) |
|
6793 |
Well, as we now have this mechanism, I'll use it to mark methods which |
|
6794 |
do keyboard processing ... <resource: keyboard ( keys )> |
|
6795 |
For faster finding of used keyboard accelerators, |
|
6796 |
and to mark resource methods (image, menu or canvas resources). |
|
6797 |
||
6798 |
prim ::= st80Primitive | st80Pragma | stxPragma |
|
6799 |
squeakPrimitive | newSTXPrimitive | resourceDecl |
|
6800 |
||
6801 |
st80Primitive ::= 'primitive:' INTEGER |
|
6802 |
st80Pragma ::= 'exception:' ( 'handle | 'raise' | 'unwind' ) |
|
6803 |
stxPragma ::= 'context:' 'return' |
|
6804 |
||
6805 |
squeakPrimitive ::= 'primitive:' STRING |
|
6806 |
||
6807 |
newSTXPrimitive ::= 'primitive' |
|
6808 |
||
6809 |
resourceDecl ::= 'resource:' SYMBOL - leave SYMBOL in primitiveResource |
|
6810 |
| 'resource:' SYMBOL (...) - leave (SYMBOL (...)) in primitiveResource |
|
6811 |
" |
|
6812 |
||
6813 |
(tokenType == #Keyword or:[tokenType == #Identifier]) ifFalse:[ |
|
6814 |
self parseError:'bad primitive definition (keyword expected)'. |
|
6815 |
^ #Error |
|
6816 |
]. |
|
6817 |
||
6818 |
(tokenName = 'primitive:') ifTrue:[ |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6819 |
^ self parseTraditionalPrimitive. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6820 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6821 |
(tokenName = 'primitive') ifTrue:[ |
1410 | 6822 |
self nextToken. |
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6823 |
self checkForClosingAngle. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6824 |
^ 0. "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6825 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6826 |
(tokenName = 'resource:') ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6827 |
self parseResourcePragma. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6828 |
^ nil. "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6829 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6830 |
(tokenName = 'exception:' |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6831 |
or:[tokenName = 'context:']) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6832 |
self parseExceptionOrContextPragma. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6833 |
self checkForClosingAngle. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6834 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6835 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6836 |
(tokenName = 'C:') ifTrue:[ |
1551 | 6837 |
self parseExternalFunctionCallDeclaration. |
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6838 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6839 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6840 |
(tokenName = 'api:') ifTrue:[ |
1551 | 6841 |
self parseExternalFunctionCallDeclaration. |
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6842 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6843 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6844 |
(tokenName = 'apicall:') ifTrue:[ |
1551 | 6845 |
self parseExternalFunctionCallDeclaration. |
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6846 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6847 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6848 |
(tokenName = 'cdecl:') ifTrue:[ |
1551 | 6849 |
self parseExternalFunctionCallDeclaration. |
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6850 |
^ nil "/ no primitive number |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6851 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6852 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6853 |
self parseError:'unrecognized pragma: ' , tokenName. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6854 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6855 |
"/ skip |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6856 |
[tokenType ~~ #EOF] whileTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6857 |
((tokenType == #BinaryOperator) and:[tokenName = '>']) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6858 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6859 |
^ nil "/ no primitive number |
1410 | 6860 |
]. |
6861 |
self nextToken. |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6862 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6863 |
^ nil "/ no primitive number |
1410 | 6864 |
! |
6865 |
||
6866 |
parsePrimitiveOrResourceSpecOrEmpty |
|
6867 |
"parse a methods primitive or resource spec" |
|
6868 |
||
6869 |
|pos wmsg primNr primNrOrString| |
|
6870 |
||
6871 |
[(tokenType == #BinaryOperator) and:[tokenName = '<']] whileTrue:[ |
|
6872 |
pos := tokenPosition. |
|
6873 |
self nextToken. |
|
6874 |
primNrOrString := self parsePrimitive. |
|
6875 |
||
6876 |
(primNrOrString == #Error) ifTrue:[^ #Error]. |
|
6877 |
wmsg := nil. |
|
6878 |
||
6879 |
primNrOrString isString ifTrue:[ |
|
6880 |
primNr := self primitiveNumberFromName:primNrOrString |
|
6881 |
] ifFalse:[ |
|
6882 |
primNr := primNrOrString |
|
6883 |
]. |
|
6884 |
||
6885 |
primNr notNil ifTrue:[ |
|
6886 |
primNr < 0 ifTrue:[ |
|
6887 |
WarnST80Directives == true ifTrue:[ |
|
6888 |
wmsg := 'ST-80/Squeak directive ignored'. |
|
6889 |
]. |
|
6890 |
] ifFalse:[ |
|
6891 |
primNr > 0 ifTrue:[ |
|
6892 |
primitiveNr := primNr. |
|
6893 |
wmsg := 'ST-80 primitive may not work' |
|
6894 |
] ifFalse:[ |
|
6895 |
primitiveNr := primNr. |
|
6896 |
wmsg := 'ST/X primitives only work in rel5 and newer' |
|
6897 |
] |
|
6898 |
]. |
|
1551 | 6899 |
wmsg notNil ifTrue:[self warning:wmsg position:pos] |
6900 |
]. |
|
1410 | 6901 |
]. |
6902 |
||
6903 |
"Created: 27.4.1996 / 16:55:55 / cg" |
|
6904 |
"Modified: 29.5.1996 / 17:25:52 / cg" |
|
6905 |
! |
|
6906 |
||
6907 |
parseResourcePragma |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6908 |
" '< resource:' has already been parsed." |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6909 |
|
1410 | 6910 |
|keys resource resourceValue| |
6911 |
||
6912 |
self nextToken. |
|
6913 |
(tokenType ~~ #Symbol) ifTrue:[ |
|
6914 |
self parseError:'symbol expected'. |
|
6915 |
^ #Error |
|
6916 |
]. |
|
6917 |
||
6918 |
resource := tokenValue. |
|
6919 |
resourceValue := true. |
|
6920 |
||
6921 |
self nextToken. |
|
6922 |
||
6923 |
tokenType == $( ifTrue:[ |
|
6924 |
self nextToken. |
|
6925 |
keys := OrderedCollection new. |
|
6926 |
[(tokenType == $)) or:[tokenType == #EOF] ] whileFalse:[ |
|
6927 |
keys add:tokenValue. |
|
6928 |
self nextToken. |
|
6929 |
]. |
|
6930 |
resourceValue := keys. |
|
6931 |
(tokenType == $)) ifFalse:[ |
|
6932 |
self parseError:'unterminated primitive/spec (missing '')'')'. |
|
6933 |
]. |
|
6934 |
self nextToken. |
|
6935 |
]. |
|
6936 |
||
6937 |
primitiveResource isNil ifTrue:[ |
|
6938 |
primitiveResource := IdentityDictionary new. |
|
6939 |
]. |
|
6940 |
primitiveResource at:(resource asSymbol) put:resourceValue. |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6941 |
self checkForClosingAngle. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6942 |
! |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6943 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6944 |
parseTraditionalPrimitive |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6945 |
"parse everything after the initial '<primitive:'" |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6946 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6947 |
|primNumber| |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6948 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6949 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6950 |
(tokenType == #Integer) ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6951 |
allowSqueakExtensions ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6952 |
(tokenType == #String) ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6953 |
self parseError:'primitive number or name expected'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6954 |
^ #Error |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6955 |
] |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6956 |
] ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6957 |
self parseError:'primitive number expected'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6958 |
^ #Error |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6959 |
] |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6960 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6961 |
primitiveNr notNil ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6962 |
self parseError:'only one primitive spec allowed'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6963 |
primNumber := -1. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6964 |
] ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6965 |
primNumber := tokenValue. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6966 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6967 |
self nextToken. |
1556 | 6968 |
|
6969 |
(tokenType == #Keyword) ifTrue:[ |
|
6970 |
(tokenName = 'errorCode:') ifTrue:[ |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6971 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6972 |
(tokenType == #Identifier) ifTrue:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6973 |
self nextToken. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6974 |
] ifFalse:[ |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6975 |
self error:'not yet implemented'. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6976 |
] |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6977 |
]. |
1556 | 6978 |
(tokenName = 'module:') ifTrue:[ |
6979 |
self nextToken. |
|
6980 |
(tokenType == #String) ifTrue:[ |
|
6981 |
self nextToken. |
|
6982 |
] ifFalse:[ |
|
6983 |
self error:'not yet implemented'. |
|
6984 |
] |
|
6985 |
]. |
|
1420
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6986 |
]. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6987 |
|
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6988 |
self checkForClosingAngle. |
57f3f5c8a070
more for exotic primitives/pragmas
Claus Gittinger <cg@exept.de>
parents:
1419
diff
changeset
|
6989 |
^ primNumber |
1410 | 6990 |
! |
6991 |
||
6992 |
primitiveNumberFromName:aPrimitiveName |
|
6993 |
"for future compatibility with Squeak ..." |
|
6994 |
||
6995 |
^ nil |
|
6996 |
! ! |
|
6997 |
||
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6998 |
!Parser methodsFor:'private'! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
6999 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7000 |
currentNameSpace |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7001 |
|spc| |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7002 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7003 |
spc := currentNamespace. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7004 |
spc isNil ifTrue:[ |
832
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
7005 |
(requestor respondsTo:#currentNameSpace) ifTrue:[ |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
7006 |
spc := requestor currentNameSpace |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
7007 |
] ifFalse:[ |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
7008 |
spc := Class nameSpaceQuerySignal query. |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
7009 |
]. |
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
7010 |
currentNamespace := spc. |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7011 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7012 |
^ spc |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7013 |
|
832
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
7014 |
"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
|
7015 |
"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
|
7016 |
"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
|
7017 |
! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7018 |
|
492
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
7019 |
currentNameSpace:aNameSpace |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
7020 |
currentNamespace := aNameSpace. |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
7021 |
|
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
7022 |
"Created: 8.2.1997 / 19:37:03 / cg" |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
7023 |
! |
fe778fd0ce46
additional entry, passing the namespace
Claus Gittinger <cg@exept.de>
parents:
489
diff
changeset
|
7024 |
|
1247
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7025 |
currentPackage |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7026 |
|pkg| |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7027 |
|
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7028 |
pkg := currentPackage. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7029 |
pkg isNil ifTrue:[ |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7030 |
(requestor respondsTo:#currentPackage) ifTrue:[ |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7031 |
pkg := requestor currentPackage |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7032 |
] ifFalse:[ |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7033 |
pkg := Class packageQuerySignal query. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7034 |
]. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7035 |
currentPackage := pkg. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7036 |
]. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7037 |
^ pkg |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7038 |
! |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7039 |
|
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7040 |
currentPackage:aPackageName |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7041 |
currentPackage := aPackageName. |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7042 |
! |
ce0d19140248
care for package directive (remember)
Claus Gittinger <cg@exept.de>
parents:
1246
diff
changeset
|
7043 |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7044 |
currentUsedNameSpaces |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7045 |
|spaces| |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7046 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7047 |
spaces := currentUsedNamespaces. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7048 |
spaces isNil ifTrue:[ |
679
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7049 |
(requestor respondsTo:#usedNameSpaces) ifTrue:[ |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7050 |
spaces := requestor usedNameSpaces |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7051 |
] ifFalse:[ |
832
553c25252a78
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
825
diff
changeset
|
7052 |
spaces := Class usedNameSpaceQuerySignal query. |
679
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7053 |
]. |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7054 |
spaces isNil ifTrue:[ |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7055 |
spaces := #() |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7056 |
]. |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7057 |
currentUsedNamespaces := spaces. |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7058 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7059 |
^ spaces |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7060 |
|
679
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7061 |
"Created: / 19.12.1996 / 23:49:10 / cg" |
6a60e6d0ccd1
avoid redoing work in #currentUsedNameSpaces
Claus Gittinger <cg@exept.de>
parents:
673
diff
changeset
|
7062 |
"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
|
7063 |
"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
|
7064 |
! |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7065 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7066 |
findNameSpaceWith:aVariableName |
692 | 7067 |
|ns currentSpace usedSpaces| |
486
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
7068 |
|
e894035d5223
fixed name resolving for private classes when accessing
Claus Gittinger <cg@exept.de>
parents:
481
diff
changeset
|
7069 |
"/ 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
|
7070 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7071 |
classToCompileFor notNil ifTrue:[ |
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7072 |
"/ Q: |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7073 |
"/ consider private classes of superclasses. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7074 |
"/ 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
|
7075 |
|
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7076 |
"/ 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
|
7077 |
"/ known to the corresponding ownerClass. |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7078 |
|
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7079 |
"is it in the classes namespace ?" |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7080 |
|
1315 | 7081 |
ns := classToCompileFor topNameSpace. |
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7082 |
(ns notNil |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7083 |
and:[ns ~~ Smalltalk]) ifTrue:[ |
1142 | 7084 |
ns isNameSpace ifTrue:[ |
7085 |
(ns at:aVariableName) notNil ifTrue:[ |
|
7086 |
^ ns |
|
7087 |
] |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7088 |
] |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7089 |
]. |
494
bb3e71c90dfd
currentClasses nameSpace is first to look for globals.
Claus Gittinger <cg@exept.de>
parents:
493
diff
changeset
|
7090 |
|
495 | 7091 |
"/ ns := classToCompileFor nameSpace. |
7092 |
"/ ns notNil ifTrue:[ |
|
7093 |
"/ "is it in the current classes namespace ?" |
|
7094 |
"/ (ns at:aVariableName asSymbol) notNil ifTrue:[ |
|
7095 |
"/ ^ ns |
|
7096 |
"/ ] |
|
7097 |
"/ ]. |
|
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7098 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7099 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7100 |
"is it in the current namespace ?" |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7101 |
currentSpace := self currentNameSpace. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7102 |
(currentSpace notNil |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7103 |
and:[currentSpace ~~ Smalltalk]) ifTrue:[ |
1043 | 7104 |
currentSpace isNameSpace ifTrue:[ |
7105 |
(currentSpace at:aVariableName) notNil ifTrue:[ |
|
7106 |
^ currentSpace |
|
7107 |
] |
|
7108 |
] ifFalse:[ |
|
7109 |
(currentSpace privateClassesAt:aVariableName) notNil ifTrue:[ |
|
7110 |
^ currentSpace |
|
7111 |
] |
|
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7112 |
] |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7113 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7114 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7115 |
"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
|
7116 |
usedSpaces := self currentUsedNameSpaces. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7117 |
usedSpaces notNil ifTrue:[ |
1042
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7118 |
usedSpaces do:[:aNameSpace | |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7119 |
(aNameSpace at:aVariableName) notNil ifTrue:[ |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7120 |
^ aNameSpace |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7121 |
] |
d192446cb745
fixed qualifiedName handling (as array constant)
Claus Gittinger <cg@exept.de>
parents:
1041
diff
changeset
|
7122 |
] |
455
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7123 |
]. |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7124 |
^ nil |
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7125 |
|
2e234d3bc96d
fixed parsing of private classes within a nameSpace
Claus Gittinger <cg@exept.de>
parents:
454
diff
changeset
|
7126 |
"Created: 19.12.1996 / 23:51:02 / cg" |
619 | 7127 |
"Modified: 14.10.1997 / 20:56:35 / cg" |
713 | 7128 |
! |
7129 |
||
1327 | 7130 |
implementedInAnyClass:selector |
7131 |
Smalltalk allClassesAndMetaclassesDo:[:cls | |
|
1518 | 7132 |
(cls includesSelector:selector) ifTrue:[^ true]. |
1327 | 7133 |
]. |
7134 |
^ false |
|
7135 |
! |
|
7136 |
||
713 | 7137 |
inWhichClassIsClassInstVar:aString |
7138 |
"search class-chain for the class-instance variable named aString |
|
7139 |
- return the class or nil if not found" |
|
7140 |
||
7141 |
|aClass| |
|
7142 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7143 |
aClass := self classToLookForClassVars. |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7144 |
|
713 | 7145 |
[aClass notNil] whileTrue:[ |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7146 |
(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
|
7147 |
aClass := aClass superclass |
713 | 7148 |
]. |
7149 |
^ nil |
|
7150 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7151 |
"Modified: / 18.6.1998 / 15:45:34 / cg" |
713 | 7152 |
! |
7153 |
||
7154 |
inWhichClassIsClassVar:aString |
|
7155 |
"search class-chain for the classvariable named aString |
|
7156 |
- return the class or nil if not found" |
|
7157 |
||
7158 |
|aClass className baseClass| |
|
7159 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7160 |
aClass := self classToLookForClassVars. |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7161 |
|
713 | 7162 |
aClass isMeta ifTrue:[ |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7163 |
className := aClass name copyWithoutLast:6. |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7164 |
baseClass := Smalltalk at:(className asSymbol). |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7165 |
baseClass notNil ifTrue:[ |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7166 |
aClass := baseClass |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7167 |
] |
713 | 7168 |
]. |
7169 |
^ aClass whichClassDefinesClassVar:aString |
|
7170 |
||
7171 |
"/ [aClass notNil] whileTrue:[ |
|
7172 |
"/ (aClass classVarNames includes:aString) ifTrue:[ ^ aClass]. |
|
7173 |
"/ aClass := aClass superclass |
|
7174 |
"/ ]. |
|
7175 |
"/ ^ nil |
|
7176 |
||
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7177 |
"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
|
7178 |
"Modified: / 18.6.1998 / 15:45:29 / cg" |
787 | 7179 |
! |
7180 |
||
1512
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7181 |
isStatementAnUnconditionalReturn:aStatementNode |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7182 |
|expr selector block1 block2 stats1 stats2| |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7183 |
|
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7184 |
aStatementNode isReturnNode ifTrue:[^ true ]. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7185 |
((expr := aStatementNode expression) notNil |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7186 |
and:[expr isMessage]) ifTrue:[ |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7187 |
selector := expr selector. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7188 |
(selector == #'ifTrue:ifFalse:' or:[selector == #'ifFalse:ifTrue:']) ifTrue:[ |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7189 |
block1 := expr arg1. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7190 |
block2 := expr arguments at:2. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7191 |
(block1 isBlockNode and:[ block2 isBlockNode]) ifTrue:[ |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7192 |
stats1 := block1 statements. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7193 |
stats2 := block2 statements. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7194 |
(stats1 notEmptyOrNil and:[ stats2 notEmptyOrNil]) ifTrue:[ |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7195 |
^ (self isStatementAnUnconditionalReturn:stats1 last) |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7196 |
and:[self isStatementAnUnconditionalReturn:stats2 last] |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7197 |
]. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7198 |
]. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7199 |
]. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7200 |
]. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7201 |
^ false. |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7202 |
! |
52986e9b02af
better isReturn (used when checking for consistent return value)
Claus Gittinger <cg@exept.de>
parents:
1507
diff
changeset
|
7203 |
|
1262 | 7204 |
makeReferenceFor:aNode |
7205 |
|rec sel indexNode contextNode arg1 arg2| |
|
7206 |
||
7207 |
contextNode := VariableNode type:#ThisContext context:contextToEvaluateIn. |
|
7208 |
indexNode := ConstantNode type:#Integer value:aNode index. |
|
7209 |
||
7210 |
aNode isArgument ifTrue:[ |
|
7211 |
sel := #forArgument:in:. |
|
7212 |
arg1 := indexNode. |
|
7213 |
arg2 := contextNode. |
|
7214 |
] ifFalse:[ |
|
7215 |
aNode isLocal ifTrue:[ |
|
7216 |
sel := #forLocal:in:. |
|
7217 |
arg1 := indexNode. |
|
7218 |
arg2 := contextNode. |
|
7219 |
] ifFalse:[ |
|
7220 |
self parseError:'unsupported variable reference (must be local or argument)'. |
|
7221 |
^ aNode |
|
7222 |
] |
|
7223 |
]. |
|
7224 |
||
7225 |
parseForCode ifFalse:[self rememberGlobalUsed:'Reference']. |
|
1309
f85561a7b90e
preps for nonDeterministic and FD variables.
Claus Gittinger <cg@exept.de>
parents:
1306
diff
changeset
|
7226 |
rec := VariableNode globalNamed:'Reference'. |
1262 | 7227 |
|
7228 |
^ MessageNode receiver:rec selector:sel arg1:arg1 arg2:arg2. |
|
7229 |
! |
|
7230 |
||
1003
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7231 |
noAssignmentAllowed:eMsg at:pos |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7232 |
((tokenType == $_) or:[tokenType == #':=']) ifTrue:[ |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7233 |
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
|
7234 |
self isSyntaxHighlighter ifFalse:[ |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7235 |
^ false |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7236 |
]. |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7237 |
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
|
7238 |
]. |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7239 |
^ true |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7240 |
! |
37badd2eb5b0
dont stop syntaxHighlighting when a bad assignment is encountered
Claus Gittinger <cg@exept.de>
parents:
997
diff
changeset
|
7241 |
|
787 | 7242 |
plausibilityCheck:aNode |
1193 | 7243 |
|note| |
7244 |
||
7245 |
note := aNode plausibilityCheck. |
|
7246 |
note isNil ifTrue:[ |
|
7247 |
aNode isMessage ifTrue:[ |
|
7248 |
(contextToEvaluateIn isNil and:[selfValue isNil]) ifTrue:[ "/ do not check this for doits |
|
7249 |
aNode receiver isSuper ifTrue:[ |
|
1535 | 7250 |
aNode receiver isHere ifFalse:[ |
7251 |
aNode selector ~= selector ifTrue:[ |
|
7252 |
^ 'possible bad super message (selector should be same as in current method) ?' |
|
7253 |
] |
|
1193 | 7254 |
]. |
7255 |
]. |
|
7256 |
]. |
|
7257 |
]. |
|
7258 |
]. |
|
7259 |
^ note |
|
1262 | 7260 |
! |
7261 |
||
7262 |
selfNode |
|
7263 |
selfNode isNil ifTrue:[ |
|
7264 |
selfNode := SelfNode value:selfValue |
|
7265 |
]. |
|
7266 |
^ selfNode |
|
141 | 7267 |
! ! |
7268 |
||
7269 |
!Parser methodsFor:'queries'! |
|
7270 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7271 |
classToLookForClassVars |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7272 |
"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
|
7273 |
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
|
7274 |
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
|
7275 |
class of the receiver." |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7276 |
|
1160 | 7277 |
|m who| |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7278 |
|
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7279 |
contextToEvaluateIn notNil ifTrue:[ |
748 | 7280 |
m := contextToEvaluateIn method. |
7281 |
m notNil ifTrue:[ |
|
7282 |
who := contextToEvaluateIn method who. |
|
7283 |
who notNil ifTrue:[ |
|
7284 |
^ who methodClass. |
|
7285 |
] |
|
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7286 |
]. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7287 |
"/ mhmh - might be a doIt ... |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7288 |
]. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7289 |
^ classToCompileFor |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7290 |
|
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7291 |
"Created: / 18.6.1998 / 15:43:42 / cg" |
748 | 7292 |
"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
|
7293 |
! |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7294 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7295 |
classesClassInstVarNames |
141 | 7296 |
"caching allInstVarNames for next compilation saves time ..." |
7297 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7298 |
|names| |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7299 |
|
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7300 |
[ |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7301 |
|cls| |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7302 |
|
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7303 |
cls := self classToLookForClassVars. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7304 |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7305 |
(PrevClassInstVarNames isNil or:[PrevClass ~~ cls]) ifTrue:[ |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7306 |
PrevClass notNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7307 |
PrevClass removeDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7308 |
]. |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7309 |
PrevClass := cls. |
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7310 |
|
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7311 |
PrevClassInstVarNames := cls class allInstVarNames. |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7312 |
PrevClass addDependent:Parser. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7313 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7314 |
names := PrevClassInstVarNames. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7315 |
] valueUninterruptably. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7316 |
^ names |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7317 |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7318 |
"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
|
7319 |
"Modified: / 18.6.1998 / 15:44:41 / cg" |
0 | 7320 |
! |
7321 |
||
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7322 |
classesClassVarNames |
141 | 7323 |
"caching allClassVarNames for next compilation saves time ..." |
7324 |
||
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7325 |
|names| |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7326 |
|
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7327 |
[ |
735
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7328 |
|cls aClass| |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7329 |
|
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7330 |
cls := self classToLookForClassVars. |
4012fa1611b1
code cleanup & fix for doIt (implementing class)
Claus Gittinger <cg@exept.de>
parents:
733
diff
changeset
|
7331 |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7332 |
(PrevClassVarNames isNil or:[PrevClass ~~ cls]) ifTrue:[ |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7333 |
PrevClass notNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7334 |
PrevClass removeDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7335 |
]. |
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7336 |
aClass := PrevClass := cls. |
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7337 |
aClass isMeta ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7338 |
aClass := aClass soleInstance. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7339 |
aClass isNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7340 |
aClass := classToCompileFor |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7341 |
] |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7342 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7343 |
PrevClassVarNames := aClass allClassVarNames. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7344 |
PrevClass addDependent:Parser. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7345 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7346 |
names := PrevClassVarNames. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7347 |
] valueUninterruptably. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7348 |
^ names |
290
d1650b17b9e9
Change the name of a classes Metaclass from e.g. "SmallIntegerclass" to
Stefan Vogel <sv@exept.de>
parents:
285
diff
changeset
|
7349 |
|
732
c36e5ef1e6ce
oops - when evaluating in a context, classVars must be
Claus Gittinger <cg@exept.de>
parents:
725
diff
changeset
|
7350 |
"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
|
7351 |
"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
|
7352 |
"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
|
7353 |
! |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7354 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7355 |
classesInstVarNames |
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7356 |
"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
|
7357 |
|
694
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7358 |
|names| |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7359 |
|
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7360 |
[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7361 |
(PrevInstVarNames isNil or:[PrevClass ~~ classToCompileFor]) ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7362 |
PrevClass notNil ifTrue:[ |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7363 |
PrevClass removeDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7364 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7365 |
PrevClass := classToCompileFor. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7366 |
PrevInstVarNames := classToCompileFor allInstVarNames. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7367 |
PrevClassInstVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7368 |
PrevClassVarNames := nil. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7369 |
PrevClass addDependent:Parser |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7370 |
]. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7371 |
names := PrevInstVarNames |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7372 |
] valueUninterruptably. |
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7373 |
|
1ec57d3a2592
must manage the PrevClass cached instVars/classInstVars
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
7374 |
^ names |
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7375 |
|
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7376 |
"Created: 14.10.1996 / 18:00:26 / cg" |
0 | 7377 |
! |
7378 |
||
934
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
7379 |
contextMustBeReturnable |
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
7380 |
^ primitiveContextInfo notNil |
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
7381 |
and:[ ^ primitiveContextInfo includes:('context:' -> #return) ] |
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
7382 |
|
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
7383 |
|
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
7384 |
! |
716f9c76b06b
pass down returnable-context flag via method.
Claus Gittinger <cg@exept.de>
parents:
931
diff
changeset
|
7385 |
|
141 | 7386 |
hasNonOptionalPrimitiveCode |
7387 |
"return true if there was any ST/X style primitive code (valid after parsing)" |
|
7388 |
||
7389 |
^ hasNonOptionalPrimitiveCode |
|
0 | 7390 |
! |
7391 |
||
141 | 7392 |
hasPrimitiveCode |
7393 |
"return true if there was any ST/X style primitive code (valid after parsing)" |
|
7394 |
||
7395 |
^ hasPrimitiveCode |
|
98 | 7396 |
! |
7397 |
||
1440 | 7398 |
isDoIt |
7399 |
^ (selector isNil or:[selector == #'doIt' or:[selector == #'doIt:']]) |
|
7400 |
! |
|
7401 |
||
883 | 7402 |
isSyntaxHighlighter |
7403 |
^ false |
|
7404 |
! |
|
7405 |
||
385 | 7406 |
lineNumberInfo |
7407 |
^ lineNumberInfo |
|
7408 |
||
7409 |
"Created: 21.10.1996 / 17:06:16 / cg" |
|
7410 |
! |
|
7411 |
||
391
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7412 |
lineNumberInfo:how |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7413 |
lineNumberInfo := how |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7414 |
|
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7415 |
"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
|
7416 |
! |
c556973a4b47
added method to extract a block, given a lineNumber within the
Claus Gittinger <cg@exept.de>
parents:
390
diff
changeset
|
7417 |
|
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7418 |
messagesSent |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7419 |
"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
|
7420 |
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
|
7421 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7422 |
^ (messagesSent ? #()) collect:[:each | each asSymbol] |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7423 |
! |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7424 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7425 |
messagesSentToSelf |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7426 |
"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
|
7427 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7428 |
^ (messagesSentToSelf ? #()) collect:[:each | each asSymbol] |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7429 |
! |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7430 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7431 |
messagesSentToSuper |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7432 |
"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
|
7433 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7434 |
^ (messagesSentToSuper ? #()) collect:[:each | each asSymbol] |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7435 |
! |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7436 |
|
141 | 7437 |
methodArgs |
7438 |
"return an array with methodarg names (valid after parsing spec)" |
|
7439 |
||
7440 |
^ methodArgNames |
|
7441 |
! |
|
7442 |
||
7443 |
methodVars |
|
7444 |
"return a collection with method variablenames (valid after parsing)" |
|
7445 |
||
7446 |
^ methodVarNames |
|
23 | 7447 |
! |
7448 |
||
141 | 7449 |
modifiedClassVars |
7450 |
"return a collection with classvariablenames modified by method (valid after parsing)" |
|
7451 |
||
541 | 7452 |
^ modifiedClassVars ? #() |
7453 |
||
7454 |
"Modified: 19.6.1997 / 17:54:48 / cg" |
|
141 | 7455 |
! |
7456 |
||
7457 |
modifiedGlobals |
|
7458 |
"return a collection with globalnames modified by method (valid after parsing)" |
|
7459 |
||
541 | 7460 |
^ modifiedGlobals ? #() |
7461 |
||
7462 |
"Modified: 19.6.1997 / 17:54:51 / cg" |
|
141 | 7463 |
! |
7464 |
||
7465 |
modifiedInstVars |
|
7466 |
"return a collection with instvariablenames modified by method (valid after parsing)" |
|
7467 |
||
541 | 7468 |
^ modifiedInstVars ? #() |
7469 |
||
7470 |
"Modified: 19.6.1997 / 17:54:27 / cg" |
|
0 | 7471 |
! |
7472 |
||
141 | 7473 |
numberOfMethodArgs |
7474 |
"return the number of methodargs (valid after parsing spec)" |
|
7475 |
||
7476 |
^ methodArgs size |
|
7477 |
! |
|
7478 |
||
7479 |
numberOfMethodVars |
|
7480 |
"return the number of method variables (valid after parsing)" |
|
7481 |
||
7482 |
^ methodVars size |
|
7483 |
! |
|
7484 |
||
1077
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7485 |
readClassVars |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7486 |
"return a collection with classvariablenames read by method (valid after parsing)" |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7487 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7488 |
^ readClassVars ? #() |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7489 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7490 |
"Modified: 19.6.1997 / 17:54:38 / cg" |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7491 |
! |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7492 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7493 |
readInstVars |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7494 |
"return a collection with instvariablenames read by method (valid after parsing)" |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7495 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7496 |
^ readInstVars ? #() |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7497 |
|
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7498 |
"Modified: 19.6.1997 / 17:54:38 / cg" |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7499 |
! |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7500 |
|
141 | 7501 |
selector |
7502 |
"return the selector (valid after parsing spec)" |
|
7503 |
||
7504 |
^ selector |
|
0 | 7505 |
! |
7506 |
||
141 | 7507 |
usedClassVars |
7508 |
"return a collection with classvariablenames refd by method (valid after parsing)" |
|
7509 |
||
541 | 7510 |
^ usedClassVars ? #() |
7511 |
||
7512 |
"Modified: 19.6.1997 / 17:54:56 / cg" |
|
141 | 7513 |
! |
7514 |
||
7515 |
usedGlobals |
|
7516 |
"return a collection with globalnames refd by method (valid after parsing)" |
|
7517 |
||
541 | 7518 |
^ usedGlobals ? #() |
7519 |
||
7520 |
"Modified: 19.6.1997 / 17:55:00 / cg" |
|
141 | 7521 |
! |
7522 |
||
7523 |
usedInstVars |
|
7524 |
"return a collection with instvariablenames refd by method (valid after parsing)" |
|
7525 |
||
541 | 7526 |
^ usedInstVars ? #() |
7527 |
||
7528 |
"Modified: 19.6.1997 / 17:54:38 / cg" |
|
141 | 7529 |
! |
7530 |
||
1064
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7531 |
usedSymbols |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7532 |
"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
|
7533 |
|
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7534 |
^ (usedSymbols ? #()) |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7535 |
! |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7536 |
|
141 | 7537 |
usedVars |
7538 |
"return a collection with variablenames refd by method (valid after parsing)" |
|
7539 |
||
541 | 7540 |
^ usedVars ? #() |
7541 |
||
7542 |
"Modified: 19.6.1997 / 17:55:04 / cg" |
|
0 | 7543 |
! |
7544 |
||
141 | 7545 |
usesSuper |
7546 |
"return true if the parsed method uses super (valid after parsing)" |
|
7547 |
||
7548 |
^ usesSuper |
|
7549 |
! ! |
|
7550 |
||
7551 |
!Parser methodsFor:'setup'! |
|
7552 |
||
1220
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7553 |
classToCompileFor |
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7554 |
^ classToCompileFor |
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7555 |
|
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7556 |
"Created: / 15.11.2001 / 17:21:10 / cg" |
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7557 |
! |
53e6eeadee72
added declare instVar and classInstVar
Claus Gittinger <cg@exept.de>
parents:
1215
diff
changeset
|
7558 |
|
229
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7559 |
foldConstants:aSymbolOrNil |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7560 |
"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
|
7561 |
|
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7562 |
foldConstants := aSymbolOrNil |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7563 |
|
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7564 |
"Created: 21.3.1996 / 16:03:22 / cg" |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7565 |
"Modified: 21.3.1996 / 16:05:04 / cg" |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7566 |
! |
7aecb52d907d
dont fold constants with immediate evaluations
Claus Gittinger <cg@exept.de>
parents:
223
diff
changeset
|
7567 |
|
141 | 7568 |
initialize |
7569 |
super initialize. |
|
7570 |
||
7571 |
hasPrimitiveCode := hasNonOptionalPrimitiveCode := false. |
|
7572 |
warnSTXHereExtensionUsed := WarnSTXSpecials. |
|
7573 |
usesSuper := false. |
|
7574 |
parseForCode := false. |
|
377 | 7575 |
foldConstants := FoldConstants. |
7576 |
lineNumberInfo := LineNumberInfo. |
|
607 | 7577 |
warnUndeclared := true. |
1160 | 7578 |
warnUnusedVars := WarnUnusedVars. |
607 | 7579 |
|
7580 |
"Modified: 7.9.1997 / 02:04:34 / cg" |
|
141 | 7581 |
! |
7582 |
||
1363 | 7583 |
initializeFlagsFrom:aParser |
7584 |
"initialize flags from another scanner" |
|
7585 |
||
7586 |
super initializeFlagsFrom:aParser. |
|
7587 |
warnSTXHereExtensionUsed := aParser warnSTXHereExtensionUsed. |
|
7588 |
! |
|
7589 |
||
141 | 7590 |
parseForCode |
7591 |
"turns off certain statistics (keeping referenced variables, modified vars etc.) |
|
7592 |
Use this when parsing for compilation or evaluation" |
|
7593 |
||
7594 |
parseForCode := true |
|
0 | 7595 |
! |
7596 |
||
141 | 7597 |
setClassToCompileFor:aClass |
7598 |
"set the class to be used for parsing/evaluating" |
|
7599 |
||
7600 |
classToCompileFor := aClass. |
|
7601 |
(classToCompileFor ~~ PrevClass) ifTrue:[ |
|
7602 |
PrevClass notNil ifTrue:[ |
|
7603 |
Parser update:PrevClass |
|
7604 |
] |
|
7605 |
] |
|
7606 |
! |
|
7607 |
||
7608 |
setContext:aContext |
|
7609 |
"set the context used while evaluating" |
|
7610 |
||
7611 |
contextToEvaluateIn := aContext |
|
7612 |
! |
|
7613 |
||
7614 |
setSelf:anObject |
|
7615 |
"set the value to be used for self while evaluating" |
|
7616 |
||
7617 |
selfValue := anObject. |
|
7618 |
classToCompileFor := anObject class. |
|
7619 |
(classToCompileFor ~~ PrevClass) ifTrue:[ |
|
7620 |
PrevClass notNil ifTrue:[ |
|
7621 |
Parser update:PrevClass |
|
7622 |
] |
|
7623 |
] |
|
607 | 7624 |
! |
7625 |
||
7626 |
warnUndeclared:aBoolean |
|
7627 |
warnUndeclared := aBoolean. |
|
7628 |
||
7629 |
"Created: 7.9.1997 / 02:05:00 / cg" |
|
1160 | 7630 |
! |
7631 |
||
7632 |
warnUnusedVars:aBoolean |
|
7633 |
warnUnusedVars := aBoolean. |
|
0 | 7634 |
! ! |
7635 |
||
84 | 7636 |
!Parser methodsFor:'statistic'! |
7637 |
||
1077
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7638 |
rememberClassVarRead:name |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7639 |
readClassVars isNil ifTrue:[ |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7640 |
readClassVars := Set new |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7641 |
]. |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7642 |
readClassVars add:name. |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7643 |
self rememberClassVarUsed:name |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7644 |
! |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7645 |
|
141 | 7646 |
rememberClassVarUsed:name |
7647 |
usedClassVars isNil ifTrue:[ |
|
7648 |
usedClassVars := Set new |
|
7649 |
]. |
|
7650 |
usedClassVars add:name. |
|
7651 |
self rememberVariableUsed:name |
|
7652 |
! |
|
7653 |
||
7654 |
rememberGlobalUsed:name |
|
7655 |
usedGlobals isNil ifTrue:[ |
|
7656 |
usedGlobals := Set new |
|
7657 |
]. |
|
7658 |
usedGlobals add:name. |
|
7659 |
self rememberVariableUsed:name |
|
7660 |
! |
|
7661 |
||
1077
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7662 |
rememberInstVarRead:name |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7663 |
readInstVars isNil ifTrue:[ |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7664 |
readInstVars := Set new |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7665 |
]. |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7666 |
readInstVars add:name. |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7667 |
self rememberVariableUsed:name |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7668 |
! |
e34f711bd1d1
#readInstVars & #readClassVars
Claus Gittinger <cg@exept.de>
parents:
1070
diff
changeset
|
7669 |
|
141 | 7670 |
rememberInstVarUsed:name |
7671 |
usedInstVars isNil ifTrue:[ |
|
7672 |
usedInstVars := Set new |
|
7673 |
]. |
|
7674 |
usedInstVars add:name. |
|
7675 |
self rememberVariableUsed:name |
|
7676 |
! |
|
7677 |
||
977
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7678 |
rememberLocalUsed:name |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7679 |
usedLocalVars isNil ifTrue:[ |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7680 |
usedLocalVars := Set new |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7681 |
]. |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7682 |
usedLocalVars add:name. |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7683 |
|
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7684 |
! |
c1afbaf48a23
remember used & modified local vars;
Claus Gittinger <cg@exept.de>
parents:
971
diff
changeset
|
7685 |
|
1231 | 7686 |
rememberReturnedValue:anExpressionNode |
7687 |
|expr| |
|
7688 |
||
7689 |
returnedValues isNil ifTrue:[returnedValues := Set new]. |
|
7690 |
||
7691 |
expr := anExpressionNode. |
|
7692 |
expr isAssignment ifTrue:[ |
|
7693 |
expr := expr expression. |
|
7694 |
]. |
|
7695 |
(expr isConstant or:[expr isSelf]) ifTrue:[ |
|
7696 |
returnedValues add:expr |
|
7697 |
]. |
|
7698 |
! |
|
7699 |
||
84 | 7700 |
rememberSelectorUsed:sel |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7701 |
messagesSent isNil ifTrue:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7702 |
messagesSent := IdentitySet new. |
84 | 7703 |
]. |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7704 |
messagesSent add:sel |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7705 |
! |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7706 |
|
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7707 |
rememberSelectorUsed:sel receiver:receiverNode |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7708 |
self rememberSelectorUsed:sel. |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7709 |
receiverNode isSuper ifTrue:[ |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7710 |
self rememberSelectorUsedInSuperSend:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7711 |
] ifFalse:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7712 |
receiverNode isSelf ifTrue:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7713 |
self rememberSelectorUsedInSelfSend:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7714 |
]. |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7715 |
]. |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7716 |
! |
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7717 |
|
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7718 |
rememberSelectorUsedInSelfSend:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7719 |
messagesSentToSelf isNil ifTrue:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7720 |
messagesSentToSelf := IdentitySet new. |
1060
9978f9d22dde
more queries (remember super messages)
Claus Gittinger <cg@exept.de>
parents:
1052
diff
changeset
|
7721 |
]. |
1082
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7722 |
messagesSentToSelf add:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7723 |
! |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7724 |
|
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7725 |
rememberSelectorUsedInSuperSend:sel |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7726 |
messagesSentToSuper isNil ifTrue:[ |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7727 |
messagesSentToSuper := IdentitySet new. |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7728 |
]. |
f795099895c5
keep track of messages sent to self (for checker)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
7729 |
messagesSentToSuper add:sel |
84 | 7730 |
! |
7731 |
||
1064
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7732 |
rememberSymbolUsed:aSymbol |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7733 |
usedSymbols isNil ifTrue:[ |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7734 |
usedSymbols := IdentitySet new. |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7735 |
]. |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7736 |
usedSymbols add:aSymbol |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7737 |
! |
ecd50cdfb881
added #usedSymbols statistic
Claus Gittinger <cg@exept.de>
parents:
1063
diff
changeset
|
7738 |
|
84 | 7739 |
rememberVariableUsed:name |
7740 |
usedVars isNil ifTrue:[ |
|
7741 |
usedVars := Set new |
|
7742 |
]. |
|
7743 |
usedVars add:name |
|
7744 |
! ! |
|
7745 |
||
1340 | 7746 |
!Parser::ParseError methodsFor:'accessing'! |
7747 |
||
1386 | 7748 |
description |
1434
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7749 |
|s| |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7750 |
|
1461 | 7751 |
s := super description. |
7752 |
s last isSeparator ifFalse:[ |
|
7753 |
errorMessage size > 0 ifTrue:[ |
|
7754 |
s := s , ' ' |
|
7755 |
] |
|
7756 |
]. |
|
7757 |
s := s , (errorMessage ? ''). |
|
1434
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7758 |
lineNumber notNil ifTrue:[ |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7759 |
s := s , ' [' , lineNumber asString , ']' |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7760 |
]. |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7761 |
^ s |
1386 | 7762 |
! |
7763 |
||
1340 | 7764 |
endPosition |
7765 |
^ endPosition |
|
7766 |
! |
|
7767 |
||
7768 |
errorMessage |
|
7769 |
^ errorMessage |
|
7770 |
! |
|
7771 |
||
1460 | 7772 |
errorMessage:errorMessageArg startPosition:startPositionArg |
7773 |
errorMessage := errorMessageArg. |
|
7774 |
startPosition := startPositionArg. |
|
7775 |
! |
|
7776 |
||
1340 | 7777 |
errorMessage:errorMessageArg startPosition:startPositionArg endPosition:endPositionArg |
7778 |
errorMessage := errorMessageArg. |
|
7779 |
startPosition := startPositionArg. |
|
7780 |
endPosition := endPositionArg. |
|
7781 |
! |
|
7782 |
||
1434
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7783 |
lineNumber:something |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7784 |
lineNumber := something. |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7785 |
! |
e7d527d493d3
optional lineNumber info added to parseError
Claus Gittinger <cg@exept.de>
parents:
1432
diff
changeset
|
7786 |
|
1340 | 7787 |
parser |
7788 |
^ originator |
|
7789 |
! |
|
7790 |
||
7791 |
startPosition |
|
7792 |
^ startPosition |
|
7793 |
! ! |
|
7794 |
||
1399
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7795 |
!Parser::UndefinedVariableNotification methodsFor:'accessing'! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7796 |
|
1514 | 7797 |
description |
1516 | 7798 |
^ 'undefined variable: ' , self variableName |
1514 | 7799 |
! |
7800 |
||
1399
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7801 |
parser |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7802 |
"return the value of the instance variable 'parser' (automatically generated)" |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7803 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7804 |
^ parser |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7805 |
! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7806 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7807 |
parser:something |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7808 |
"set the value of the instance variable 'parser' (automatically generated)" |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7809 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7810 |
parser := something. |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7811 |
! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7812 |
|
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7813 |
variableName |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7814 |
^ parameter |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7815 |
! ! |
95b2eaa4e457
undefinedVariableNotification fix
Claus Gittinger <cg@exept.de>
parents:
1398
diff
changeset
|
7816 |
|
358
78b0d8954c49
removed possible conflict between #classVarNames here and in Class.
Claus Gittinger <cg@exept.de>
parents:
354
diff
changeset
|
7817 |
!Parser class methodsFor:'documentation'! |
148 | 7818 |
|
7819 |
version |
|
1561
175735dcd732
do not check for endOfInput if parsing from a Stream
Claus Gittinger <cg@exept.de>
parents:
1557
diff
changeset
|
7820 |
^ '$Header: /cvs/stx/stx/libcomp/Parser.st,v 1.446 2004-11-25 14:30:33 cg Exp $' |
148 | 7821 |
! ! |
1322
da25e31f423c
autodefine workspace variables
Claus Gittinger <cg@exept.de>
parents:
1315
diff
changeset
|
7822 |
|
141 | 7823 |
Parser initialize! |