UndefinedObject.st
author Claus Gittinger <cg@exept.de>
Wed, 28 Aug 1996 15:19:12 +0200
changeset 1638 8df0060e4d73
parent 1461 dd25bb1e9973
child 1803 754f9205b651
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.
"

'From Smalltalk/X, Version:2.10.9 on 12-jun-1996 at 11:56:25'                   !

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 (NULL),
    there can be only one instance of UndefinedObject, and no subclassing is
    possible. 
    (to be exact: subclassing UndefinedObject is technically possible, 
     but instances of it would not be recognized as being nil 
     - therefore, subclassing is blocked and an error is raised when it is tried)

    For advanced users:
      Beside the above role, nil can be subclassed (!!).
      This creates a class which inherits no protocol whatsoever - not even
      the basic interfaces as defined by the Object class. Subclasses of nil
      are useful if all messages send to instances should trap into the
      #doesNotUnderstand: method. For example, proxy objects are typically defined
      this way.

    [author:]
        Claus Gittinger
"
! !

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

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

        newClass methodDictionary size == 0 ifTrue:[
            "
             copy over method objects from Object
             and modify the source code
            "
            methodDict := MethodDictionary new:3.
            #(#class #isBehavior #doesNotUnderstand:) do:[:sel|
                method := (Object compiledMethodAt:sel) copy.
                method source: method 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. 
"
'.
                methodDict at:sel put:method.
            ].
            newClass methodDictionary:methodDict.
            Class addChangeRecordForClass:newClass.
        ]
    ].
    ^ newClass

    "Modified: 28.2.1996 / 15:47:41 / cg"
    "Modified: 12.6.1996 / 10:46:15 / stefan"
!

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.25 1996-08-28 13:19:12 cg Exp $'
! !