compiler/PPCRewritingVisitor.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 26 Aug 2015 23:01:00 +0100
changeset 532 132d7898a2a1
parent 452 9f4558b3be66
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:#PPCRewritingVisitor
	instanceVariableNames:'change'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Visitors'
!

!PPCRewritingVisitor methodsFor:'as yet unclassified'!

change
    self flag: 'JK: Do we need this?'.
    change := true.
!

visitChild: child of: node
    | newChild |

    (self isOpen: child) ifTrue: [ 
        "already processing..."
        ^ nil
    ].

    (self isCached: child) ifTrue: [ 
        "Use Cached Value"
        node replace: child with: (self cachedValue: child).
        ^ nil
    ]. 


    change := false.
    newChild := self visit: child.
    change ifTrue: [ 
        node replace: child with: newChild.
    ].
!

visitChildren: node
    node children do: [ :child | 
        self visitChild: child of: node
    ]
! !