author | Merge Script |
Sun, 07 Jun 2015 06:38:49 +0200 | |
branch | jv |
changeset 18457 | 214d760f8247 |
parent 18366 | a6e62e167c32 |
child 18487 | 8735bd9eee2f |
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, |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
62 |
any send of 'foo' from wíthin the NS-namespace will invoke the second method. |
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 |
]. |
133 |
^ ObjectMemory allocationFailureSignal raise. |
|
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 |
|
17185 | 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 |
||
196 |
isUnary |
|
16714 | 197 |
"same as isUnarySelector - for squeak compatibility" |
198 |
||
11819 | 199 |
^ self isUnarySelector |
13690 | 200 |
! |
201 |
||
202 |
precedence |
|
203 |
"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
|
204 |
unary < binary < keyword" |
13690 | 205 |
|
206 |
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
|
207 |
ifTrue: [^ 0]. |
13690 | 208 |
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
|
209 |
ifFalse: [^ 2]. |
13690 | 210 |
self last = $: |
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
211 |
ifTrue: [^ 3]. |
13690 | 212 |
^ 1 |
213 |
||
214 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
215 |
self assert:(#foo precedence < #+ precedence). |
13690 | 216 |
self assert:(#+ precedence < #key: precedence). |
217 |
self assert:(#foo precedence < #key: precedence). |
|
218 |
" |
|
219 |
||
220 |
"Created: / 12-09-2011 / 14:53:54 / cg" |
|
11819 | 221 |
! ! |
222 |
||
7261 | 223 |
!Symbol methodsFor:'Compatibility-VW'! |
7153 | 224 |
|
225 |
<< catalogID |
|
226 |
"create and return a new UserMessage, with the receiver as key, |
|
227 |
and the argument as cataglogID. |
|
228 |
VW compatibility." |
|
229 |
||
230 |
^ UserMessage key:self catalogID:catalogID |
|
231 |
||
232 |
" |
|
11859 | 233 |
(#theFooMessage << #myMessages) |
234 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') |
|
235 |
(#theFooMessage >> 'cannot read subclass of metaclass') |
|
7153 | 236 |
" |
237 |
! |
|
238 |
||
239 |
>> aString |
|
240 |
"create and return a new UserMessage, with the receiver as key, |
|
241 |
and the argument as defaultString. |
|
242 |
VW compatibility." |
|
243 |
||
11859 | 244 |
^ UserMessage key:self defaultString:aString |
7153 | 245 |
|
246 |
" |
|
11859 | 247 |
(#theFooMessage << #myMessages) |
248 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') |
|
249 |
(#theFooMessage >> 'cannot read subclass of metaclass') |
|
7153 | 250 |
" |
251 |
! ! |
|
252 |
||
1 | 253 |
!Symbol methodsFor:'accessing'! |
254 |
||
255 |
basicAt:index put:something |
|
345 | 256 |
"report an error if an interned symbol is about to be changed |
1219 | 257 |
- interned symbols may NOT be changed. |
258 |
For uninterned symbols, this is allowed." |
|
1 | 259 |
|
77 | 260 |
self knownAsSymbol ifTrue:[ |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
261 |
self noModificationError. |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
262 |
"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
|
263 |
Raise again non-resumable" |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
264 |
NoModificationError raiseWith:self errorString:' - interned symbols cannot be changed'. |
77 | 265 |
]. |
266 |
" |
|
267 |
uninterned - allow change |
|
268 |
" |
|
269 |
^ super basicAt:index put:something |
|
1219 | 270 |
|
271 |
"Modified: 19.4.1996 / 11:16:10 / cg" |
|
13423 | 272 |
! |
273 |
||
274 |
nameSpace |
|
16735 | 275 |
"if I have the format of a namespace-selector, |
276 |
retrieve the namespace. Otherwise, return nil. |
|
277 |
Also return nil, if that namespace does not exist. |
|
278 |
Namespace selectors have a special, fix defined format, which |
|
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
279 |
is also known in the VM. |
16735 | 280 |
They must be of the form :<ns>::<sel>, |
17512 | 281 |
where <ns> is the namespace and <sel> is the raw selector. |
282 |
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
|
283 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 284 |
|
17516 | 285 |
|nsPart| |
286 |
||
287 |
self isNameSpaceSelector ifFalse:[^ nil]. |
|
288 |
||
289 |
nsPart := self nameSpaceAndSelectorParts first. |
|
290 |
^ Smalltalk at:nsPart asSymbol |
|
16735 | 291 |
|
292 |
" |
|
293 |
#':foo:' nameSpace -> nil (bad format) |
|
294 |
#':foo::bar' nameSpace -> nil (non existing) |
|
17516 | 295 |
#':Tools::bar' nameSpace -> Tools |
16735 | 296 |
" |
13423 | 297 |
|
298 |
"Created: / 20-07-2010 / 10:41:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
299 |
! |
|
300 |
||
301 |
nameSpaceAndSelector |
|
16735 | 302 |
"return a two element tuple consisting of the namespace and the raw selector. |
303 |
If I do not have the format of a namespace-selector, or the namespace is non-existing, |
|
304 |
the first element of the returned tuple will be nil. |
|
305 |
Namespace selectors have a special, fix defined format, which |
|
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
306 |
is also known in the VM. |
16735 | 307 |
They must be of the form :<ns>::<sel>, |
17512 | 308 |
where <ns> is the namespace and <sel> is the raw selector. |
309 |
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
|
310 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 311 |
|
17516 | 312 |
|parts ns| |
13423 | 313 |
|
314 |
self isNameSpaceSelector ifFalse:[ |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
315 |
^ Array with:nil with:self |
13423 | 316 |
]. |
17516 | 317 |
parts := self nameSpaceAndSelectorParts. |
318 |
ns := Smalltalk at:parts first asSymbol. |
|
319 |
^ Array with:ns with:parts second |
|
13423 | 320 |
|
16735 | 321 |
" |
322 |
#':foo:bar' nameSpaceAndSelector -> #(nil #':foo:bar') |
|
323 |
#':foo::bar' nameSpaceAndSelector -> #(nil #bar) |
|
324 |
#':Tools::foo' nameSpaceAndSelector -> #(Tools (* NameSpace *) #foo) |
|
325 |
" |
|
326 |
||
13423 | 327 |
"Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
328 |
! |
|
329 |
||
17516 | 330 |
nameSpaceAndSelectorParts |
331 |
"return a two element tuple consisting of the namespace name and the raw selector. |
|
332 |
If I do not have the format of a namespace-selector, or the namespace is non-existing, |
|
333 |
the first element of the returned tuple will be nil. |
|
334 |
Namespace selectors have a special, fix defined format, which |
|
335 |
is also known in the VM. |
|
336 |
They must be of the form :<ns>::<sel>, |
|
337 |
where <ns> is the namespace and <sel> is the raw selector. |
|
338 |
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
|
339 |
is legal, and this can be checked quickly by just looking at the first character." |
17516 | 340 |
|
341 |
|nsPart selPart idx| |
|
342 |
||
343 |
self isNameSpaceSelector ifFalse:[ |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
344 |
^ Array with:nil with:self |
17516 | 345 |
]. |
346 |
idx := self indexOf:$: startingAt:3. |
|
347 |
nsPart := self copyFrom:2 to:idx - 1. |
|
348 |
selPart := self copyFrom:idx + 2. |
|
349 |
^ Array with:nsPart with:selPart asSymbol |
|
350 |
||
351 |
" |
|
352 |
#':foo:bar' nameSpaceAndSelector -> #(nil #':foo:bar') |
|
353 |
#':foo::bar' nameSpaceAndSelector -> #(nil #bar) |
|
354 |
#':Tools::foo' nameSpaceAndSelector -> #(Tools (* NameSpace *) #foo) |
|
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. |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
363 |
Namespace selectors have a special, fix defined format, |
17516 | 364 |
which is also known in the VM. |
365 |
They must be of the form :<ns>::<sel>, |
|
366 |
where <ns> is the namespace and <sel> is the raw selector. |
|
367 |
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
|
368 |
is legal, and this can be checked quickly by just looking at the first character." |
17516 | 369 |
|
370 |
self isNameSpaceSelector ifFalse:[^ nil]. |
|
371 |
^ self nameSpaceAndSelectorParts first. |
|
372 |
||
373 |
" |
|
374 |
#':foo:' nameSpacePart -> nil (bad format) |
|
375 |
#':foo::bar' nameSpacePart -> 'foo' |
|
376 |
#':Tools::bar' nameSpacePart -> 'Tools' |
|
377 |
" |
|
378 |
! |
|
379 |
||
13423 | 380 |
selector |
17512 | 381 |
<resource: #obsolete> |
382 |
||
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
383 |
"if I have the format of a namespace-selector, retrieve the raw selector. |
17512 | 384 |
Otherwise, return myself. |
385 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
16735 | 386 |
They must be of the form :<ns>::<sel>, |
17512 | 387 |
where <ns> is the namespace and <sel> is the raw selector. |
388 |
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
|
389 |
is legal, and this can be checked quickly by just looking at the first character." |
17512 | 390 |
|
391 |
self obsoleteMethodWarning:'use selectorWithoutNameSpace'. |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
392 |
^ self selectorWithoutNameSpace |
17512 | 393 |
! |
394 |
||
395 |
selectorWithoutNameSpace |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
396 |
"if I have the format of a namespace-selector, retrieve the raw selector. |
17512 | 397 |
Otherwise, return myself. |
398 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
399 |
They must be of the form :<ns>::<sel>, |
|
400 |
where <ns> is the namespace and <sel> is the raw selector. |
|
401 |
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
|
402 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 403 |
|
404 |
^ self isNameSpaceSelector |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
405 |
ifTrue: [ self nameSpaceAndSelectorParts second ] |
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
406 |
ifFalse:[ self ] |
16735 | 407 |
|
408 |
" |
|
17516 | 409 |
#':foo:' selectorWithoutNameSpace -> #':foo:' (bad format) |
410 |
#':foo::bar' selectorWithoutNameSpace -> bar |
|
411 |
#':Tools::bar' selectorWithoutNameSpace -> bar |
|
16735 | 412 |
" |
13423 | 413 |
|
414 |
"Created: / 20-07-2010 / 10:41:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1 | 415 |
! ! |
416 |
||
13423 | 417 |
|
608 | 418 |
!Symbol methodsFor:'comparing'! |
159 | 419 |
|
608 | 420 |
= something |
421 |
"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
|
422 |
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
|
423 |
(which can to be compared using #==). |
608 | 424 |
If the argument is a symbol, we use a quick pointer compare, instead of |
425 |
the inherited value compare." |
|
13 | 426 |
|
608 | 427 |
%{ /* NOCONTEXT */ |
428 |
OBJ cls; |
|
13 | 429 |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
430 |
if (something == self) RETURN(true); |
608 | 431 |
if (! __isNonNilObject(something)) RETURN(false); |
432 |
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
|
433 |
RETURN (false); |
608 | 434 |
} |
14658 | 435 |
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
|
436 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? true : false); |
345 | 437 |
} |
438 |
%}. |
|
608 | 439 |
"fall back; could be a TwoByteString, or a collection of Characters" |
1 | 440 |
|
608 | 441 |
^ super = something |
427 | 442 |
! |
443 |
||
356 | 444 |
identityHash |
445 |
"interned symbols can return a better hash key" |
|
446 |
||
13881 | 447 |
%{ /* NOCONTEXT */ |
448 |
||
16891
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16890
diff
changeset
|
449 |
REGISTER unsigned int val; // yes: only 32 bit |
14651 | 450 |
REGISTER unsigned char *cp; |
356 | 451 |
int l; |
452 |
||
14651 | 453 |
if (__qIsSymbol(self)) { |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
454 |
val = __GET_HASH(self); |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
455 |
/* |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
456 |
* only do it, if I have no standard hash key |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
457 |
* assigned (which can only happen due to a #become:, |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
458 |
* or by creating a symbol uninterned, and interning it |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
459 |
* after it got a hashKey assigned. |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
460 |
*/ |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
461 |
if (val == 0) { |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
462 |
extern unsigned int __symbolHash(char *); |
14651 | 463 |
|
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
464 |
cp = __stringVal(self); |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
465 |
l = __stringSize(self); |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
466 |
|
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
467 |
val = __symbolHash(cp); |
16891
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16890
diff
changeset
|
468 |
// make sure, it fits into a smallInt |
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16890
diff
changeset
|
469 |
val = (val ^ (val >> 30)) & 0x3FFFFFFF; |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
470 |
} else { |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
471 |
val = __MAKE_HASH__(val); |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
472 |
} |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
473 |
RETURN ( __mkSmallInteger(val) ); |
14651 | 474 |
} |
356 | 475 |
%}. |
14651 | 476 |
|
477 |
^ super identityHash. |
|
3985 | 478 |
|
479 |
" |
|
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
480 |
|hashColl hashSet| |
3985 | 481 |
|
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
482 |
hashColl := OrderedCollection new:20000. |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
483 |
Symbol allInstancesDo:[:instance | |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
484 |
hashColl add:instance identityHash |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
485 |
]. |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
486 |
hashSet := hashColl asSet. |
3985 | 487 |
|
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
488 |
Transcript showCR:'Symbols: ', hashColl size printString, |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
489 |
' unique hash keys: ', hashSet size printString, |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
490 |
' collisions:', (hashColl size - hashSet size) printString. |
3985 | 491 |
" |
13881 | 492 |
|
493 |
"Modified (comment): / 26-12-2011 / 14:32:10 / cg" |
|
370 | 494 |
! |
495 |
||
496 |
~= something |
|
497 |
"return true, if the receiver and argument do not consist of the same characters. |
|
11859 | 498 |
Redefined here, for more efficient #~= comparison of symbols |
370 | 499 |
(which ought to be compared using #~~). |
500 |
If the argument is a symbol, we use a quick pointer compare, instead of |
|
501 |
the inherited value compare." |
|
502 |
||
503 |
%{ /* NOCONTEXT */ |
|
504 |
OBJ cls; |
|
505 |
||
379 | 506 |
if (! __isNonNilObject(something)) RETURN(true); /* cannot be equal */ |
370 | 507 |
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
|
508 |
RETURN (self == something ? false : true); |
370 | 509 |
} |
14658 | 510 |
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
|
511 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? false : true); |
370 | 512 |
} |
513 |
%}. |
|
514 |
"fall back; could be a TwoByteString, or a collection of Characters" |
|
515 |
||
516 |
^ super ~= something |
|
356 | 517 |
! ! |
518 |
||
608 | 519 |
!Symbol methodsFor:'converting'! |
520 |
||
521 |
asString |
|
522 |
"return a string with printname taken from mine" |
|
523 |
||
524 |
%{ /* NOCONTEXT */ |
|
525 |
OBJ s; |
|
526 |
||
2565 | 527 |
s = __MKSTRING_ST(self); |
608 | 528 |
if (s != nil) { |
11859 | 529 |
RETURN (s); |
608 | 530 |
} |
531 |
%}. |
|
5434 | 532 |
^ (String new:(self size)) |
11859 | 533 |
replaceFrom:1 with:self startingAt:1 |
608 | 534 |
! |
535 |
||
536 |
asSymbol |
|
9231 | 537 |
"Return a unique symbol with the name taken from the receivers characters. |
608 | 538 |
Since I am a symbol - just return myself" |
539 |
||
540 |
^ self |
|
541 |
! |
|
542 |
||
543 |
asSymbolIfInterned |
|
17185 | 544 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
608 | 545 |
Since I am a symbol - just return myself" |
546 |
||
547 |
^ self |
|
548 |
! ! |
|
549 |
||
550 |
!Symbol methodsFor:'copying'! |
|
551 |
||
552 |
copy |
|
553 |
"return a copy of myself |
|
4729 | 554 |
- reimplemented here since symbols are immutable." |
608 | 555 |
|
556 |
^ self |
|
557 |
! |
|
558 |
||
3659 | 559 |
copyReplaceAll:oldElement with:newElement |
560 |
"return a copy of the receiver as a string, where all elements equal to oldElement |
|
561 |
have been replaced by newElement." |
|
562 |
||
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
563 |
"/ 'Warning: #copyReplaceAll:with: will change semantics as defined in ANSI soon' errorPrintCR. |
3659 | 564 |
^ self asString replaceAll:oldElement with:newElement |
565 |
||
566 |
"Created: / 18.7.1998 / 23:03:38 / cg" |
|
567 |
! |
|
568 |
||
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
569 |
copyReplacing:oldElement withObject:newElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
570 |
"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
|
571 |
have been replaced by newElement. |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
572 |
ANSI version of what used to be #copyReplaceAll:with:" |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
573 |
|
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
574 |
^ self asString replaceAll:oldElement with:newElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
575 |
! |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
576 |
|
608 | 577 |
deepCopy |
578 |
"return a copy of myself |
|
4729 | 579 |
- reimplemented here since symbols are immutable." |
608 | 580 |
|
581 |
^ self |
|
582 |
! |
|
583 |
||
10950 | 584 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8383 | 585 |
"return a deep copy of myself |
4729 | 586 |
- reimplemented here since symbols are immutable." |
608 | 587 |
|
588 |
^ self |
|
589 |
! |
|
590 |
||
591 |
shallowCopy |
|
592 |
"return a copy of myself |
|
10581 | 593 |
- reimplemented here since symbols are immutable and unique, |
594 |
so we return the receiver." |
|
608 | 595 |
|
596 |
^ self |
|
10581 | 597 |
|
598 |
"Modified: / 31-05-2007 / 15:32:30 / cg" |
|
608 | 599 |
! |
600 |
||
601 |
simpleDeepCopy |
|
602 |
"return a copy of myself |
|
4729 | 603 |
- reimplemented here since symbols are immutable." |
608 | 604 |
|
605 |
^ self |
|
606 |
! ! |
|
607 |
||
16154 | 608 |
!Symbol methodsFor:'evaluation'! |
609 |
||
610 |
value: el |
|
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
611 |
"this is sent by collection enumeration methods, |
16155 | 612 |
if a symbol is given instead of a block as loop-block argument" |
16154 | 613 |
|
614 |
^ el perform:self. |
|
615 |
||
616 |
" |
|
617 |
this allows us to say: |
|
618 |
||
619 |
#(1 2 3 4) do: #printCR |
|
620 |
#(1 -2 -3 4) collect: #abs |
|
621 |
" |
|
622 |
! |
|
623 |
||
624 |
value: el value:arg |
|
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
625 |
"this is sent by collection enumeration methods, |
16155 | 626 |
if a symbol is given instead of a block as loop-block argument" |
16154 | 627 |
|
628 |
^ el perform:self with:arg. |
|
629 |
||
630 |
" |
|
631 |
this allows us to say: |
|
632 |
||
633 |
#(1 2 3 4) with:#(10 20 30 40) collect: #+ |
|
634 |
" |
|
635 |
! ! |
|
636 |
||
14651 | 637 |
|
608 | 638 |
!Symbol methodsFor:'printing & storing'! |
639 |
||
640 |
printOn:aStream |
|
4392 | 641 |
"append a user printed representation of the receiver to aStream. |
642 |
The format is suitable for a human - not meant to be read back. |
|
643 |
||
608 | 644 |
In contrast to ST-80, this does return the symbols characters |
645 |
without any leading #. Therefore, you can directly send symbols' |
|
646 |
printStrings to some output device. This is incompatible, but easier |
|
647 |
to use." |
|
648 |
||
649 |
"/ ST-80 behavior: |
|
650 |
||
651 |
"/ self storeOn:aStream |
|
652 |
||
653 |
aStream nextPutAll:self |
|
654 |
! |
|
655 |
||
656 |
printString |
|
657 |
"return a printed representation of the receiver. |
|
658 |
In contrast to ST-80, this does return the symbols characters |
|
659 |
without any leading #. Therefore, you can directly send symbols' |
|
660 |
printStrings to some output device. This is incompatible, but easier |
|
661 |
to use." |
|
662 |
||
663 |
"/ ST-80 behavior: |
|
664 |
"/ ^ self storeString |
|
665 |
||
666 |
^ self asString |
|
667 |
! |
|
668 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
669 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
670 |
"store myself on a stream. |
8368 | 671 |
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
|
672 |
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
|
673 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
674 |
|storeString| |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
675 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
676 |
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
|
677 |
(self == #true or:[self == #false or:[self == #nil or:[(storeString at:2) == $']]]) ifTrue:[ |
11859 | 678 |
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
|
679 |
] ifFalse:[ |
11859 | 680 |
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
|
681 |
]. |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
682 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
683 |
|
608 | 684 |
storeOn:aStream |
685 |
"store myself on a stream" |
|
686 |
||
687 |
aStream nextPutAll:(self storeString) |
|
688 |
! |
|
689 |
||
690 |
storeString |
|
691 |
"return a String for storing the receiver" |
|
692 |
||
11859 | 693 |
|sz "{Class: SmallInteger }" |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
694 |
c anyColon| |
1125 | 695 |
|
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
696 |
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
|
697 |
(sz ~~ 0 and:[(self at:1) isLetter]) ifTrue:[ |
11859 | 698 |
anyColon := false. |
699 |
2 to:sz do:[:index | |
|
700 |
c := self at:index. |
|
701 |
c == $: ifTrue:[ |
|
702 |
(index == sz or:[(self at:(index+1)) isLetterOrDigit]) ifFalse:[ |
|
703 |
^ '#' , super storeString. |
|
704 |
]. |
|
705 |
anyColon := true. |
|
706 |
] ifFalse:[ |
|
707 |
c isLetterOrDigit ifFalse:[ |
|
708 |
^ '#' , super storeString |
|
709 |
]. |
|
710 |
]. |
|
711 |
]. |
|
712 |
"no colon in symbol or symbol ends with a colon" |
|
713 |
(anyColon and:[c ~~ $:]) ifFalse:[ |
|
714 |
^ '#' , self |
|
715 |
]. |
|
608 | 716 |
]. |
5896 | 717 |
^ '#' , super storeString |
3285
bd5827c97b21
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3086
diff
changeset
|
718 |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
719 |
" |
11859 | 720 |
#'abc' storeString |
721 |
#'abc:' storeString |
|
722 |
#'abc:def:' storeString |
|
723 |
#'abc:def' storeString |
|
724 |
#'abc::def' storeString |
|
725 |
#'abc &^*' storeString |
|
726 |
#'abcdef::' storeString |
|
727 |
#'hello''world' storeString |
|
728 |
#'' storeString |
|
729 |
#'''' storeString |
|
730 |
#'_hello' storeString |
|
731 |
#'123' storeString |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
732 |
" |
608 | 733 |
! ! |
734 |
||
735 |
!Symbol methodsFor:'queries'! |
|
736 |
||
4987 | 737 |
isInfix |
738 |
"return true, if the receiver is a binary message selector" |
|
739 |
||
7350
a62d53937a6b
ansified (isAlphaNumeric -> isLetterOrDigit)
Claus Gittinger <cg@exept.de>
parents:
7301
diff
changeset
|
740 |
^ self first isLetterOrDigit not |
4987 | 741 |
|
742 |
" |
|
11859 | 743 |
#at:put: isInfix |
744 |
#at: isInfix |
|
745 |
#+ isInfix |
|
746 |
#size isInfix |
|
4987 | 747 |
" |
748 |
||
749 |
"Created: / 1.11.1997 / 12:34:55 / cg" |
|
750 |
"Modified: / 1.11.1997 / 12:36:37 / cg" |
|
751 |
! |
|
752 |
||
11859 | 753 |
isSymbol |
608 | 754 |
"return true, if the receiver is some kind of symbol. |
755 |
Since I am a symbol, return always true" |
|
756 |
||
757 |
^ true |
|
758 |
! |
|
759 |
||
760 |
species |
|
761 |
"when copying, or concatenating, return instances of this class" |
|
762 |
||
763 |
^ String |
|
764 |
! ! |
|
765 |
||
77 | 766 |
!Symbol methodsFor:'system primitives'! |
767 |
||
768 |
become:anotherObject |
|
769 |
"make all references to the receiver become references to anotherObject |
|
95 | 770 |
and vice-versa. For symbols, some special action is required, to |
771 |
correctly handle a become of the global dictionaries. |
|
77 | 772 |
Anyway: this is very dangerous - mysterous side-effects are to be |
95 | 773 |
expected. |
774 |
||
775 |
Notice: because of the danger here, this method may report an error |
|
159 | 776 |
in future versions" |
77 | 777 |
|
778 |
(Smalltalk includesKey:self) ifTrue:[ |
|
159 | 779 |
super become:anotherObject. |
77 | 780 |
%{ |
159 | 781 |
__rehashSystemDictionaries(); |
77 | 782 |
%}. |
783 |
] ifFalse:[ |
|
159 | 784 |
super become:anotherObject |
77 | 785 |
] |
786 |
! |
|
787 |
||
788 |
becomeNil |
|
789 |
"make all references to the receiver become nil - effectively getting |
|
95 | 790 |
rid of the receiver. For symbols, this is not allowed, if the receiver |
7765 | 791 |
is used as a key in some SystemDictionary. |
95 | 792 |
This can be a very dangerous operation - be warned. |
793 |
||
794 |
Notice: because of the danger here, this method may report an error |
|
11859 | 795 |
in future versions" |
77 | 796 |
|
797 |
(Smalltalk includesKey:self) ifTrue:[ |
|
11859 | 798 |
self primitiveFailed |
77 | 799 |
] ifFalse:[ |
11859 | 800 |
super becomeNil |
77 | 801 |
] |
13388 | 802 |
! |
803 |
||
804 |
grow:newSize |
|
13389 | 805 |
"blocked" |
13388 | 806 |
|
13389 | 807 |
self fixedSizeError |
13388 | 808 |
|
809 |
"Created: / 20-06-2011 / 14:57:36 / cg" |
|
13389 | 810 |
! |
811 |
||
812 |
removeAll |
|
813 |
"blocked" |
|
814 |
||
815 |
self fixedSizeError |
|
816 |
||
817 |
"Created: / 20-06-2011 / 14:59:02 / cg" |
|
77 | 818 |
! ! |
819 |
||
16774 | 820 |
!Symbol methodsFor:'testing'! |
821 |
||
822 |
isSingleByteString |
|
823 |
"returns true only for strings and immutable strings. |
|
824 |
Must replace foo isMemberOf:String and foo class == String" |
|
825 |
||
826 |
^ false |
|
827 |
! ! |
|
828 |
||
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
829 |
!Symbol methodsFor:'tracing'! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
830 |
|
4682 | 831 |
traceInto:aRequestor level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
832 |
"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
|
833 |
|
4682 | 834 |
^ aRequestor traceSymbol:self level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
835 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
836 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
837 |
! ! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
838 |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
839 |
!Symbol methodsFor:'visiting'! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
840 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
841 |
acceptVisitor:aVisitor with:aParameter |
16735 | 842 |
"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
|
843 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
844 |
^ aVisitor visitSymbol:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
845 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
846 |
|
632 | 847 |
!Symbol class methodsFor:'documentation'! |
848 |
||
16155 | 849 |
version |
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
850 |
^ '$Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.117 2015-05-18 00:06:52 cg Exp $' |
16155 | 851 |
! |
852 |
||
13423 | 853 |
version_CVS |
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
854 |
^ '$Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.117 2015-05-18 00:06:52 cg Exp $' |
12473
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
855 |
! |
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
856 |
|
13423 | 857 |
version_SVN |
15524 | 858 |
^ '$ Id: Symbol.st 10648 2011-06-23 15:55:10Z vranyj1 $' |
632 | 859 |
! ! |
17185 | 860 |