Skip to content

Commit 3695999

Browse files
committed
Fix the setting of next blocks of breack statements
1 parent b7e058c commit 3695999

4 files changed

Lines changed: 26 additions & 4 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
@@ -985,7 +985,7 @@ FASTPythonCFGTest >> testFunctionWithWhileWithBreakInIfThen2 [
985985
break
986986
c()
987987
d()'.
988-
self skip. "To fix"
988+
989989
self assert: startBlock isConditional.
990990
self deny: startBlock isFinal.
991991
self assert: startBlock statements size equals: 1.
@@ -1015,7 +1015,7 @@ FASTPythonCFGTest >> testFunctionWithWhileWithBreakInIfThen2 [
10151015

10161016
nullBlock := startBlock nextFalseBlock.
10171017
self assert: nullBlock isNullBlock.
1018-
self assert: endOfWhile nextBlock equals: nullBlock.
1018+
self assert: thenBlock nextBlock equals: nullBlock.
10191019
self assert: nullBlock isFinal
10201020
]
10211021

@@ -1273,7 +1273,7 @@ FASTPythonCFGTest >> testFunctionWithWhileWithIfInElif [
12731273
else:
12741274
e()
12751275
f()'.
1276-
self skip. "Not working for now because break are not well managed"
1276+
12771277
self assert: startBlock isConditional.
12781278
self deny: startBlock isFinal.
12791279
self assert: startBlock statements size equals: 1.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ FASTCFGAbstractBlock >> allFollowingBlocks [
2929
^ self deep: #nextBlocks collect: #yourself
3030
]
3131

32+
{ #category : 'testing' }
33+
FASTCFGAbstractBlock >> endsWithBreakStatement [
34+
35+
^ self subclassResponsibility
36+
]
37+
3238
{ #category : 'initialization' }
3339
FASTCFGAbstractBlock >> initialize [
3440

@@ -91,6 +97,15 @@ FASTCFGAbstractBlock >> previousBlocks [
9197
^ previousBlocks
9298
]
9399

100+
{ #category : 'asserting' }
101+
FASTCFGAbstractBlock >> shouldBreakInContext: context [
102+
"I should breack this node if it's a breack and that we are currently visiting a loop. This node is breaking the loop in all cases of the current branch. "
103+
104+
self endsWithBreakStatement ifFalse: [ ^ false ].
105+
106+
^ context anySatisfy: #isLoop
107+
]
108+
94109
{ #category : 'accessing' }
95110
FASTCFGAbstractBlock >> sourceCode [
96111

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ FASTCFGNullBlock >> addNextBlock: aBlock [
1212
self error: 'A null block cannot have a next block since it represent a virtual block merging all exit points if the exit point is not unique.'
1313
]
1414

15+
{ #category : 'testing' }
16+
FASTCFGNullBlock >> endsWithBreakStatement [
17+
"I cannot contain a breack"
18+
19+
^ false
20+
]
21+
1522
{ #category : 'testing' }
1623
FASTCFGNullBlock >> isNullBlock [
1724

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ FASTTCFGUtility >> managePreviousBlocksOf: newBlock [
143143

144144
topContext currentBlocks ifEmpty: [ topContext conditional addNextBlock: newBlock ] ifNotEmpty: [ :blocksAtScope |
145145
(blocksAtScope flatCollect: #withAllFollowingBlocks)
146-
reject: [ :block | block isFull ]
146+
reject: [ :block | block isFull or: [ block shouldBreakInContext: context ] ]
147147
thenDo: [ :block | block addNextBlock: newBlock ] ]
148148
]
149149

0 commit comments

Comments
 (0)