Skip to content

Commit 952bc03

Browse files
committed
Begin to work on conditions
1 parent 201e1ee commit 952bc03

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,29 @@ FASTPythonCFGTest >> setUp [
3131
builder := FASTPythonCFGBuilder new
3232
]
3333

34+
{ #category : 'tests' }
35+
FASTPythonCFGTest >> testFunctionWithIf [
36+
37+
| nextBlock |
38+
self skip.
39+
self flag: #todo. "Finish"
40+
self buildCFGFor: 'def f(i):
41+
if i > 3:
42+
print(i)'.
43+
44+
self assert: startBlock isConditional.
45+
self assert: startBlock isFinal. "If the condition is false then the block is indeed final"
46+
self assert: startBlock statements size equals: 1.
47+
self assert: (startBlock statements first class isOfType: FASTPyComparisonOperator).
48+
self assert: startBlock nextBlocks size equals: 2.
49+
self assert: (startBlock nextBlock select: #isNullBlock) size equals: 1.
50+
51+
nextBlock := startBlock nextBlockForValue: true.
52+
self assert: nextBlock isConditional not.
53+
self assert: nextBlock isFinal.
54+
self assertEmpty: nextBlock statements
55+
]
56+
3457
{ #category : 'tests' }
3558
FASTPythonCFGTest >> testFunctionWithOneStatement [
3659

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ FASTPythonCFGVisitor >> visitFASTPyReturnStatement: aReturn [
3535
cfgBuilder currentBlock nextBlock: FASTNullBlock new
3636
]
3737

38+
{ #category : 'visiting' }
39+
FASTPythonCFGVisitor >> visitFASTTConditionalStatement: aStatement [
40+
41+
cfgBuilder newConditionalBlock: aStatement.
42+
43+
super visitFASTTConditionalStatement: aStatement
44+
]
45+
3846
{ #category : 'visiting' }
3947
FASTPythonCFGVisitor >> visitFASTTStatement: aStatement [
4048

0 commit comments

Comments
 (0)