GDBMAContainer.st
author Jan Vrany <jan.vrany@labware.com>
Fri, 08 Sep 2023 12:40:22 +0100
changeset 317 7f63737e0374
parent 272 cdd1c9ad00de
permissions -rw-r--r--
Fix `GDBMIDebugger` after rename of `GDBStXUnixProcess` to `GDBUnixProcess` ...in commit d1422e1ee.

"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2020 LabWare
Copyright (C) 2022-2023 LabWare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

Magritte::MAContainer subclass:#GDBMAContainer
	instanceVariableNames:'klass'
	classVariableNames:''
	poolDictionaries:''
	category:'GDB-Internal-Support'
!

!GDBMAContainer class methodsFor:'documentation'!

copyright
"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2020 LabWare
Copyright (C) 2022-2023 LabWare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
! !

!GDBMAContainer class methodsFor:'instance creation'!

forClass: aClass
    ^ self new  
        klass:aClass;
        yourself

    "Created: / 23-09-2014 / 22:36:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMAContainer class methodsFor:'testing'!

isAbstract
    ^ false

    "Created: / 23-09-2014 / 22:38:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMAContainer methodsFor:'accessing'!

klass
    ^ klass
!

klass:something
    klass := something.
!

propertyDescriptorAt: name
    ^ children detect:[:each | (each accessor isKindOf: GDBMAPropertyAccessor) and:[ each accessor name = name ] ] ifNone:[ nil ]

    "Created: / 23-09-2014 / 22:50:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-10-2018 / 21:54:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMAContainer methodsFor:'adding-easy shortcuts'!

define: property as: class
    "/ Handle primitive types first...

    | description |

    class == Boolean ifTrue:[ 
        description := Magritte::MABooleanDescription new.
    ] ifFalse:[
    class == Integer ifTrue:[ 
        description := Magritte::MANumberDescription new
    ] ifFalse:[
    class == String ifTrue:[ 
        description := Magritte::MAStringDescription new
    ] ifFalse:[
    class == ByteArray ifTrue:[ 
        description := GDBMAByteArrayDescription new        
    ] ifFalse:[
        description := (self descriptionOf: class). 
    ]]]].
    description accessor: (GDBMAPropertyAccessor forPropertyNamed: property).

    self add: description.
    ^ description

    "Created: / 23-09-2014 / 22:20:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-04-2019 / 16:20:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 15-06-2020 / 12:29:54 / Jan Vrany <jan.vrany@labware.com>"
!

define: property as: collectionClass of: elementClass
    "/ Handle primitive types first...

    | description |

    elementClass == Boolean ifTrue:[ 
        description := Magritte::MAToManyScalarRelationDescription new.
        description reference: Magritte::MABooleanDescription new.      
    ] ifFalse:[
    elementClass == Integer ifTrue:[ 
        description := Magritte::MAToManyScalarRelationDescription new.
        description reference: Magritte::MANumberDescription new.
    ] ifFalse:[
    elementClass == String ifTrue:[
        description := Magritte::MAToManyScalarRelationDescription new.
        description reference: Magritte::MAStringDescription new.
    ] ifFalse:[
    elementClass == ByteArray ifTrue:[
        description := Magritte::MAToManyScalarRelationDescription new.
        description reference: GDBMAByteArrayDescription new.     
    ] ifFalse:[
        description := Magritte::MAToManyRelationDescription new.
        description reference: (self descriptionOf: elementClass).
    ]]]].
    description accessor: (GDBMAPropertyAccessor forPropertyNamed: property).       
    description classes: (Array with: elementClass).
    description ordered: (collectionClass inheritsFrom: SequenceableCollection).

    self add: description.
    ^ description.

    "Created: / 23-09-2014 / 22:54:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-04-2019 / 16:19:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

define: property as: collectionClass of: elementClass1 whenTaggedBy: tag1 or: elementClass2 whenTaggedBy: tag2 
    "/ Handle primitive types first...

    | description |

    description := Magritte::MAToManyRelationDescription new.
    description reference: (
        GDBMADescriptionSwitch 
            forTag: tag1 use: (self descriptionOf: elementClass1) 
            forTag: tag2 use: (self descriptionOf: elementClass2)
    ).
    description classes: (Array with: elementClass1 with: elementClass2).
    description accessor: (GDBMAPropertyAccessor forPropertyNamed: property).       
    description ordered: (collectionClass inheritsFrom: SequenceableCollection).

    self add: description.
    ^ description.

    "Created: / 03-07-2018 / 17:10:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-04-2019 / 16:20:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMAContainer methodsFor:'parsing-GDB/MI'!

parseUsingGDBMIParser:aGDBMIParser
    ^ aGDBMIParser parseValueAsInstanceOf: klass describedBy: self.

    "Created: / 23-09-2014 / 22:32:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMAContainer methodsFor:'private'!

descriptionOf: aClass
    "
    Return Magritte descrioption of a given class.

    Essentially this is the same as `aClass description` except it 
    handles the case when `aClass` is the same a `klass`. In that case,
    return self.

    This is needed to support recursive structures (sich a GDBBreakpoint, where
    each location is another breakpoint).

    CAVEAT: this does not support mutually recursive structures like that
    type A object holds on type B object which holds on another type A object.
    To fix this, we'd need to fix Magritte itsef.
    "
    ^ klass == aClass ifTrue:[ self ] ifFalse:[ aClass description ]

    "Created: / 25-04-2019 / 16:19:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 30-04-2019 / 16:37:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMAContainer class methodsFor:'documentation'!

version_HG

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