ClassCategoryReader.st
author Claus Gittinger <cg@exept.de>
Thu, 18 Jan 1996 15:01:29 +0100
changeset 882 cb91ec165c55
parent 868 fc7ab02e0537
child 955 6b5487deebfa
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1989 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:#ClassCategoryReader
	instanceVariableNames:'myClass myCategory privacy ignore primSpec'
	classVariableNames:'KeepSource'
	poolDictionaries:''
	category:'Kernel-Support'
!

!ClassCategoryReader class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1989 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
"
    a helper class for fileIn - keeps track of class and category to filein for.
    Instances of this are created by the #methodsFor: methods in Class, to
    read the next chunk(s) from a stream.
"
! !

!ClassCategoryReader class methodsFor:'initialization'!

initialize
    KeepSource := true
! !

!ClassCategoryReader class methodsFor:'instance creation'!

class:aClass category:aCategory
    "return a new ClassCategoryReader to read methods for aClass with
     methodCategory aCategory"

    ^ self new class:aClass category:aCategory
!

class:aClass primitiveSpec:which
    "return a ClassCategoryReader to read a primitiveSpec chunk"

    ^ self new class:aClass primitiveSpec:which
!

skippingChunks
    "return a class categoryReader which skips chunks up to the next empty one"

    ^ self new ignoreMethods
! !

!ClassCategoryReader class methodsFor:'defaults'!

keepSource
    ^ KeepSource

    "Created: 9.9.1995 / 15:22:27 / claus"
!

keepSource:aBoolean
    KeepSource := aBoolean

    "Created: 9.9.1995 / 15:22:26 / claus"
! !

!ClassCategoryReader methodsFor:'fileIn'!

fileInFrom:aStream
    "read method-chunks from the input stream, aStream; compile them
     and add the methods to the class defined by the class-instance var"

    self fileInFrom:aStream notifying:nil passChunk:false
!

fileInFrom:aStream notifying:requestor passChunk:passChunk
    "read method-chunks from the input stream, aStream; compile them
     and add the methods to the class defined by the class-instance var;
     errors and notifications are passed to requestor"

    |aString done method compiler makeSourceRef sourceFile pos nm|

    ignore ifFalse:[
	Smalltalk silentLoading ifFalse:[
	    myClass isNil ifTrue:[
		nm := '** UndefinedClass **'
	    ] ifFalse:[
		nm := myClass name
	    ].
	    Transcript show:'  '; show:nm; show:' -> '; showCr:myCategory.
	].

	makeSourceRef := false.

	"/
	"/ KeepSource controls if
	"/ the sourceString should be kept or
	"/ a reference to the fileStream should be placed into the
	"/ method intead.
	"/
	KeepSource == false ifTrue:[
	    aStream isFileStream ifTrue:[
		sourceFile := aStream pathName.
		"/
		"/ only do it, if the sourceFiles name
		"/ ends with '.st'
		"/ this prevents methods to reference the changes file.
		"/
		(sourceFile endsWith:'.st') ifTrue:[
		    makeSourceRef := true.
		]
	    ]
	].
    ].

    done := false.
    [done] whileFalse:[
	done := aStream atEnd.
	done ifFalse:[
	    makeSourceRef ifTrue:[
		pos := aStream position
	    ].
	    aString := aStream nextChunk.
	    done := aString isNil or:[aString isEmpty].
	    done ifFalse:[
		primSpec notNil ifTrue:[
		    myClass perform:primSpec with:aString.
		    "
		     ignore rest
		    "
		    ignore := true
		].
		ignore ifFalse:[
		    passChunk ifTrue:[
			requestor source:aString
		    ].

		    compiler := myClass compilerClass.

		    "/
		    "/ kludge - for now;
		    "/ have to make ST/X's compiler protocol be compatible to ST-80's
		    "/ for other compilers to work ... (TGEN for example)
		    "/
		    (compiler respondsTo:#compile:forClass:inCategory:notifying:install:skipIfSame:)
		    ifTrue:[
			"/ ST/X's compiler
			method :=compiler
				     compile:aString
				     forClass:myClass
				     inCategory:myCategory
				     notifying:requestor
				     install:true
				     skipIfSame:true.

			(method notNil and:[method ~~ #Error]) ifTrue:[
			    makeSourceRef ifTrue:[
				method getSource = aString ifTrue:[
				    method sourceFilename:sourceFile position:pos 
				]
			    ]
			]
		    ] ifFalse:[
			"/ some generated (TGEN) compiler
			method := compiler new
				      compile:aString 
				      in:myClass 
				      notifying:requestor 
				      ifFail:nil
		    ].

		    privacy notNil ifTrue:[
			privacy == #private ifTrue:[
			    method setToPrivate
			] ifFalse:[
			    privacy == #protected ifTrue:[
				method setToProtected
			    ]
			]
		    ]
		]
	    ]
	]
    ]

    "Modified: 9.9.1995 / 15:29:08 / claus"
    "Modified: 17.12.1995 / 16:01:47 / cg"
! !

!ClassCategoryReader methodsFor:'private'!

class:aClass category:aCategory
    "set the instance variables"

    myClass := aClass.
    myCategory := aCategory.
    ignore := false
!

class:aClass primitiveSpec:which
    "set the instance variables"

    myClass := aClass.
    primSpec := which.
    ignore := false
! !

!ClassCategoryReader methodsFor:'special'!

ignoreMethods 
    ignore := true
!

privateProtocol
    privacy := #private
!

protectedProtocol
    privacy := #protected
! !

!ClassCategoryReader class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/ClassCategoryReader.st,v 1.26 1996-01-18 14:01:29 cg Exp $'
! !
ClassCategoryReader initialize!