!=========================================================================
! Copyright (C) VMware, Inc. 1986-2011.  All Rights Reserved.
!
! $Id: canonsymboldict.gs,v 1.10 2008-01-09 22:50:09 stever Exp $
!
!  New class for AllSymbols in Gemstone64 1.0
!
! Superclass Hierarchy:
!   CanonSymbolDict, CanonStringDict, 
!   AbstractDictionary, Collection, Object.
!
!=========================================================================

expectvalue %String
run
CanonStringDict _newKernelSubclass: #CanonSymbolDict 
  instVarNames: #()
  classVars: #()
  classInstVars: #()
  poolDictionaries: #[]
  inDictionary: Globals
  constraints: #[ ]
  instancesInvariant: false
  isModifiable: false
  reservedOop: 935 
%

expectvalue true
run
CanonSymbolDict _disallowGciCreateStore .
^ true
%

removeallmethods CanonSymbolDict
removeallclassmethods CanonSymbolDict

category: 'For Documentation Installation only'
classmethod: CanonSymbolDict
installDocumentation

| doc txt |
doc := GsClassDocumentation newForClass: self.

txt := (GsDocText new) details:
'CanonicalSymbolDict is the class of AllSymbols. Instances may
 only be modified by SystemUser, or the SymbolCreation session.' .
doc documentClassWith: txt.

self description: doc.
%


! ------------------- Class methods 

! ------------------- Instance methods 
category: 'Private'
method: CanonSymbolDict
validateSystemUser

"validate that the current session is SystemUser."

System myUserProfile userId = 'SystemUser' ifFalse:[
  self error:'instance only modifiable by SystemUser'.
  self _uncontinuableError .
  ^ nil
  ].
^ self  
%

category: 'Private'
method: CanonSymbolDict
_initializeWithoutClear: newSize

"Private. Initializes the instance variables of the receiver to be an empty
 KeyValueDictionary of the specified size. Does not clear the contents
 of the receiver - assumes they are all nil."

self validateSystemUser .
super _initializeWithoutClear: newSize .
^self
%

category: 'Initializing'
method: CanonSymbolDict
initialize: itsSize

"Initializes the instance variables of the receiver to be an empty
 dictionary of the specified size."

self validateSystemUser .
super initialize: itsSize
%


category: 'Adding'
method: CanonSymbolDict
add: aString

"Disallowed, only the Virtual machine's creation of a Symbol
 should add elements to AllSymbols."

^ self shouldNotImplement: #add:

%

category: 'Adding'
method: CanonSymbolDict
addKey: aSymbol

"Only used during repository conversion."

self validateSystemUser .
"We expect that AllSymbols is not yet an instance of this class."
(Globals at:#AllSymbols) class == CanonSymbolDict ifTrue:[
  ^ self error:'Illegal use for other than repository conversion' .
].
aSymbol class == Symbol ifFalse:[
  aSymbol class == DoubleByteSymbol ifFalse:[
    ^ self error:'bad argument class ' , aSymbol class name 
  ].
].
^ super add: aSymbol .
%

category: 'Adding'
method: CanonSymbolDict
addAll: aCollection

"Disallowed, only the Virtual machine's creation of a Symbol
 should add elements to AllSymbols."

^ self shouldNotImplement: #addAll:
%

! associationsDo: not implemented  , CanonSymbolDict's do not hold assocations


category: 'Removing'
method: CanonSymbolDict
remove: aString

^ self shouldNotImplement: #remove:
%

category: 'Removing'
method: CanonSymbolDict
remove: aString ifAbsent: aBlock

^ self shouldNotImplement: #remove:ifAbsent:
%

category: 'Removing'
method: CanonSymbolDict
removeKey: aKey ifAbsent: aBlock

"To remove Symbols from AllSymbols:
   1. you must be SystemUser,
   2. stop the Symbol Creation Session , and all other user sessions
      (System stopSymbolCreationSession . System stopUserSessions)
   3. The Symbols to be removed from AllSymbols
      must be referenced only from AllSymbols ,
      as confirmed by SystemRepository listReferences: .
   4. execute removals from AllSymbols and commit . 
   5. System startSymbolCreationSession .
"

self validateSystemUser .
^ super removeKey: aKey ifAbsent: aBlock
%

! deleted _canonicalizeSymbolAt: offset oldSymbol: oldSym newSymbol: newSym

category: 'Private'
method: CanonSymbolDict
_resetParentRef

"Private. After a become:, the parent refs of the collisionBuckets must
 be reset to point to the correct parent."

self validateSystemUser .
^ super _resetParentRef 
%

category: 'Private'
method: CanonSymbolDict
changeToSegment: aSegment

"Assigns the receiver and all its components to the given segment. Returns
 the receiver."

self validateSystemUser .
^ super changeToSegment: aSegment
%
