author | Stefan Vogel <sv@exept.de> |
Wed, 31 Jan 2018 09:24:00 +0100 | |
changeset 22517 | 982299841888 |
parent 22516 | 8fe8242e6c72 |
child 23412 | be414bc6ccea |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
" |
|
5434 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17512 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
3985 | 16 |
String variableByteSubclass:#Symbol |
1020 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Collections-Text' |
|
1 | 21 |
! |
22 |
||
77 | 23 |
!Symbol class methodsFor:'documentation'! |
1 | 24 |
|
88 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 28 |
All Rights Reserved |
88 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
77 | 39 |
documentation |
40 |
" |
|
41 |
Symbols represent unique strings - every symbol with same printString |
|
42 |
exists exactly once in the system; Symbols are used for selectors, global |
|
345 | 43 |
variable-keys etc. Symbols can also be used to represent things which are |
44 |
enumeration type values in other programming languages (since symbols are |
|
370 | 45 |
created at compile time, comparing them using == is a fast pointer compare). |
345 | 46 |
|
47 |
A symbol may not change its characters - i.e. it is constant over its lifetime. |
|
48 |
Other than that, symbols behave much like strings. |
|
1290 | 49 |
|
17512 | 50 |
The most prominent use of symbols is as key for message sending: methods are stored |
51 |
in a classes method dictionary, where symbols are used as key to map names to methods. |
|
52 |
Also, symbols are used as key to map class names (global names) to actual class objects. |
|
53 |
||
54 |
Special ST/X feature: |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
55 |
The ST/X VM method lookup supports selector namespaces for method extensions. |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
56 |
This means, that a class may contain method extensions in another namespace, |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
57 |
which are only seen and invoked if called from a class within that namespace. |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
58 |
Technically, this is done by storing the method under a special namespace-selector, |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
59 |
which is a symbol consisting of the user visible name, prefixed by ':<ns>::'. |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
60 |
The VM's method lookup algorithm contains special handling code for such constructs. |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
61 |
Thus, if two methods are stored as 'foo' and ':NS::foo' are present in a class, |
22516 | 62 |
any send of 'foo' from wíthin the NS-namespace will invoke the second method. |
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
63 |
Any other send will invoke the first one. |
17512 | 64 |
|
65 |
||
1290 | 66 |
[author:] |
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
67 |
Claus Gittinger |
77 | 68 |
" |
69 |
! ! |
|
1 | 70 |
|
77 | 71 |
!Symbol class methodsFor:'instance creation'! |
1 | 72 |
|
62 | 73 |
basicNew:size |
74 |
"redefined to return a string instead of a symbol - |
|
75 |
this allows all copy methods inherited from String to |
|
76 |
return strings containing the symbols characters. |
|
1020 | 77 |
Real symbols are only created with #intern: or #asSymbol." |
62 | 78 |
|
79 |
^ String new:size |
|
1020 | 80 |
|
81 |
"Modified: 26.2.1996 / 12:51:38 / cg" |
|
62 | 82 |
! |
83 |
||
77 | 84 |
fromString:aString |
85 |
"same as intern: for Symbol, but may be used to create interned instances |
|
86 |
of subclasses. |
|
87 |
Notice: this fails, if you try to intern an instance of a subclass, AND |
|
88 |
a symbol with the same name already exists. In this case, the original |
|
89 |
symbol is returned. To use it for enum-type symbols, make certain, that the |
|
90 |
names are unique (for example by including the classes name as a prefix-string)." |
|
91 |
||
267 | 92 |
|sym len| |
77 | 93 |
|
267 | 94 |
sym := aString asSymbolIfInterned. |
95 |
sym notNil ifTrue:[ |
|
96 |
^ sym |
|
77 | 97 |
]. |
98 |
||
99 |
" |
|
100 |
create a new uninterned instance first |
|
101 |
" |
|
102 |
len := aString size. |
|
267 | 103 |
sym := super basicNew:len. |
104 |
sym replaceFrom:1 to:len with:aString. |
|
77 | 105 |
|
106 |
"now, intern it" |
|
107 |
%{ |
|
329 | 108 |
sym = __INTERNSYMBOL(sym, (OBJ *)0, __context); |
77 | 109 |
%}. |
267 | 110 |
^ sym |
77 | 111 |
! |
112 |
||
608 | 113 |
intern:aString |
114 |
"return a unique symbol with printname taken from the String-argument" |
|
115 |
||
116 |
%{ /* NOCONTEXT */ |
|
117 |
OBJ newSymbol; |
|
118 |
||
119 |
if (__isSymbol(aString)) { |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
120 |
RETURN (aString); |
608 | 121 |
} |
12473
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
122 |
if (__isStringLike(aString)) { |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
123 |
newSymbol = __MKSYMBOL(__stringVal(aString), (OBJ *)0); |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
124 |
if (newSymbol != nil) { |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
125 |
RETURN (newSymbol); |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
126 |
} |
608 | 127 |
} |
128 |
%}. |
|
12473
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
129 |
(aString class ~~ String and:[aString class ~~ ImmutableString]) ifTrue:[ |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
130 |
"only allowed to intern strings" |
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
131 |
^ self mustBeString |
608 | 132 |
]. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
133 |
^ AllocationFailure raise. |
608 | 134 |
! |
135 |
||
1 | 136 |
internCharacter:aCharacter |
137 |
"return a unique symbol with printname taken from the Character-argument" |
|
138 |
||
139 |
^ self intern:(aCharacter asString) |
|
608 | 140 |
! |
141 |
||
142 |
new:size |
|
143 |
"redefined to return a string instead of a symbol - |
|
144 |
this allows all copy methods inherited from String to |
|
145 |
return strings containing the symbols characters. |
|
146 |
Real symbols are only created with intern: or asSymbol." |
|
147 |
||
148 |
^ String new:size |
|
149 |
! ! |
|
150 |
||
2570
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
151 |
|
22516 | 152 |
|
153 |
||
1 | 154 |
!Symbol class methodsFor:'queries'! |
155 |
||
608 | 156 |
findInterned:aString |
157 |
"for ST-80 compatibility - if the argument, aString is known |
|
158 |
as Symbol, return this symbol. Otherwise return nil." |
|
159 |
||
160 |
^ aString asSymbolIfInterned |
|
161 |
! |
|
162 |
||
163 |
hasInterned:aString |
|
164 |
"return true, if the argument, aString is known as Symbol; |
|
165 |
false otherwise" |
|
166 |
||
167 |
^ aString knownAsSymbol |
|
168 |
! |
|
169 |
||
1 | 170 |
hasInterned:aString ifTrue:trueBlock |
171 |
"for ST-80 compatibility - if the argument, aString is known |
|
172 |
as Symbol, evaluate the block with the corresponding symbol |
|
173 |
as argument and return true; otherwise return false" |
|
174 |
||
275 | 175 |
|sym| |
176 |
||
177 |
(sym := aString asSymbolIfInterned) notNil ifTrue:[ |
|
178 |
trueBlock value:sym. |
|
159 | 179 |
^ true |
1 | 180 |
]. |
181 |
^ false |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
182 |
! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
183 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
184 |
hasSharedInstances |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
185 |
"return true if this class has shared instances, that is, instances |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
186 |
with the same value are identical. |
4654 | 187 |
True returned here - there is only one of each symbol (per contents)." |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
188 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
189 |
^ true |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
190 |
|
1 | 191 |
! ! |
192 |
||
13423 | 193 |
|
11819 | 194 |
!Symbol methodsFor:'Compatibility-Squeak'! |
195 |
||
13690 | 196 |
precedence |
197 |
"the precedence in an expression; 0 is highest; |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
198 |
unary < binary < keyword" |
13690 | 199 |
|
200 |
self size = 0 |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
201 |
ifTrue: [^ 0]. |
13690 | 202 |
self first isLetter |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
203 |
ifFalse: [^ 2]. |
13690 | 204 |
self last = $: |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
205 |
ifTrue: [^ 3]. |
13690 | 206 |
^ 1 |
207 |
||
208 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
209 |
self assert:(#foo precedence < #+ precedence). |
13690 | 210 |
self assert:(#+ precedence < #key: precedence). |
211 |
self assert:(#foo precedence < #key: precedence). |
|
212 |
" |
|
213 |
||
214 |
"Created: / 12-09-2011 / 14:53:54 / cg" |
|
11819 | 215 |
! ! |
216 |
||
7261 | 217 |
!Symbol methodsFor:'Compatibility-VW'! |
7153 | 218 |
|
219 |
<< catalogID |
|
220 |
"create and return a new UserMessage, with the receiver as key, |
|
221 |
and the argument as cataglogID. |
|
222 |
VW compatibility." |
|
223 |
||
224 |
^ UserMessage key:self catalogID:catalogID |
|
225 |
||
226 |
" |
|
11859 | 227 |
(#theFooMessage << #myMessages) |
228 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') |
|
229 |
(#theFooMessage >> 'cannot read subclass of metaclass') |
|
7153 | 230 |
" |
231 |
! |
|
232 |
||
233 |
>> aString |
|
234 |
"create and return a new UserMessage, with the receiver as key, |
|
235 |
and the argument as defaultString. |
|
236 |
VW compatibility." |
|
237 |
||
11859 | 238 |
^ UserMessage key:self defaultString:aString |
7153 | 239 |
|
240 |
" |
|
11859 | 241 |
(#theFooMessage << #myMessages) |
242 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') |
|
243 |
(#theFooMessage >> 'cannot read subclass of metaclass') |
|
7153 | 244 |
" |
245 |
! ! |
|
246 |
||
1 | 247 |
!Symbol methodsFor:'accessing'! |
248 |
||
249 |
basicAt:index put:something |
|
345 | 250 |
"report an error if an interned symbol is about to be changed |
1219 | 251 |
- interned symbols may NOT be changed. |
252 |
For uninterned symbols, this is allowed." |
|
1 | 253 |
|
77 | 254 |
self knownAsSymbol ifTrue:[ |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
255 |
self noModificationError. |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
256 |
"Even if you hit continue - you cannot change symbols. |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
257 |
Raise again non-resumable" |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
258 |
NoModificationError raiseWith:self errorString:' - interned symbols cannot be changed'. |
77 | 259 |
]. |
260 |
" |
|
261 |
uninterned - allow change |
|
262 |
" |
|
263 |
^ super basicAt:index put:something |
|
1219 | 264 |
|
265 |
"Modified: 19.4.1996 / 11:16:10 / cg" |
|
13423 | 266 |
! |
267 |
||
268 |
nameSpace |
|
16735 | 269 |
"if I have the format of a namespace-selector, |
270 |
retrieve the namespace. Otherwise, return nil. |
|
18619 | 271 |
Also return nil, if that namespace does not exist (in contrast to nameSpacePart). |
272 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
16735 | 273 |
They must be of the form :<ns>::<sel>, |
17512 | 274 |
where <ns> is the namespace and <sel> is the raw selector. |
275 |
This special format (a symbol starting with a colon) was chosen, because almost every other selector |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
276 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 277 |
|
17516 | 278 |
|nsPart| |
279 |
||
280 |
nsPart := self nameSpaceAndSelectorParts first. |
|
18619 | 281 |
nsPart isNil ifTrue:[^ nil]. |
17516 | 282 |
^ Smalltalk at:nsPart asSymbol |
16735 | 283 |
|
284 |
" |
|
285 |
#':foo:' nameSpace -> nil (bad format) |
|
286 |
#':foo::bar' nameSpace -> nil (non existing) |
|
17516 | 287 |
#':Tools::bar' nameSpace -> Tools |
18619 | 288 |
#'bar' nameSpace -> nil |
289 |
#'bar:' nameSpace -> nil |
|
16735 | 290 |
" |
13423 | 291 |
|
292 |
"Created: / 20-07-2010 / 10:41:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
293 |
! |
|
294 |
||
295 |
nameSpaceAndSelector |
|
16735 | 296 |
"return a two element tuple consisting of the namespace and the raw selector. |
297 |
If I do not have the format of a namespace-selector, or the namespace is non-existing, |
|
298 |
the first element of the returned tuple will be nil. |
|
18619 | 299 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
16735 | 300 |
They must be of the form :<ns>::<sel>, |
17512 | 301 |
where <ns> is the namespace and <sel> is the raw selector. |
302 |
This special format (a symbol starting with a colon) was chosen, because almost every other selector |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
303 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 304 |
|
17516 | 305 |
|parts ns| |
13423 | 306 |
|
307 |
self isNameSpaceSelector ifFalse:[ |
|
18701 | 308 |
^ Array with:nil with:self |
13423 | 309 |
]. |
17516 | 310 |
parts := self nameSpaceAndSelectorParts. |
311 |
ns := Smalltalk at:parts first asSymbol. |
|
312 |
^ Array with:ns with:parts second |
|
13423 | 313 |
|
16735 | 314 |
" |
315 |
#':foo:bar' nameSpaceAndSelector -> #(nil #':foo:bar') |
|
316 |
#':foo::bar' nameSpaceAndSelector -> #(nil #bar) |
|
317 |
#':Tools::foo' nameSpaceAndSelector -> #(Tools (* NameSpace *) #foo) |
|
318 |
" |
|
319 |
||
13423 | 320 |
"Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
321 |
! |
|
322 |
||
17516 | 323 |
nameSpaceAndSelectorParts |
324 |
"return a two element tuple consisting of the namespace name and the raw selector. |
|
18701 | 325 |
If I do not have the format of a namespace-selector, |
17516 | 326 |
the first element of the returned tuple will be nil. |
18619 | 327 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
17516 | 328 |
They must be of the form :<ns>::<sel>, |
329 |
where <ns> is the namespace and <sel> is the raw selector. |
|
330 |
This special format (a symbol starting with a colon) was chosen, because almost every other selector |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
331 |
is legal, and this can be checked quickly by just looking at the first character." |
17516 | 332 |
|
333 |
|nsPart selPart idx| |
|
334 |
||
335 |
self isNameSpaceSelector ifFalse:[ |
|
18701 | 336 |
^ Array with:nil with:self |
17516 | 337 |
]. |
338 |
idx := self indexOf:$: startingAt:3. |
|
339 |
nsPart := self copyFrom:2 to:idx - 1. |
|
340 |
selPart := self copyFrom:idx + 2. |
|
341 |
^ Array with:nsPart with:selPart asSymbol |
|
342 |
||
343 |
" |
|
18619 | 344 |
#':foo:bar' nameSpaceAndSelectorParts -> #(nil #':foo:bar') |
345 |
#':foo:bar' nameSpaceAndSelector -> #(nil #':foo:bar') |
|
346 |
||
347 |
#':foo::bar' nameSpaceAndSelectorParts -> #('foo' #bar) |
|
348 |
#':foo::bar' nameSpaceAndSelector -> #(nil #bar) |
|
349 |
||
350 |
#'bar' nameSpaceAndSelectorParts -> #(nil #bar) |
|
351 |
#'bar' nameSpaceAndSelector -> #(nil #bar) |
|
352 |
||
353 |
#':Tools::foo' nameSpaceAndSelectorParts -> #('Tools' #foo) |
|
354 |
#':Tools::foo' nameSpaceAndSelector -> #(Tools (* NameSpace *) #foo) |
|
17516 | 355 |
" |
356 |
||
357 |
"Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
358 |
! |
|
359 |
||
360 |
nameSpacePart |
|
361 |
"if I have the format of a namespace-selector, |
|
362 |
retrieve the namespace name. Otherwise, return nil. |
|
18619 | 363 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
17516 | 364 |
They must be of the form :<ns>::<sel>, |
365 |
where <ns> is the namespace and <sel> is the raw selector. |
|
366 |
This special format (a symbol starting with a colon) was chosen, because almost every other selector |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
367 |
is legal, and this can be checked quickly by just looking at the first character." |
17516 | 368 |
|
369 |
^ self nameSpaceAndSelectorParts first. |
|
370 |
||
371 |
" |
|
372 |
#':foo:' nameSpacePart -> nil (bad format) |
|
373 |
#':foo::bar' nameSpacePart -> 'foo' |
|
374 |
#':Tools::bar' nameSpacePart -> 'Tools' |
|
375 |
" |
|
376 |
! |
|
377 |
||
13423 | 378 |
selector |
17512 | 379 |
<resource: #obsolete> |
380 |
||
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
381 |
"if I have the format of a namespace-selector, retrieve the raw selector. |
17512 | 382 |
Otherwise, return myself. |
383 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
16735 | 384 |
They must be of the form :<ns>::<sel>, |
17512 | 385 |
where <ns> is the namespace and <sel> is the raw selector. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
386 |
This special format (a symbol starting with a colon) was chosen, |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
387 |
because almost every other selector is legal, |
19714 | 388 |
and this can be checked quickly in the VM, by just looking at the first character." |
17512 | 389 |
|
390 |
self obsoleteMethodWarning:'use selectorWithoutNameSpace'. |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
391 |
^ self selectorWithoutNameSpace |
17512 | 392 |
! |
393 |
||
394 |
selectorWithoutNameSpace |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
395 |
"if I have the format of a namespace-selector, retrieve the raw selector. |
17512 | 396 |
Otherwise, return myself. |
397 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
398 |
They must be of the form :<ns>::<sel>, |
|
399 |
where <ns> is the namespace and <sel> is the raw selector. |
|
400 |
This special format (a symbol starting with a colon) was chosen, because almost every other selector |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
401 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 402 |
|
18619 | 403 |
^ self nameSpaceAndSelectorParts second |
16735 | 404 |
|
405 |
" |
|
17516 | 406 |
#':foo:' selectorWithoutNameSpace -> #':foo:' (bad format) |
407 |
#':foo::bar' selectorWithoutNameSpace -> bar |
|
408 |
#':Tools::bar' selectorWithoutNameSpace -> bar |
|
16735 | 409 |
" |
13423 | 410 |
|
411 |
"Created: / 20-07-2010 / 10:41:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1 | 412 |
! ! |
413 |
||
13423 | 414 |
|
608 | 415 |
!Symbol methodsFor:'comparing'! |
159 | 416 |
|
608 | 417 |
= something |
418 |
"return true, if the receiver and argument consist of the same characters. |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
419 |
Redefined here, for more efficient comparison of symbols |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
420 |
(which can to be compared using #==). |
608 | 421 |
If the argument is a symbol, we use a quick pointer compare, instead of |
422 |
the inherited value compare." |
|
13 | 423 |
|
608 | 424 |
%{ /* NOCONTEXT */ |
18701 | 425 |
#ifdef __SCHTEAM__ |
426 |
if (something.isSymbol()) { |
|
427 |
return context._RETURN ( self == something ? STObject.True : STObject.False ); |
|
428 |
} |
|
429 |
if (something.isSTString()) { |
|
430 |
return context._RETURN ( something.isStringEqual(self) ? STObject.True : STObject.False ); |
|
431 |
} |
|
432 |
if (something == STObject.Nil) { |
|
433 |
return context._RETURN_false ( ); |
|
434 |
} |
|
435 |
#else |
|
608 | 436 |
OBJ cls; |
13 | 437 |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
438 |
if (something == self) RETURN(true); |
608 | 439 |
if (! __isNonNilObject(something)) RETURN(false); |
440 |
if ((cls = __qClass(something)) == Symbol) { |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
441 |
RETURN (false); |
608 | 442 |
} |
14658 | 443 |
if (cls == String || cls == ImmutableString) { |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
444 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? true : false); |
345 | 445 |
} |
18701 | 446 |
#endif |
345 | 447 |
%}. |
608 | 448 |
"fall back; could be a TwoByteString, or a collection of Characters" |
1 | 449 |
|
608 | 450 |
^ super = something |
427 | 451 |
! |
452 |
||
356 | 453 |
identityHash |
454 |
"interned symbols can return a better hash key" |
|
455 |
||
13881 | 456 |
%{ /* NOCONTEXT */ |
457 |
||
16891
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16890
diff
changeset
|
458 |
REGISTER unsigned int val; // yes: only 32 bit |
356 | 459 |
|
14651 | 460 |
if (__qIsSymbol(self)) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
461 |
val = __GET_HASH(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
462 |
/* |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
463 |
* only do it, if I have no standard hash key |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
464 |
* assigned (which can only happen due to a #become:, |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
465 |
* or by creating a symbol uninterned, and interning it |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
466 |
* after it got a hashKey assigned. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
467 |
*/ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
468 |
if (val == 0) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
469 |
extern unsigned int __symbolHash(char *); |
14651 | 470 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
471 |
val = __symbolHash(__stringVal(self)); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
472 |
// make sure, it fits into a smallInt |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
473 |
val = (val ^ (val >> 30)) & 0x3FFFFFFF; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
474 |
} else { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
475 |
val = __MAKE_HASH__(val); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
476 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
477 |
RETURN ( __mkSmallInteger(val) ); |
14651 | 478 |
} |
356 | 479 |
%}. |
14651 | 480 |
|
481 |
^ super identityHash. |
|
3985 | 482 |
|
483 |
" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
484 |
|hashColl hashSet| |
3985 | 485 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
486 |
hashColl := OrderedCollection new:20000. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
487 |
Symbol allInstancesDo:[:instance | |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
488 |
hashColl add:instance identityHash |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
489 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
490 |
hashSet := hashColl asSet. |
3985 | 491 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
492 |
Transcript showCR:'Symbols: ', hashColl size printString, |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
493 |
' unique hash keys: ', hashSet size printString, |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
494 |
' collisions:', (hashColl size - hashSet size) printString. |
3985 | 495 |
" |
13881 | 496 |
|
497 |
"Modified (comment): / 26-12-2011 / 14:32:10 / cg" |
|
370 | 498 |
! |
499 |
||
500 |
~= something |
|
501 |
"return true, if the receiver and argument do not consist of the same characters. |
|
11859 | 502 |
Redefined here, for more efficient #~= comparison of symbols |
370 | 503 |
(which ought to be compared using #~~). |
504 |
If the argument is a symbol, we use a quick pointer compare, instead of |
|
505 |
the inherited value compare." |
|
506 |
||
507 |
%{ /* NOCONTEXT */ |
|
18701 | 508 |
#ifdef __SCHTEAM__ |
509 |
if (something.isSymbol()) { |
|
510 |
return context._RETURN ( self == something ? STObject.False : STObject.True ); |
|
511 |
} |
|
512 |
if (something.isSTString()) { |
|
513 |
return context._RETURN ( something.isStringEqual(self) ? STObject.False : STObject.True ); |
|
514 |
} |
|
515 |
if (something == STObject.Nil) { |
|
516 |
return context._RETURN_true ( ); |
|
517 |
} |
|
518 |
#else |
|
370 | 519 |
OBJ cls; |
520 |
||
379 | 521 |
if (! __isNonNilObject(something)) RETURN(true); /* cannot be equal */ |
370 | 522 |
if ((cls = __qClass(something)) == Symbol) { |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
523 |
RETURN (self == something ? false : true); |
370 | 524 |
} |
14658 | 525 |
if (cls == String || cls == ImmutableString) { |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
526 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? false : true); |
370 | 527 |
} |
18701 | 528 |
#endif |
370 | 529 |
%}. |
530 |
"fall back; could be a TwoByteString, or a collection of Characters" |
|
531 |
||
532 |
^ super ~= something |
|
356 | 533 |
! ! |
534 |
||
608 | 535 |
!Symbol methodsFor:'converting'! |
536 |
||
537 |
asString |
|
538 |
"return a string with printname taken from mine" |
|
539 |
||
540 |
%{ /* NOCONTEXT */ |
|
541 |
OBJ s; |
|
542 |
||
2565 | 543 |
s = __MKSTRING_ST(self); |
608 | 544 |
if (s != nil) { |
11859 | 545 |
RETURN (s); |
608 | 546 |
} |
547 |
%}. |
|
5434 | 548 |
^ (String new:(self size)) |
11859 | 549 |
replaceFrom:1 with:self startingAt:1 |
608 | 550 |
! |
551 |
||
552 |
asSymbol |
|
19467 | 553 |
"Return a unique symbol with the name taken from the receiver's characters. |
608 | 554 |
Since I am a symbol - just return myself" |
555 |
||
556 |
^ self |
|
557 |
! |
|
558 |
||
559 |
asSymbolIfInterned |
|
17185 | 560 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
608 | 561 |
Since I am a symbol - just return myself" |
562 |
||
563 |
^ self |
|
21017 | 564 |
! |
565 |
||
566 |
asSymbolIfInternedOrSelf |
|
567 |
^ self |
|
608 | 568 |
! ! |
569 |
||
570 |
!Symbol methodsFor:'copying'! |
|
571 |
||
572 |
copy |
|
573 |
"return a copy of myself |
|
4729 | 574 |
- reimplemented here since symbols are immutable." |
608 | 575 |
|
576 |
^ self |
|
577 |
! |
|
578 |
||
3659 | 579 |
copyReplaceAll:oldElement with:newElement |
580 |
"return a copy of the receiver as a string, where all elements equal to oldElement |
|
581 |
have been replaced by newElement." |
|
582 |
||
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
583 |
"/ 'Warning: #copyReplaceAll:with: will change semantics as defined in ANSI soon' errorPrintCR. |
3659 | 584 |
^ self asString replaceAll:oldElement with:newElement |
585 |
||
586 |
"Created: / 18.7.1998 / 23:03:38 / cg" |
|
587 |
! |
|
588 |
||
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
589 |
copyReplacing:oldElement withObject:newElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
590 |
"return a copy of the receiver, where all elements equal to oldElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
591 |
have been replaced by newElement. |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
592 |
ANSI version of what used to be #copyReplaceAll:with:" |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
593 |
|
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
594 |
^ self asString replaceAll:oldElement with:newElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
595 |
! |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
596 |
|
608 | 597 |
deepCopy |
598 |
"return a copy of myself |
|
4729 | 599 |
- reimplemented here since symbols are immutable." |
608 | 600 |
|
601 |
^ self |
|
602 |
! |
|
603 |
||
10950 | 604 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8383 | 605 |
"return a deep copy of myself |
4729 | 606 |
- reimplemented here since symbols are immutable." |
608 | 607 |
|
608 |
^ self |
|
609 |
! |
|
610 |
||
611 |
shallowCopy |
|
612 |
"return a copy of myself |
|
10581 | 613 |
- reimplemented here since symbols are immutable and unique, |
614 |
so we return the receiver." |
|
608 | 615 |
|
616 |
^ self |
|
10581 | 617 |
|
618 |
"Modified: / 31-05-2007 / 15:32:30 / cg" |
|
608 | 619 |
! |
620 |
||
621 |
simpleDeepCopy |
|
622 |
"return a copy of myself |
|
4729 | 623 |
- reimplemented here since symbols are immutable." |
608 | 624 |
|
625 |
^ self |
|
626 |
! ! |
|
627 |
||
16154 | 628 |
!Symbol methodsFor:'evaluation'! |
629 |
||
22399 | 630 |
value:el |
19605 | 631 |
"this is sent by collection enumeration methods, |
632 |
if a symbol is given instead of a block as loop-block argument" |
|
633 |
||
634 |
^ el perform:self. |
|
635 |
||
636 |
" |
|
637 |
this allows us to say: |
|
638 |
||
639 |
#(1 2 3 4) do: #printCR |
|
640 |
#(1 -2 -3 4) collect: #abs |
|
22399 | 641 |
#(1 2 3 4) select: #even |
642 |
'hello' collect: #rot13 |
|
19605 | 643 |
someCollection collect: #withoutSeparators |
644 |
" |
|
645 |
! |
|
646 |
||
16154 | 647 |
value: el value:arg |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
648 |
"this is sent by collection enumeration methods, |
16155 | 649 |
if a symbol is given instead of a block as loop-block argument" |
16154 | 650 |
|
651 |
^ el perform:self with:arg. |
|
652 |
||
653 |
" |
|
654 |
this allows us to say: |
|
655 |
||
656 |
#(1 2 3 4) with:#(10 20 30 40) collect: #+ |
|
657 |
" |
|
658 |
! ! |
|
659 |
||
14651 | 660 |
|
608 | 661 |
!Symbol methodsFor:'printing & storing'! |
662 |
||
22516 | 663 |
displayString |
664 |
"return a string used when displaying the receiver in a view; |
|
665 |
for example an Inspector. This is usually the same as printString, |
|
666 |
but sometimes redefined for a better look." |
|
667 |
||
22517 | 668 |
^ self storeString |
22516 | 669 |
|
670 |
"Created: / 31-01-2018 / 09:01:45 / stefan" |
|
671 |
! |
|
672 |
||
608 | 673 |
printOn:aStream |
4392 | 674 |
"append a user printed representation of the receiver to aStream. |
675 |
The format is suitable for a human - not meant to be read back. |
|
676 |
||
608 | 677 |
In contrast to ST-80, this does return the symbols characters |
678 |
without any leading #. Therefore, you can directly send symbols' |
|
679 |
printStrings to some output device. This is incompatible, but easier |
|
680 |
to use." |
|
681 |
||
682 |
"/ ST-80 behavior: |
|
683 |
||
684 |
"/ self storeOn:aStream |
|
685 |
||
686 |
aStream nextPutAll:self |
|
687 |
! |
|
688 |
||
689 |
printString |
|
690 |
"return a printed representation of the receiver. |
|
691 |
In contrast to ST-80, this does return the symbols characters |
|
692 |
without any leading #. Therefore, you can directly send symbols' |
|
693 |
printStrings to some output device. This is incompatible, but easier |
|
694 |
to use." |
|
695 |
||
696 |
"/ ST-80 behavior: |
|
697 |
"/ ^ self storeString |
|
698 |
||
699 |
^ self asString |
|
700 |
! |
|
701 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
702 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
703 |
"store myself on a stream. |
8368 | 704 |
I am stored as an array element, so the '#' may be omitted sometimes. |
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
705 |
Take care for special symbols" |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
706 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
707 |
|storeString| |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
708 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
709 |
storeString := self storeString. |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
710 |
(self == #true or:[self == #false or:[self == #nil or:[(storeString at:2) == $']]]) ifTrue:[ |
11859 | 711 |
aStream nextPutAll:storeString. |
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
712 |
] ifFalse:[ |
11859 | 713 |
aStream nextPutAll:self. |
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
714 |
]. |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
715 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
716 |
|
608 | 717 |
storeOn:aStream |
718 |
"store myself on a stream" |
|
719 |
||
720 |
aStream nextPutAll:(self storeString) |
|
721 |
! |
|
722 |
||
723 |
storeString |
|
724 |
"return a String for storing the receiver" |
|
725 |
||
11859 | 726 |
|sz "{Class: SmallInteger }" |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
727 |
c anyColon| |
1125 | 728 |
|
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
729 |
sz := self size. |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
730 |
(sz ~~ 0 and:[(self at:1) isLetter]) ifTrue:[ |
11859 | 731 |
anyColon := false. |
732 |
2 to:sz do:[:index | |
|
733 |
c := self at:index. |
|
734 |
c == $: ifTrue:[ |
|
735 |
(index == sz or:[(self at:(index+1)) isLetterOrDigit]) ifFalse:[ |
|
736 |
^ '#' , super storeString. |
|
737 |
]. |
|
738 |
anyColon := true. |
|
739 |
] ifFalse:[ |
|
740 |
c isLetterOrDigit ifFalse:[ |
|
741 |
^ '#' , super storeString |
|
742 |
]. |
|
743 |
]. |
|
744 |
]. |
|
745 |
"no colon in symbol or symbol ends with a colon" |
|
746 |
(anyColon and:[c ~~ $:]) ifFalse:[ |
|
747 |
^ '#' , self |
|
748 |
]. |
|
608 | 749 |
]. |
5896 | 750 |
^ '#' , super storeString |
3285
bd5827c97b21
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3086
diff
changeset
|
751 |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
752 |
" |
11859 | 753 |
#'abc' storeString |
754 |
#'abc:' storeString |
|
755 |
#'abc:def:' storeString |
|
756 |
#'abc:def' storeString |
|
757 |
#'abc::def' storeString |
|
758 |
#'abc &^*' storeString |
|
759 |
#'abcdef::' storeString |
|
760 |
#'hello''world' storeString |
|
761 |
#'' storeString |
|
762 |
#'''' storeString |
|
763 |
#'_hello' storeString |
|
764 |
#'123' storeString |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
765 |
" |
608 | 766 |
! ! |
767 |
||
768 |
!Symbol methodsFor:'queries'! |
|
769 |
||
770 |
species |
|
771 |
"when copying, or concatenating, return instances of this class" |
|
772 |
||
773 |
^ String |
|
774 |
! ! |
|
775 |
||
77 | 776 |
!Symbol methodsFor:'system primitives'! |
777 |
||
778 |
become:anotherObject |
|
779 |
"make all references to the receiver become references to anotherObject |
|
95 | 780 |
and vice-versa. For symbols, some special action is required, to |
781 |
correctly handle a become of the global dictionaries. |
|
77 | 782 |
Anyway: this is very dangerous - mysterous side-effects are to be |
95 | 783 |
expected. |
784 |
||
785 |
Notice: because of the danger here, this method may report an error |
|
159 | 786 |
in future versions" |
77 | 787 |
|
788 |
(Smalltalk includesKey:self) ifTrue:[ |
|
159 | 789 |
super become:anotherObject. |
77 | 790 |
%{ |
159 | 791 |
__rehashSystemDictionaries(); |
77 | 792 |
%}. |
793 |
] ifFalse:[ |
|
159 | 794 |
super become:anotherObject |
77 | 795 |
] |
796 |
! |
|
797 |
||
798 |
becomeNil |
|
799 |
"make all references to the receiver become nil - effectively getting |
|
95 | 800 |
rid of the receiver. For symbols, this is not allowed, if the receiver |
7765 | 801 |
is used as a key in some SystemDictionary. |
95 | 802 |
This can be a very dangerous operation - be warned. |
803 |
||
804 |
Notice: because of the danger here, this method may report an error |
|
11859 | 805 |
in future versions" |
77 | 806 |
|
807 |
(Smalltalk includesKey:self) ifTrue:[ |
|
11859 | 808 |
self primitiveFailed |
77 | 809 |
] ifFalse:[ |
11859 | 810 |
super becomeNil |
77 | 811 |
] |
13388 | 812 |
! |
813 |
||
814 |
grow:newSize |
|
13389 | 815 |
"blocked" |
13388 | 816 |
|
13389 | 817 |
self fixedSizeError |
13388 | 818 |
|
819 |
"Created: / 20-06-2011 / 14:57:36 / cg" |
|
13389 | 820 |
! |
821 |
||
822 |
removeAll |
|
823 |
"blocked" |
|
824 |
||
825 |
self fixedSizeError |
|
826 |
||
827 |
"Created: / 20-06-2011 / 14:59:02 / cg" |
|
77 | 828 |
! ! |
829 |
||
16774 | 830 |
!Symbol methodsFor:'testing'! |
831 |
||
832 |
isSingleByteString |
|
833 |
"returns true only for strings and immutable strings. |
|
834 |
Must replace foo isMemberOf:String and foo class == String" |
|
835 |
||
836 |
^ false |
|
21127 | 837 |
! |
838 |
||
839 |
isSymbol |
|
840 |
"return true, if the receiver is some kind of symbol. |
|
841 |
Since I am a symbol, return always true" |
|
842 |
||
843 |
^ true |
|
16774 | 844 |
! ! |
845 |
||
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
846 |
!Symbol methodsFor:'tracing'! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
847 |
|
4682 | 848 |
traceInto:aRequestor level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
849 |
"double dispatch into tracer, passing my type implicitely in the selector" |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
850 |
|
4682 | 851 |
^ aRequestor traceSymbol:self level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
852 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
853 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
854 |
! ! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
855 |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
856 |
!Symbol methodsFor:'visiting'! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
857 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
858 |
acceptVisitor:aVisitor with:aParameter |
16735 | 859 |
"dispatch for visitor pattern; send #visitSymbol:with: to aVisitor" |
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
860 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
861 |
^ aVisitor visitSymbol:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
862 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
863 |
|
632 | 864 |
!Symbol class methodsFor:'documentation'! |
865 |
||
16155 | 866 |
version |
18619 | 867 |
^ '$Header$' |
16155 | 868 |
! |
869 |
||
13423 | 870 |
version_CVS |
18619 | 871 |
^ '$Header$' |
12473
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
872 |
! |
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
873 |
|
13423 | 874 |
version_SVN |
15524 | 875 |
^ '$ Id: Symbol.st 10648 2011-06-23 15:55:10Z vranyj1 $' |
632 | 876 |
! ! |
21017 | 877 |