JavaConstantPool.st
author cg
Mon, 05 Jan 1998 18:49:32 +0000
changeset 252 04b330744577
parent 243 d580e27e1b66
child 264 44aedfcd08d1
permissions -rw-r--r--
new javaVM stuff & back to pre-stefans changes

'From Smalltalk/X, Version:3.3.1 on 4-jan-1998 at 4:22:53 pm'                   !

Array subclass:#JavaConstantPool
	instanceVariableNames:'owner'
	classVariableNames:''
	poolDictionaries:''
	category:'Java-Reader-Support'
!


!JavaConstantPool class methodsFor:'special'!

compressPools
    "unify all constants"

    |strings nameandTypes jStrings|

    strings := Set new.
    nameandTypes := Set new.

    self allInstancesDo:[:aPool |
        aPool keysAndValuesDo:[:idx :aConst |
            |existing nt|

            aConst isString ifTrue:[
                existing := strings elementAt:aConst ifAbsent:nil.
                existing isNil ifTrue:[
                    strings add:aConst
                ] ifFalse:[
                    aPool at:idx put:existing
                ]
            ] ifFalse:[
                (aConst isMemberOf:JavaFieldref) ifTrue:[
                    nt := aConst nameandType.
                    existing := nameandTypes elementAt:nt ifAbsent:nil.
                    existing isNil ifTrue:[
                        nameandTypes add:nt
                    ] ifFalse:[
                        aConst nameandType:existing
                    ]
                ] ifFalse:[
                    (aConst isMemberOf:JavaNameandType) ifTrue:[
                        existing := nameandTypes elementAt:aConst ifAbsent:nil.
                        existing isNil ifTrue:[
                            nameandTypes add:aConst
                        ] ifFalse:[
                            aPool at:idx put:existing
                        ]
                    ]
                ]
            ]
        ].
    ]

    "
     self compressPools
    "

    "Modified: 19.8.1997 / 14:04:25 / cg"
! !

!JavaConstantPool methodsFor:'accessing'!

owner
    "return owner"

    ^ owner

    "Created: 28.6.1996 / 21:12:22 / cg"
!

owner:something
    "set owner"

    owner := something.

    "Created: 28.6.1996 / 21:12:22 / cg"
! !

!JavaConstantPool methodsFor:'printing & storing'!

displayString
    owner isNil ifTrue:[
        ^ '*** unowned ConstantPool'
    ].
    ^ 'ConstantPool of ' , owner fullName

    "Created: 28.6.1996 / 21:13:41 / cg"
    "Modified: 28.6.1996 / 21:20:26 / cg"
! !

!JavaConstantPool methodsFor:'queries'!

referesToMethodNamed:aJavaMethodName
    self do:[:constItem |
        (constItem isMemberOf:JavaMethod) ifTrue:[
            constItem name = aJavaMethodName ifTrue:[^ true].
        ] ifFalse:[
            (constItem isMemberOf:JavaMethodref) ifTrue:[
self halt.
                constItem name = aJavaMethodName ifTrue:[^ true].
            ].
            (constItem isMemberOf:JavaUnresolvedMethodrefConstant) ifTrue:[
                self halt.
            ]
        ]
    ].
    ^ false

    "Modified: 29.7.1997 / 17:38:35 / cg"
    "Created: 29.7.1997 / 17:39:41 / cg"
!

refersToMethod:aJavaMethod
    self do:[:constItem |
        (constItem == aJavaMethod) ifTrue:[^ true].
        (constItem isMemberOf:JavaMethodref) ifTrue:[
            self halt.
        ].
        (constItem isMemberOf:JavaUnresolvedMethodrefConstant) ifTrue:[
            self halt.
        ]
    ].
    ^ false

    "Modified: 29.7.1997 / 17:36:49 / cg"
    "Created: 29.7.1997 / 17:39:19 / cg"
!

refersToMethodNamed:aJavaMethodName
    self do:[:constItem |
        (constItem isMemberOf:JavaMethod) ifTrue:[
            constItem name = aJavaMethodName ifTrue:[^ true].
        ] ifFalse:[
            (constItem isMemberOf:JavaMethodref) ifTrue:[
                constItem name = aJavaMethodName ifTrue:[^ true].
            ].
            (constItem isMemberOf:JavaUnresolvedMethodrefConstant) ifTrue:[
                self halt.
            ]
        ]
    ].
    ^ false

    "Modified: 29.7.1997 / 17:38:35 / cg"
    "Created: 29.7.1997 / 17:39:24 / cg"
! !

!JavaConstantPool methodsFor:'special'!

classReferencesDo:aBlock
    self do:[:constItem |
        constItem isJavaClass ifTrue:[
            aBlock value:constItem
        ] 
    ]

    "Modified: / 7.8.1997 / 19:17:38 / cg"
    "Created: / 4.1.1998 / 00:40:11 / cg"
!

updateClassRefsFrom:oldClass to:newClass
owner == oldClass ifTrue:[
    self halt.
    ^ self
].

    self keysAndValuesDo:[:index :constItem |
        constItem == oldClass ifTrue:[
            self at:index put:newClass
        ] ifFalse:[
            (constItem isNil
            or:[constItem isNumber]) ifFalse:[
                constItem isString ifTrue:[
                    "/ nothing done ...
                ] ifFalse:[
                    (constItem isMemberOf:(Java java_lang_String)) ifTrue:[
                        "/ nothing done ...
                    ] ifFalse:[
                        constItem isBehavior ifFalse:[
                            constItem updateClassRefsFrom:oldClass to:newClass
                        ] ifTrue:[
                            constItem isJavaClass ifTrue:[
                                constItem fullName = oldClass fullName ifTrue:[
                                    'JAVA: class update by name [in pool].' infoPrintCR.
                                    self at:index put:newClass
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]

    "Modified: 7.8.1997 / 19:17:38 / cg"
! !

!JavaConstantPool class methodsFor:'documentation'!

version
    ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaConstantPool.st,v 1.7 1998/01/05 18:47:11 cg Exp $'
! !