Skip to content

Commit bcee95d

Browse files
committed
Tests for while and for were wrong
1 parent 7cd9583 commit bcee95d

5 files changed

Lines changed: 49 additions & 10 deletions

File tree

src/FAST-Python-Tools-Tests/FASTPythonCFGTest.class.st

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ FASTPythonCFGTest >> testFunctionWithFor [
4545
self deny: forBlock isFinal.
4646
self assert: forBlock statements size equals: 1.
4747
self assert: (forBlock statements first isOfType: FASTPyCall).
48+
self assert: forBlock nextBlock equals: startBlock.
4849

4950
nullBlock := startBlock nextFalseBlock.
5051
self assert: nullBlock isNullBlock.
51-
self assert: nullBlock identicalTo: forBlock nextBlock.
5252
self assert: nullBlock isFinal
5353
]
5454

@@ -442,9 +442,9 @@ FASTPythonCFGTest >> testFunctionWithWhile [
442442
self assert: whileBlock statements size equals: 2.
443443
self assert: (whileBlock statements first isOfType: FASTPyAugmentedAssignment).
444444
self assert: (whileBlock statements second isOfType: FASTPyCall).
445-
445+
self assert: whileBlock nextBlock equals: startBlock.
446+
446447
nullBlock := startBlock nextFalseBlock.
447448
self assert: nullBlock isNullBlock.
448-
self assert: nullBlock identicalTo: whileBlock nextBlock.
449449
self assert: nullBlock isFinal
450450
]

src/FAST-Python-Tools/FASTCFGAbstractBlock.class.st

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Class {
22
#name : 'FASTCFGAbstractBlock',
33
#superclass : 'Object',
44
#instVars : [
5+
'isStart',
56
'statements',
67
'previousBlocks'
78
],
@@ -26,7 +27,8 @@ FASTCFGAbstractBlock >> addPreviousBlock: aBlock [
2627
FASTCFGAbstractBlock >> initialize [
2728

2829
super initialize.
29-
previousBlocks := OrderedCollection new
30+
previousBlocks := OrderedCollection new.
31+
isStart := false
3032
]
3133

3234
{ #category : 'inspector' }
@@ -62,10 +64,14 @@ FASTCFGAbstractBlock >> isNullBlock [
6264
^ false
6365
]
6466

65-
{ #category : 'testing' }
67+
{ #category : 'accessing' }
6668
FASTCFGAbstractBlock >> isStart [
69+
^ isStart
70+
]
6771

68-
^ self previousBlocks isEmpty
72+
{ #category : 'accessing' }
73+
FASTCFGAbstractBlock >> isStart: anObject [
74+
isStart := anObject
6975
]
7076

7177
{ #category : 'accessing' }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Class {
2+
#name : 'FASTCFGLoopConditionalBlock',
3+
#superclass : 'FASTCFGConditionalBlock',
4+
#category : 'FAST-Python-Tools-CFG/DataFlow',
5+
#package : 'FAST-Python-Tools',
6+
#tag : 'CFG/DataFlow'
7+
}
8+
9+
{ #category : 'adding' }
10+
FASTCFGLoopConditionalBlock >> addNextBlock: aBlock [
11+
12+
| nextBlock |
13+
nextBlock := super addNextBlock: aBlock.
14+
15+
"In a loop, by default my first node loop to myself. There is an edge case when the first statement is a break, but this will be managed elsewhere."
16+
(self nextBlocks indexOf: nextBlock) = 1 ifTrue: [ nextBlock addNextBlock: self ].
17+
18+
^ nextBlock
19+
]

src/FAST-Python-Tools/FASTPythonCFGVisitor.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ FASTPythonCFGVisitor >> visitFASTPyForStatement: aForStatement [
3939
self addStatement: aForStatement left.
4040
self addStatement: aForStatement right.
4141

42-
self buildAndUseConditionalBlockDuring: [
42+
self buildAndUseLoopConditionalBlockDuring: [
4343
self visitFASTTStatementBlock: aForStatement.
4444

4545
self flag: #todo. "Manage and test else clause"
@@ -71,7 +71,7 @@ FASTPythonCFGVisitor >> visitFASTPyWhileStatement: aWhileStatement [
7171

7272
self visitFASTTConditionalStatement: aWhileStatement.
7373

74-
self buildAndUseConditionalBlockDuring: [
74+
self buildAndUseLoopConditionalBlockDuring: [
7575
self visitFASTTStatementBlock: aWhileStatement.
7676

7777
self flag: #todo. "Manage and test else clause"

src/FAST-Python-Tools/FASTTCFGUtility.trait.st

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,28 @@ FASTTCFGUtility >> allBlocks [
3333
{ #category : 'running' }
3434
FASTTCFGUtility >> buildAndUseConditionalBlockDuring: aBlock [
3535

36+
^ self buildAndUseConditionalOfKind: FASTCFGConditionalBlock during: aBlock
37+
]
38+
39+
{ #category : 'running' }
40+
FASTTCFGUtility >> buildAndUseConditionalOfKind: aClass during: aBlock [
41+
3642
| conditional |
3743
[
38-
conditional := self buildBlockOfType: FASTCFGConditionalBlock.
44+
conditional := self buildBlockOfType: aClass.
3945
currentConditionals push: conditional.
4046

4147
aBlock value ] ensure: [
4248
self assert: conditional == currentConditionals top description: 'The top conditional does not match the one produced before the execution of the block'.
4349
currentConditionals pop ]
4450
]
4551

52+
{ #category : 'running' }
53+
FASTTCFGUtility >> buildAndUseLoopConditionalBlockDuring: aBlock [
54+
55+
^ self buildAndUseConditionalOfKind: FASTCFGLoopConditionalBlock during: aBlock
56+
]
57+
4658
{ #category : 'running' }
4759
FASTTCFGUtility >> buildBlockIfNeeded [
4860
"If we have statements stocked, we create a new block with them. Else we do nothing."
@@ -61,7 +73,9 @@ FASTTCFGUtility >> buildBlockOfType: aBlockClass [
6173

6274
self managePreviousBlocksOf: newBlock.
6375

64-
startBlock ifNil: [ startBlock := newBlock ].
76+
startBlock ifNil: [
77+
startBlock := newBlock.
78+
newBlock isStart: true ].
6579

6680
^ newBlock
6781
]

0 commit comments

Comments
 (0)