UndefinedObject.st
author claus
Mon, 10 Oct 1994 01:29:28 +0100
changeset 159 514c749165c3
parent 95 d22739a0c6e9
child 202 40ca7cc6fb9c
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1988 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

Object subclass:#UndefinedObject
       instanceVariableNames:''
       classVariableNames:''
       poolDictionaries:''
       category:'Kernel-Objects'
!

UndefinedObject comment:'
COPYRIGHT (c) 1988 by Claus Gittinger
	      All Rights Reserved

$Header: /cvs/stx/stx/libbasic/UndefinedObject.st,v 1.12 1994-10-10 00:29:03 claus Exp $
'!

!UndefinedObject class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1988 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
"
$Header: /cvs/stx/stx/libbasic/UndefinedObject.st,v 1.12 1994-10-10 00:29:03 claus Exp $
"
!

documentation
"
    there is only one instance of this class: nil, representing an undefined
    or otherwise unspecified object.

    All instance variables, array elements and even method/block local 
    variables are initially set to nil.
    Since in Smalltalk/X, nil is represented by a special pointer value,
    there can be only one instance of UndefinedObject, and no subclassing is
    possible. 
    (to be exact: subclassing is technically possible, but instances of it 
     would not be recognized as being nil - therefore, subclassing is blocked)
"
! !

!UndefinedObject class methodsFor:'instance creation'!

basicNew
    "catch new - there MUST be only one nil in the system"

    ^ nil
!

basicNew:size
    "catch new - there MUST be only one nil in the system"

    ^ nil
! !

!UndefinedObject class methodsFor:'queries'!

canBeSubclassed
    "return true, if its allowed to create subclasses of the receiver.
     Return nil here - since it is NOT possible for UndefinedObject"

    ^ false
! !

!UndefinedObject methodsFor:'error catching'!

basicAt:index
    "catch array access - its illegal
     defined here since basicAt: in Object ommits the nil-check"

    ^ self notIndexed
!

basicAt:index put:anObject
    "catch array access - its illegal
     defined here since basicAt:put: in Object ommits the nil-check"

    ^ self notIndexed
! !

!UndefinedObject methodsFor:'testing'!

isNil
    "return true if I am nil - since I am, return true"

    ^ true
!

notNil
    "return true if I am not nil - since I am nil, return false"

    ^ false
!

size
    "return the number of indexed instvars
     defined here since size in Object ommits the nil-check"
 
    ^ 0
!

basicSize
    "return the number of indexed instvars
     defined here since size in Object ommits the nil-check"

    ^ 0
!

hash
    "return an integer useful as a hash key"

    ^ 0
!

identityHash
    "return an integer useful as a hash key"

    ^ 0
!

isLiteral
    "return true, if the receiver can be used as a literal
     (i.e. can be used in constant arrays)"

    ^ true
! !

!UndefinedObject methodsFor:'copying'!

copy
    "return a shallow copy of myself
     - since there is only one nil in the system return self"

    ^ self
!

shallowCopy
    "return a shallow copy of myself
     - since there is only one nil in the system return self"

    ^ self
!

deepCopy
    "return a deep copy of myself
     - since there is only one nil in the system return self"

    ^ self
!

simpleDeepCopy
    "return a deep copy of myself
     - since there is only one nil in the system return self"

    ^ self
!

deepCopyUsing:aDictionary
    "return a deep copy of myself
     - since there is only one nil in the system return self"

    ^ self
! !

!UndefinedObject methodsFor:'printing & storing'!

printString
    "return a string for printing myself"

    ^ 'nil'
!

storeString
    "return a string for storing myself"

    ^ 'nil'
!

printOn:aStream
    "append a printed representation of the receiver to the
     argument, aStream"

    aStream nextPutAll:'nil'
!

storeOn:aStream
    "append a printed representation of the receiver to the
     argument, aStream, which allows reconstruction of it"

    ^ self printOn:aStream
! !

!UndefinedObject methodsFor:'binary storage'!

hasSpecialBinaryRepresentation
    ^ true
!

storeBinaryOn: stream manager: manager
    stream nextPut: (manager codeForNil)
! !

!UndefinedObject methodsFor:'subclass creation'!

subclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
    "create a new class which has nil as superclass 
     - i.e. traps into doesNotUnderstand: for all of its messages."

    |newClass upd|

    upd := Class updateChanges:false.
    [
	newClass := Object subclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat.
    ] valueNowOrOnUnwindDo:[
	Class updateChanges:upd
    ].
    newClass notNil ifTrue:[
	newClass setSuperclass:nil.
	newClass 
	    setSelectors:(Array with:#class
				with:#doesNotUnderstand:)
	    methods:(Array with:(Object compiledMethodAt:#class)
			   with:(Object compiledMethodAt:#doesNotUnderstand:)).
	Class addChangeRecordForClass:newClass.
    ].
    ^ newClass
! 

variableSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
    "create a new class which has nil as superclass 
     - i.e. traps into doesNotUnderstand: for all of its messages."

    |newClass upd|

    upd := Class updateChanges:false.
    [
	newClass := Object variableSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat.
    ] valueNowOrOnUnwindDo:[
	Class updateChanges:upd
    ].
    newClass notNil ifTrue:[
	newClass setSuperclass:nil.
	newClass 
	    setSelectors:(Array with:#class
				with:#doesNotUnderstand:)
	    methods:(Array with:(Object compiledMethodAt:#class)
			   with:(Object compiledMethodAt:#doesNotUnderstand:)).
	Class addChangeRecordForClass:newClass.
    ].
    ^ newClass
! 

variableByteSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat
    "create a new class which has nil as superclass 
     - i.e. traps into doesNotUnderstand: for all of its messages."

    |newClass upd|

    upd := Class updateChanges:false.
    [
	newClass := Object variableByteSubclass:t instanceVariableNames:f classVariableNames:d poolDictionaries:s category:cat.
    ] valueNowOrOnUnwindDo:[
	Class updateChanges:upd
    ].
    newClass notNil ifTrue:[
	newClass setSuperclass:nil.
	newClass 
	    setSelectors:(Array with:#class
				with:#doesNotUnderstand:)
	    methods:(Array with:(Object compiledMethodAt:#class)
			   with:(Object compiledMethodAt:#doesNotUnderstand:)).
	Class addChangeRecordForClass:newClass.
    ].
    ^ newClass
! !