compiler/TCompilationUnitDefinition.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 25 Sep 2015 03:51:15 +0100
changeset 16 17a2d1d9f205
parent 8 eec72263ed75
permissions -rw-r--r--
Added standalone Tea compiler - teak It allows for compilation of .tea files from the command line.

"
    Copyright (C) 2015-now Jan Vrany

    This code is not an open-source (yet). You may use this code
    for your own experiments and projects, given that:

    * all modification to the code will be sent to the
      original author for inclusion in future releases
    * this is not used in any commercial software

    This license is provisional and may (will) change in
    a future.
"
"{ Package: 'jv:tea/compiler' }"

"{ NameSpace: Smalltalk }"

RGAbstractContainer subclass:#TCompilationUnitDefinition
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Tea-Compiler-Model'
!

!TCompilationUnitDefinition class methodsFor:'documentation'!

copyright
"
    Copyright (C) 2015-now Jan Vrany

    This code is not an open-source (yet). You may use this code
    for your own experiments and projects, given that:

    * all modification to the code will be sent to the
      original author for inclusion in future releases
    * this is not used in any commercial software

    This license is provisional and may (will) change in
    a future.
"
! !

!TCompilationUnitDefinition methodsFor:'accessing'!

classes
    "Return a list of classes defined in this compilation unit"

    ^ elements at: #classes ifAbsentPut:[ OrderedCollection new ]

    "Created: / 13-09-2015 / 08:01:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name
    ^ name ? '<in memory>'

    "Created: / 14-09-2015 / 10:56:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TCompilationUnitDefinition methodsFor:'adding & removing'!

addClass: class 
    self addElement: class in: self classes

    "Created: / 13-09-2015 / 08:00:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

addMethod: method
    | className classIsMeta class |

    classIsMeta := false.
    className := method className.
    (className endsWith: ' class') ifTrue:[
        className := className copyTo: (className size - "' class' size"6).
        classIsMeta := true.
    ].
    class := self classes detect:[:class | class name = className ] ifNone:[ nil ].
    class isNil ifTrue:[ 
        self error: 'No class %1 found in compilation unit'
    ].
    classIsMeta ifTrue:[ 
        class := class theMetaclass.
    ].
    class addMethod: method.

    "Created: / 13-09-2015 / 08:02:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TCompilationUnitDefinition methodsFor:'testing types'!

isCompilationUnit

    ^true

    "Created: / 14-09-2015 / 10:29:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TCompilationUnitDefinition methodsFor:'visiting'!

acceptVisitor: visitor
    ^ visitor acceptCompilationUnitDefinition: self

    "Created: / 14-09-2015 / 10:32:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!TCompilationUnitDefinition class methodsFor:'documentation'!

version_HG

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