UndefObj.st
author Claus Gittinger <cg@exept.de>
Wed, 01 Nov 1995 15:44:26 +0100
changeset 468 72dfba4603b4
parent 384 cc3d110ea879
child 530 07d0bce293c9
permissions -rw-r--r--
Initial revision

"
 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/Attic/UndefObj.st,v 1.17 1995-08-11 03:04:39 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/Attic/UndefObj.st,v 1.17 1995-08-11 03:04:39 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:'subclass creation'!

nilSubclass:selector args:args
    "common helper for subclass creation.
     Creates a nil-superclass class with entries for the minimum
     required protocol (#class, #isBehavior and #doesNotUnderstand:).
     These are required to avoid getting into deep trouble when
     inspecting or debugging instances of this new class.

     The methods get a modified source code to remind you that these
     methods were automatically generated."

    |newClass mA|

    Class withoutUpdatingChangesDo:
    [
	newClass := Object perform:selector withArguments:args
    ].
    newClass notNil ifTrue:[
	newClass setSuperclass:nil.

	"
	 copy over method objects from Object
	"
	newClass 
	    setSelectors:(Array 
			    with:#class
			    with:#isBehavior 
			    with:#doesNotUnderstand:)
	    methods:(mA := Array 
			    with:(Object compiledMethodAt:#class) copy
			    with:(Object compiledMethodAt:#isBehavior) copy
			    with:(Object compiledMethodAt:#doesNotUnderstand:) copy).

	"
	 and modify the source code
	"
	mA do:[:m |
	    m source:m source , '
"
*** WARNING
***
*** this method has been automatically created,
*** since all nil-subclasses should respond to some minimum required
*** protocol.
***
*** Inspection and/or debugging of instances may not be possible,
*** if you remove/change this method. 
"
'.
	].
	Class addChangeRecordForClass:newClass.
    ].
    ^ newClass
!

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."

    ^ self nilSubclass:(thisContext selector) args:(thisContext args)
! 

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."

    ^ self nilSubclass:(thisContext selector) args:(thisContext args)
! 

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."

    ^ self nilSubclass:(thisContext selector) args:(thisContext args)
! !