UndefinedObject.st
author Claus Gittinger <cg@exept.de>
Wed, 28 Feb 1996 15:50:02 +0100
changeset 1030 a21295a6725d
parent 1029 c469a63e88e2
child 1294 e26bbb61f6b2
permissions -rw-r--r--
oops - the last one did not do it

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

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:'copying'!

copy
    "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
!

deepCopyUsing:aDictionary
    "return a deep 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
!

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

    ^ self
! !

!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:'printing & storing'!

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

    aStream nextPutAll:'nil'
!

printString
    "return a string for printing myself"

    ^ 'nil'
!

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

    ^ self printOn:aStream
!

storeString
    "return a string for storing myself"

    ^ 'nil'
! !

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

        newClass selectorArray size == 0 ifTrue:[
        "
         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

    "Modified: 28.2.1996 / 15:47:41 / cg"
!

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)
!

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)
!

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)
! !

!UndefinedObject methodsFor:'testing'!

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
!

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
! !

!UndefinedObject class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/UndefinedObject.st,v 1.21 1996-02-28 14:50:02 cg Exp $'
! !