VDBInstructionsAndSourcePresenter.st
author Jan Vrany <jan.vrany@labware.com>
Mon, 30 May 2022 14:18:03 +0100
changeset 264 23960fcb9dac
parent 120 4fae7ad78949
permissions -rw-r--r--
Relicense under MIT license.

"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022 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:vdb' }"

"{ NameSpace: Smalltalk }"

VDBAbstractPresenter subclass:#VDBInstructionsAndSourcePresenter
	instanceVariableNames:'instructionsAndSource'
	classVariableNames:''
	poolDictionaries:''
	category:'VDB-Presentation'
!

!VDBInstructionsAndSourcePresenter class methodsFor:'documentation'!

copyright
"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022 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.
"
! !

!VDBInstructionsAndSourcePresenter methodsFor:'accessing'!

address
    instructionsAndSource instructions notEmpty ifTrue:[ 
        ^ instructionsAndSource address.
    ] ifFalse:[ 
        | siblings index |

        siblings := parent children.
        index := siblings identityIndexOf: self.
        index < siblings size ifTrue:[ 
            ^ (siblings at: index + 1) address.
        ].
    ].
    ^ nil.

    "Created: / 26-06-2018 / 12:37:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-08-2018 / 11:55:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

basicBlock
    children isEmptyOrNil ifTrue:[ ^ nil ].
    ^ self children first basicBlock

    "Created: / 26-06-2018 / 12:37:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-08-2018 / 11:43:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

lineDigitsToDisplay
    "Return a number of line digits to display."

    "/ Currently hardcoded but maybe it will be dynamic
    "/ in future...
    ^ 5

    "Created: / 09-08-2018 / 11:10:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

subject
    "Return an instance of GDB object that this presenter displays."

    ^ instructionsAndSource

    "Created: / 22-06-2018 / 15:10:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

tooltip
    | source line tooltip |

    source := instructionsAndSource source.
    source isNil ifTrue:[ ^ instructionsAndSource file, ':  ', instructionsAndSource line printString ].
    line := instructionsAndSource line asInteger.
    tooltip := TextStream on: ''.
    tooltip emphasis: #bold;
      nextPutAll: instructionsAndSource file;
      emphasis: nil.
    tooltip cr; cr.
    ((line - 5) max: 1) to: ((line + 10) min: source size) do:[:i | 
        i == line ifTrue:[ tooltip emphasis: #bold ].
        i == line ifTrue:[ tooltip nextPut: $> ] ifFalse:[ tooltip space. ].
        tooltip space.                                                      
        i printOn: tooltip base: 10 size: self lineDigitsToDisplay fill: Character space.
        tooltip space.
        tooltip nextPutLine: (source at: i).
        i == line ifTrue:[ tooltip emphasis: nil ].
    ].
    ^ tooltip contents.

    "Created: / 09-08-2018 / 10:45:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBInstructionsAndSourcePresenter methodsFor:'initialization'!

setInstructionsAndSource: aGDBInstructionsAndSourceLine
    instructionsAndSource := aGDBInstructionsAndSourceLine

    "Created: / 22-06-2018 / 12:40:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBInstructionsAndSourcePresenter methodsFor:'protocol-accessing'!

fetchChildren
    ^ instructionsAndSource instructions collect:[ :i | VDBInstructionPresenter new setInstruction: i; parent: self ]

    "Created: / 22-06-2018 / 12:19:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

label
    | source line |
    source := instructionsAndSource source.
    line := instructionsAndSource line.
    (source notNil and:[ line notNil and: [ instructionsAndSource line asInteger between: 1 and: source size]]) ifTrue:[ 
        ^ (line printStringRadix: 10 size: self lineDigitsToDisplay fill: Character space) , Character space , (source at: line asInteger) 
    ] ifFalse:[
        | file |

        "/ Use `propertyAt: #file` rather than #file since
        "/ the latter tries to resolve the file and returns
        "/ nil if the file cannot be resolved. 
        "/ 
        "/ However, here we need the file name, no matter whether
        "/ we can access it or not. 
        file := instructionsAndSource propertyAt: #file.
        ^ (file ? '??') , ':  ', instructionsAndSource line printString
    ]

    "Created: / 22-06-2018 / 12:22:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 07-10-2018 / 08:51:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBInstructionsAndSourcePresenter methodsFor:'testing'!

isInstructionsAndSourcePresenter
    ^ true
! !

!VDBInstructionsAndSourcePresenter class methodsFor:'documentation'!

version_HG

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