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