Added static analysis of blocks when inlining. Allow inlining only when block is functional
...i.e., does not access any shared state (in instance or class variables). If the block does
a self-send, the sent method has to be (transitively) functional too.
To allow for self-sends in action blocks, copy (transitively) self-sent methods to target
parser. This is safe as these self-sent methods are guarnateed to be functional.
"{ Package: 'stx:goodies/petitparser/compiler/tests' }"
"{ NameSpace: Smalltalk }"
TestCase subclass:#PEGFsaTransitionTest
instanceVariableNames:'t1 t2 result'
classVariableNames:''
poolDictionaries:''
category:'PetitCompiler-Tests-FSA'
!
!PEGFsaTransitionTest methodsFor:'as yet unclassified'!
setUp
t1 := PEGFsaTransition new.
t2 := PEGFsaTransition new.
!
testCompare
t1 addCharacter: $a.
t1 addCharacter: $b.
t2 addCharacter: $a.
t2 addCharacter: $b.
self assert: t1 = t2.
!
testComplement
t1 addCharacter: $a.
t1 addCharacter: $b.
t2 addCharacter: $b.
t2 addCharacter: $c.
result := t1 complement: t2.
self assert: (result at: $a codePoint).
self assert: (result at: $b codePoint) not.
self assert: (result at: $c codePoint) not.
!
testComplement2
t1 addCharacter: $a.
t1 addCharacter: $b.
t2 addCharacter: $b.
t2 addCharacter: $c.
result := t2 complement: t1.
self assert: (result at: $a codePoint) not.
self assert: (result at: $b codePoint) not.
self assert: (result at: $c codePoint).
!
testCopy
t1 addCharacter: $a.
t1 addCharacter: $b.
t2 := t1 copy.
self assert: t1 = t2.
self assert: (t1 == t2) not.
t2 destination: #foo.
self assert: (t1 = t2) not.
t1 destination: #foo.
self assert: (t1 = t2).
t1 addCharacter: $c.
self assert: (t1 = t2) not.
t2 addCharacter: $c.
t1 priority: -1.
self assert: (t1 = t2) not.
t2 priority: -1.
self assert: (t1 = t2).
!
testDisjunction
t1 addCharacter: $a.
t1 addCharacter: $c.
t2 addCharacter: $b.
t2 addCharacter: $c.
result := t1 disjunction: t2.
self assert: (result at: $a codePoint).
self assert: (result at: $b codePoint).
self assert: (result at: $c codePoint) not.
!
testIntersection
t1 addCharacter: $a.
t1 addCharacter: $b.
t2 addCharacter: $b.
t2 addCharacter: $c.
result := t1 intersection: t2.
self assert: (result at: $b codePoint).
self assert: (result at: $a codePoint) not.
self assert: (result at: $c codePoint) not.
!
testIntersection2
t1 addCharacter: $a.
t2 addCharacter: $b.
result := t1 intersection: t2.
self assert: (result allSatisfy: [:e | e not ]).
!
testUnion
t1 addCharacter: $a.
t1 addCharacter: $b.
t2 addCharacter: $b.
t2 addCharacter: $c.
result := t1 union: t2.
self assert: (result at: $b codePoint).
self assert: (result at: $a codePoint).
self assert: (result at: $c codePoint).
self assert: (result at: $d codePoint) not.
! !