compiler/PPCNotNode.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 01 Nov 2014 00:30:28 +0000
changeset 403 7063d523b064
parent 392 9b297f0d949c
child 414 0eaf09920532
permissions -rw-r--r--
Removed autoload attribut for tests. As all classes are in a test package, when package is loaded likely tests are required, so load them right away.

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

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

!PPCNotNode methodsFor:'accessing'!

prefix
	^ #not
! !

!PPCNotNode methodsFor:'analysis'!

isFirstSetTerminal
	^ false
! !

!PPCNotNode methodsFor:'compiling'!

compileWith: compiler effect: effect id: id

	compiler startMethod: id.
	compiler addVariable: 'memento'.
	compiler add: (compiler smartRemember: child).
	
	compiler startTokenMode.
	compiler call: (child compileWith: compiler).
	compiler stopTokenMode.
	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
	] 
! !