compiler/PPCNotNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 06 Nov 2014 02:22:56 +0000
changeset 416 b0fd54ee0412
parent 414 0eaf09920532
child 422 116d2b2af905
permissions -rw-r--r--
Do not try to inline PPCPluggableNode on Smalltalk/X Sadly, on Smalltalk/X blocks cannot be inlined because the VM does not provide enough information to map it back to the source code. Very bad indeed!

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

PPCDelegateNode subclass:#PPCNotNode
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Nodes'
!

!PPCNotNode methodsFor:'accessing'!

prefix
	^ #not
! !

!PPCNotNode methodsFor:'analysis'!

firstCharSet
	^ PPCharSetPredicate on: [:e | true ] 
!

isFirstSetTerminal
	^ true
! !

!PPCNotNode methodsFor:'compiling'!

compileWith: compiler effect: effect id: id

	compiler startMethod: id.
	compiler addVariable: 'memento'.
	compiler add: (compiler smartRemember: child).
	
	compiler call: (child compileWith: compiler).
	compiler add: (compiler smartRestore: child).

	compiler add: '^ error ifFalse: [ self error ] ifTrue: [ self clearError. nil ]'.
 ^ compiler stopMethod.
! !

!PPCNotNode methodsFor:'optimizing'!

optimize: params 
	(self rewrite: params) ifTrue: [ 
		^ true.
	].
	^ super optimize: params.
!

rewrite: changeStatus
	(child isKindOf: PPCAbstractLiteralNode) ifTrue: [  
		changeStatus change.
		^ PPCNotLiteralNode new
			name: self name;
			literal: self child literal;
			yourself
	]. 

	(child isKindOf: PPCMessagePredicateNode) ifTrue: [  
		changeStatus change.
		^ PPCNotMessagePredicateNode new
			name: self name;
			message: child message;
			yourself
	].

	(child isKindOf: PPCCharSetPredicateNode) ifTrue: [  
		changeStatus change.
		^ PPCNotCharSetPredicateNode new
			name: self name;
			predicate: child predicate;
			yourself
	].

	"Can do the fast version, because we throw away the result and return  nil"
	(self allNodes anySatisfy: [ :node | node asFast ~= node ]) ifTrue: [  
		changeStatus change.
		self replace: child with: (child transform: [:node | node asFast]).
	]
! !