ByteCodeCompilerWithBreakpointSupport.st
author Claus Gittinger <cg@exept.de>
Thu, 24 Nov 2011 18:58:37 +0100
changeset 2758 6e774a75b71d
parent 2537 72fde5f496de
child 2799 37dfd9b9d9ee
permissions -rw-r--r--
changed: #possiblyWrapABreakPointAround:

"
 COPYRIGHT (c) 2006 by eXept Software AG
	      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:libcomp' }"

ByteCodeCompiler subclass:#ByteCodeCompilerWithBreakpointSupport
	instanceVariableNames:'breakpoints'
	classVariableNames:''
	poolDictionaries:''
	category:'System-Compiler-Debugging'
!

!ByteCodeCompilerWithBreakpointSupport class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2006 by eXept Software AG
	      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
"
    I'm an experimental compiler class that supports
    breakpoints. Once tested, the code will be merged
    to ByteCodeCompiler.

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

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!ByteCodeCompilerWithBreakpointSupport methodsFor:'adding breakpoint'!

possiblyWrapABreakPointAround:aBlock
    "refactored Jan's original code; changed to not wrap an already wrapped expression"

    | expr bpnt pos |

    pos := tokenPosition ? source position.

    [
        breakpoints notEmpty
        and:[breakpoints first position < pos]
    ] whileTrue:[
        bpnt := breakpoints removeFirst
    ].

    expr := aBlock value.

    bpnt isNil ifTrue:[^expr].
    expr isBreakPointNode ifTrue:[^expr].
    bpnt isReached:true.
    Transcript show:'adding breakpoint '; show:bpnt; show:' before: '; showCR:expr.
    ^ BreakpointNode new
        breakpoint: bpnt;
        expression: expr;
        lineNumber:(bpnt line ? tokenLineNr);
        yourself

    "Created: / 05-07-2011 / 21:11:19 / cg"
!

removeMissedBreakpointsBefore:aPosition
    [
        breakpoints notEmpty
        and:[breakpoints first position < aPosition]
    ] whileTrue:[
        breakpoints removeFirst
    ].

    "Created: / 05-07-2011 / 23:13:25 / cg"
! !

!ByteCodeCompilerWithBreakpointSupport methodsFor:'parsing-expressions'!

binaryExpression
    ^ self possiblyWrapABreakPointAround:[super binaryExpression]

    "Created: / 05-07-2011 / 23:08:43 / cg"
!

binaryExpressionFor:aReceiver
    ^ self possiblyWrapABreakPointAround:[super binaryExpressionFor:aReceiver]

    "Created: / 05-07-2011 / 21:10:53 / cg"
!

block
    |blockNode|

    self removeMissedBreakpointsBefore:source position.
    blockNode := super block.
    self removeMissedBreakpointsBefore:blockNode endPosition+2.
    ^ blockNode

    "Created: / 05-07-2011 / 22:56:19 / cg"
!

expression
    ^ self possiblyWrapABreakPointAround:[super expression]

    "Created: / 16-06-2011 / 14:58:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-07-2011 / 21:11:38 / cg"
!

primary
    ^ self possiblyWrapABreakPointAround:[super primary]

    "Created: / 16-06-2011 / 14:58:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-07-2011 / 21:11:38 / cg"
    "Created: / 05-07-2011 / 23:05:23 / cg"
!

unaryExpression
    ^ self possiblyWrapABreakPointAround:[super unaryExpression]

    "Created: / 05-07-2011 / 23:08:54 / cg"
!

unaryExpressionFor:aReceiver
    ^ self possiblyWrapABreakPointAround:[super unaryExpressionFor:aReceiver]

    "Created: / 05-07-2011 / 21:15:30 / cg"
! !

!ByteCodeCompilerWithBreakpointSupport methodsFor:'private'!

breakpoints:aCollection
    breakpoints := aCollection copy sort:[:a :b|a position < b position].

    "Created: / 16-06-2011 / 14:35:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Created: / 05-07-2011 / 21:37:28 / cg"
!

notifying: anObject
    super notifying: anObject.
    anObject notNil ifTrue:[
        breakpoints isNil ifTrue:[
            self breakpoints:(anObject perform: #breakpoints ifNotUnderstood:#()).
        ]
    ]

    "Created: / 16-06-2011 / 14:35:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-07-2011 / 21:48:37 / cg"
! !

!ByteCodeCompilerWithBreakpointSupport class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libcomp/ByteCodeCompilerWithBreakpointSupport.st,v 1.3 2011-11-24 17:58:37 cg Exp $'
!

version_SVN
    ^ '§ Id §'
! !