ByteCodeCompilerWithBreakpointSupport.st
author Claus Gittinger <cg@exept.de>
Tue, 05 Jul 2011 23:24:58 +0200
changeset 2537 72fde5f496de
parent 2498 43bfd25f2552
child 2758 6e774a75b71d
permissions -rw-r--r--
fixes to make testSuite pass

"
 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 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.2 2011-07-05 21:24:58 cg Exp $'
!

version_SVN
    ^ '§ Id §'
! !