BeeProjectSourceWriter.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 05 Nov 2018 20:52:42 +0000
branchjv
changeset 4381 5f0582aa5462
parent 4377 cbf86fdee06c
child 4573 ba0441fba5fe
permissions -rw-r--r--
Various fixes for Bee source / package writer

"
 COPYRIGHT (c) 2015-2016 Jan Vrany
              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.
"
"{ Package: 'stx:libbasic3' }"

"{ NameSpace: Smalltalk }"

BeeProjectWriter subclass:#BeeProjectSourceWriter
	instanceVariableNames:'porter classesToInitialize'
	classVariableNames:''
	poolDictionaries:''
	category:'Kernel-Classes-Support'
!

!BeeProjectSourceWriter class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2015-2016 Jan Vrany
              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 writer to write Smalltalk/X package in Bee Smalltalk format (.stp). Usage:

    BeeProjectSourceWriter fileOut: 'jv:calipel/s' to: '/tmp/jv-calipel-s.stp'

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!BeeProjectSourceWriter methodsFor:'initialization'!

initialize
    "Invoked when a new instance is created."

    super initialize.
    porter := BeeSourcePorter new.

    "Created: / 26-10-2018 / 11:44:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BeeProjectSourceWriter methodsFor:'source writing'!

fileOutClasses: classes on: stream

    stream nextPutAll: '"**** Class definitions ****"!!'; cr.

    classes topologicalSort:[:a :b | b isSubclassOf:a].

    classes do:[:cls | 
        cls isPrivate ifTrue:[
            self error:'Cannot file out private class: ',cls name.
        ].
    ].  

    classesToInitialize := classes select:[ :each | each class methodDictionary includesKey:#initialize ].

    [
        classes do:[:class |
            self activityNotification:'exporting ', class name,'...'.
            writer fileOut:class on:stream withTimeStamp:false withInitialize:false withDefinition:true methodFilter:[:m | false]
        ].
        classes do:[:class |
            self activityNotification:'exporting ', class name,'...'.
            writer fileOut:class on:stream withTimeStamp:false withInitialize:false withDefinition:false methodFilter:[:m | 
                | who |

                who := m who.
                (who methodClass isMetaclass and:[ who methodSelector == #copyright ]) not
                    and:[ (AbstractSourceCodeManager isVersionMethodSelector: who methodSelector) not ]
            ]
        ].
    ] on: AbstractSourceFileWriter methodSourceRewriteQuery do:[:request |
        | method source |

        method := request method.
        source := request source.
        source := porter portMethod: method source: source.
        request proceedWith: source.         
    ] on: AbstractSourceFileWriter classSourceRewriteQuery do:[:request |
        | klass source |

        klass := request klass.
        source := request source.
        source := porter portClass: klass source: source.
        request proceedWith: source.         
    ].

    "Created: / 14-04-2015 / 13:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 30-10-2018 / 15:49:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

fileOutExtensions: methods on:stream

    self activityNotification:'exporting extensions...'.
    AbstractSourceFileWriter methodSourceRewriteQuery handle:[:request |
        | method source |

        method := request method.
        source := request source.
        source := porter portMethod: method source: source.
        request proceedWith: source.         
    ] do:[
        methods do:[:eachMethod |
            writer fileOutMethods:methods on:stream.
            stream cr.
        ]
    ]

    "Modified: / 30-10-2018 / 15:49:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

fileOutFooterOn:aStresm
    classesToInitialize notEmptyOrNil ifTrue:[ 
        | classMap |

        classMap := Dictionary new.
        porter collectClassRewritesFrom: (classesToInitialize collect:[:e|e name]) into: classMap. 
        aStresm nextPutAll: '"**** Initializing ****"!!'; cr.
        classesToInitialize do:[:each | 
            | name |

            name := classMap at: each name ifAbsent:[ each name ].
            aStresm nextPutAll: name; nextPutAll: ' initialize!!'; cr.
        ].
    ].

    "Created: / 30-10-2018 / 15:36:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

fileOutHeaderOn: aStream

    aStream nextPutAll:(
'"
        __________________________________________________
        Author: %(AUTHOR).
        Project name: %(NAME)
        Version: %(VERSION)
        Timestamp: %(TIMESTAMP)
        Description: %(DESCRIPTION)
        __________________________________________________
"

' bindWithArguments: self mappings)

    "Created: / 14-04-2015 / 13:42:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-11-2015 / 19:00:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

fileOutPools: pools on: stream   
    pools do:[:pool | 
        self activityNotification:'exporting ', pool name,'...'.
        writer fileOutPool:pool on:stream.          
    ].

    "Created: / 29-10-2018 / 15:42:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!BeeProjectSourceWriter methodsFor:'utilities'!

ensureNoUnicodeInClass:aClass
    "/ check if we need UTF8 encoding
    aClass withAllPrivateClasses do:[:cls |
         cls instAndClassMethods contains:[:m |
            self ensureNoUnicodeInMethod:m
         ]
    ].
!

ensureNoUnicodeInMethod:aMethod
    |src|

    src := aMethod source.
    src isNil ifTrue:[
        self error:'missing source in ',aMethod whoString
    ].
    src asSingleByteStringIfPossible isWideString ifTrue:[
        self error:(aMethod whoString , ' contains unicode strings or character contants. Cannot be exported to VSE')
    ].
! !

!BeeProjectSourceWriter class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !