compiler/PPCInliningVisitor.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 26 Aug 2015 23:01:00 +0100
changeset 532 132d7898a2a1
parent 525 751532c8f3db
child 534 a949c4fe44df
permissions -rw-r--r--
PPCConfiguration refactoring: [4/10]: introduced a class - PPCPass ... representing a compilation pass over the PPCNode tree. The pass has a common api method: #run:in: which is not used in PPCConfiguration. This simplifed the code and removed some code duplication.

"{ Package: 'stx:goodies/petitparser/compiler' }"

"{ NameSpace: Smalltalk }"

PPCPass subclass:#PPCInliningVisitor
	instanceVariableNames:'canInline acceptedNodes'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Visitors'
!


!PPCInliningVisitor methodsFor:'initialization'!

initialize
    super 	initialize.
        
    acceptedNodes := 0
! !

!PPCInliningVisitor methodsFor:'testing'!

canInline
    ^ acceptedNodes > 1
! !

!PPCInliningVisitor methodsFor:'visiting'!

beforeAccept: node
    acceptedNodes := acceptedNodes + 1.
    super beforeAccept: node
!

markForInline: node
    self canInline ifTrue: [ 
        node markForInline.
    ].
    ^ node
!

visitActionNode: node
    "Only mark unnamed sequence nodes for inlining.
     Named nodes should not be inlined as they should make a method.
     There's little point in inlining non-sequence nodes, so don't
     enforce inlining on those. Some (JK :-) may prefer them non-inlined
     (for debugging purposes)"
    (node child isSequenceNode and:[node child name isNil]) ifTrue: [ node child markForInline ].
    ^ super visitActionNode: node.

    "Created: / 13-05-2015 / 16:25:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 31-07-2015 / 08:20:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

visitCharSetPredicateNode: node
    ^ self markForInline: node
!

visitCharacterNode: node
    ^ self markForInline: node
!

visitLiteralNode: node
    ^ self markForInline: node
!

visitMessagePredicateNode: node
    ^ self markForInline: node
!

visitNilNode: node
    ^ self markForInline: node
!

visitNotCharSetPredicateNode: node
    ^ self markForInline: node
!

visitNotLiteralNode: node
    ^ self markForInline: node
!

visitNotMessagePredicateNode: node
    ^ self markForInline: node
!

visitPluggableNode: node
    "Sadly, on Smalltalk/X blocks cannot be inlined because
     the VM does not provide enough information to map
     it back to source code. Very bad indeed!!"
    ((Smalltalk respondsTo:#isSmalltalkX) and:[ Smalltalk isSmalltalkX ]) ifFalse:[
			self markForInline: node
    ].
    ^ super visitPluggableNode: node.

    "Modified: / 23-04-2015 / 12:15:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

visitStarCharSetPredicateNode: node
    ^ self markForInline: node
!

visitStarMessagePredicateNode: node
    ^ self markForInline: node
!

visitTokenConsumeNode: node
    "super visitTokenConsumeNode: node."

    node name isNil ifTrue: [ 
        self markForInline: node
    ].

    ^ node
!

visitTokenStarMessagePredicateNode: node
    ^ self markForInline: node
!

visitTokenStarSeparatorNode: node
    ^ self markForInline: node
!

visitTokenWhitespaceNode: node
    super visitTokenWhitespaceNode: node.
    self markForInline: node.
    ^ node
!

visitTokenizingParserNode: node
    "skip tokens"
    "skip whitespace"
    "self visit: node whitespace."

    self visit: node parser.
    
    ^ node
! !

!PPCInliningVisitor class methodsFor:'documentation'!

version_HG

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