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