compiler/PPCMergingVisitor.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 07 Sep 2015 11:53:38 +0100
changeset 538 16e8536f5cfb
parent 452 9f4558b3be66
permissions -rw-r--r--
PPCConfiguration refactoring: [10/10]: Cleaned up compilation API The main compilation method is now PPParser>>compileWithOptions: Removed oither old and unused compilation methods from PPParser and other PetitCompiler classes.

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

"{ NameSpace: Smalltalk }"

PPCRewritingVisitor subclass:#PPCMergingVisitor
	instanceVariableNames:'nodeSet'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Visitors'
!

!PPCMergingVisitor methodsFor:'as yet unclassified'!

equivalentNode: node
    ^  nodeSet detect: [ :e | e = node ]
!

hasEquivalentNode: node
    ^ nodeSet includes: node
!

initialize
    super initialize.
    
    nodeSet := Set new
!

store: node
    self assert: (self hasEquivalentNode: node) not.
    nodeSet add: node
!

visitNode: node
    super visitNode: node.
    
    (self hasEquivalentNode: node) ifTrue: [
        self change.
        ^ self equivalentNode: node
    ] ifFalse: [  
        self store: node
    ].

    ^ node
! !