@@ -254,6 +254,178 @@ FASTPythonCFGTest >> testFunctionWithIfThenElif [
254254 self assert: nullBlock isFinal
255255]
256256
257+ { #category : ' tests - if' }
258+ FASTPythonCFGTest >> testFunctionWithIfThenElifElif [
259+
260+ | thenBlock elifConditionBlock elifBlock elifConditionBlock2 elifBlock2 nullBlock |
261+ self buildCFGFor: ' def f(i):
262+ if i > 3:
263+ print(i)
264+ elif i < 8:
265+ pass
266+ elif i < 10:
267+ a()' .
268+
269+ self assert: startBlock isConditional.
270+ self deny: startBlock isFinal.
271+ self assert: startBlock statements size equals: 1 .
272+ self assert: (startBlock statements first class isOfType: FASTPyComparisonOperator ).
273+ self assert: startBlock nextBlocks size equals: 2 .
274+ self assertEmpty: (startBlock nextBlocks select: #isNullBlock ).
275+
276+ thenBlock := startBlock nextTrueBlock.
277+ self deny: thenBlock isConditional.
278+ self deny: thenBlock isFinal.
279+ self assert: thenBlock statements size equals: 1 .
280+ self assert: (thenBlock statements first isOfType: FASTPyCall ).
281+
282+ elifConditionBlock := startBlock nextFalseBlock.
283+ self assert: elifConditionBlock isConditional.
284+ self deny: elifConditionBlock isFinal.
285+ self assert: elifConditionBlock statements size equals: 1 .
286+ self assert: (elifConditionBlock statements first isOfType: FASTPyComparisonOperator ).
287+
288+ elifBlock := elifConditionBlock nextTrueBlock.
289+ self deny: elifBlock isConditional.
290+ self deny: elifBlock isFinal.
291+ self assert: elifBlock statements size equals: 1 .
292+ self assert: (elifBlock statements first isOfType: FASTPyPassStatement ).
293+
294+ elifConditionBlock2 := elifConditionBlock nextFalseBlock.
295+ self assert: elifConditionBlock2 isConditional.
296+ self deny: elifConditionBlock2 isFinal.
297+ self assert: elifConditionBlock2 statements size equals: 1 .
298+ self assert: (elifConditionBlock2 statements first isOfType: FASTPyComparisonOperator ).
299+
300+ elifBlock2 := elifConditionBlock2 nextTrueBlock.
301+ self deny: elifBlock2 isConditional.
302+ self deny: elifBlock2 isFinal.
303+ self assert: elifBlock2 statements size equals: 1 .
304+ self assert: (elifBlock2 statements first isOfType: FASTPyCall ).
305+
306+ nullBlock := thenBlock nextBlock.
307+ self assert: nullBlock isNullBlock.
308+ self assert: nullBlock identicalTo: elifBlock nextBlock.
309+ self assert: nullBlock identicalTo: elifConditionBlock2 nextFalseBlock.
310+ self assert: nullBlock identicalTo: elifBlock2 nextBlock.
311+ self assert: nullBlock isFinal
312+ ]
313+
314+ { #category : ' tests - if' }
315+ FASTPythonCFGTest >> testFunctionWithIfThenElifElifElse [
316+
317+ | thenBlock elifConditionBlock elifBlock elifConditionBlock2 elifBlock2 elseBlock nullBlock |
318+ self buildCFGFor: ' def f(i):
319+ if i > 3:
320+ print(i)
321+ elif i < 8:
322+ pass
323+ elif i < 10:
324+ a()
325+ else:
326+ b()' .
327+
328+ self assert: startBlock isConditional.
329+ self deny: startBlock isFinal.
330+ self assert: startBlock statements size equals: 1 .
331+ self assert: (startBlock statements first class isOfType: FASTPyComparisonOperator ).
332+ self assert: startBlock nextBlocks size equals: 2 .
333+ self assertEmpty: (startBlock nextBlocks select: #isNullBlock ).
334+
335+ thenBlock := startBlock nextTrueBlock.
336+ self deny: thenBlock isConditional.
337+ self deny: thenBlock isFinal.
338+ self assert: thenBlock statements size equals: 1 .
339+ self assert: (thenBlock statements first isOfType: FASTPyCall ).
340+
341+ elifConditionBlock := startBlock nextFalseBlock.
342+ self assert: elifConditionBlock isConditional.
343+ self deny: elifConditionBlock isFinal.
344+ self assert: elifConditionBlock statements size equals: 1 .
345+ self assert: (elifConditionBlock statements first isOfType: FASTPyComparisonOperator ).
346+
347+ elifBlock := elifConditionBlock nextTrueBlock.
348+ self deny: elifBlock isConditional.
349+ self deny: elifBlock isFinal.
350+ self assert: elifBlock statements size equals: 1 .
351+ self assert: (elifBlock statements first isOfType: FASTPyPassStatement ).
352+
353+ elifConditionBlock2 := elifConditionBlock nextFalseBlock.
354+ self assert: elifConditionBlock2 isConditional.
355+ self deny: elifConditionBlock2 isFinal.
356+ self assert: elifConditionBlock2 statements size equals: 1 .
357+ self assert: (elifConditionBlock2 statements first isOfType: FASTPyComparisonOperator ).
358+
359+ elifBlock2 := elifConditionBlock2 nextTrueBlock.
360+ self deny: elifBlock2 isConditional.
361+ self deny: elifBlock2 isFinal.
362+ self assert: elifBlock2 statements size equals: 1 .
363+ self assert: (elifBlock2 statements first isOfType: FASTPyCall ).
364+
365+ elseBlock := elifConditionBlock2 nextFalseBlock.
366+ self deny: elseBlock isConditional.
367+ self deny: elseBlock isFinal.
368+ self assert: elseBlock statements size equals: 1 .
369+ self assert: (elseBlock statements first isOfType: FASTPyCall ).
370+
371+ nullBlock := thenBlock nextBlock.
372+ self assert: nullBlock isNullBlock.
373+ self assert: nullBlock identicalTo: elifBlock nextBlock.
374+ self assert: nullBlock identicalTo: elifBlock2 nextBlock.
375+ self assert: nullBlock identicalTo: elseBlock nextBlock.
376+ self assert: nullBlock isFinal
377+ ]
378+
379+ { #category : ' tests - if' }
380+ FASTPythonCFGTest >> testFunctionWithIfThenElifElse [
381+
382+ | thenBlock elifConditionBlock elifBlock elseBlock nullBlock |
383+ self buildCFGFor: ' def f(i):
384+ if i > 3:
385+ print(i)
386+ elif i < 8:
387+ pass
388+ else:
389+ a()' .
390+
391+ self assert: startBlock isConditional.
392+ self deny: startBlock isFinal.
393+ self assert: startBlock statements size equals: 1 .
394+ self assert: (startBlock statements first class isOfType: FASTPyComparisonOperator ).
395+ self assert: startBlock nextBlocks size equals: 2 .
396+ self assertEmpty: (startBlock nextBlocks select: #isNullBlock ).
397+
398+ thenBlock := startBlock nextTrueBlock.
399+ self deny: thenBlock isConditional.
400+ self deny: thenBlock isFinal.
401+ self assert: thenBlock statements size equals: 1 .
402+ self assert: (thenBlock statements first isOfType: FASTPyCall ).
403+
404+ elifConditionBlock := startBlock nextFalseBlock.
405+ self assert: elifConditionBlock isConditional.
406+ self deny: elifConditionBlock isFinal.
407+ self assert: elifConditionBlock statements size equals: 1 .
408+ self assert: (elifConditionBlock statements first isOfType: FASTPyComparisonOperator ).
409+
410+ elifBlock := elifConditionBlock nextTrueBlock.
411+ self deny: elifBlock isConditional.
412+ self deny: elifBlock isFinal.
413+ self assert: elifBlock statements size equals: 1 .
414+ self assert: (elifBlock statements first isOfType: FASTPyPassStatement ).
415+
416+ elseBlock := elifConditionBlock nextFalseBlock.
417+ self deny: elseBlock isConditional.
418+ self deny: elseBlock isFinal.
419+ self assert: elseBlock statements size equals: 1 .
420+ self assert: (elseBlock statements first isOfType: FASTPyCall ).
421+
422+ nullBlock := elseBlock nextBlock.
423+ self assert: nullBlock isNullBlock.
424+ self assert: nullBlock identicalTo: thenBlock nextBlock.
425+ self assert: nullBlock identicalTo: elifBlock nextBlock.
426+ self assert: nullBlock isFinal
427+ ]
428+
257429{ #category : ' tests - if' }
258430FASTPythonCFGTest >> testFunctionWithIfThenElse [
259431
@@ -672,3 +844,126 @@ FASTPythonCFGTest >> testFunctionWithWhileWithBreakInIfThenBreakingAndElse [
672844 self assert: thenBlock nextBlock equals: nullBlock.
673845 self assert: nullBlock isFinal
674846]
847+
848+ { #category : ' tests - while' }
849+ FASTPythonCFGTest >> testFunctionWithWhileWithBreakInIfThenBreakingAndElseBreaking [
850+
851+ | ifConditionalBlock thenBlock esleBlock nullBlock |
852+ self buildCFGFor: ' def f(i):
853+ while i < 4:
854+ a()
855+ if i > 2:
856+ b()
857+ break
858+ c()
859+ else:
860+ d()
861+ break
862+ e()' .
863+
864+ self assert: startBlock isConditional.
865+ self deny: startBlock isFinal.
866+ self assert: startBlock statements size equals: 1 .
867+ self assert: (startBlock statements first class isOfType: FASTPyComparisonOperator ).
868+ self assert: startBlock nextBlocks size equals: 2 .
869+ self assert: (startBlock nextBlocks select: #isNullBlock ) size equals: 1 .
870+
871+ ifConditionalBlock := startBlock nextTrueBlock.
872+ self assert: ifConditionalBlock isConditional.
873+ self deny: ifConditionalBlock isFinal.
874+ self assert: ifConditionalBlock statements size equals: 2 .
875+ self assert: (ifConditionalBlock statements first isOfType: FASTPyCall ).
876+ self assert: (ifConditionalBlock statements second isOfType: FASTPyComparisonOperator ).
877+
878+ thenBlock := ifConditionalBlock nextTrueBlock.
879+ self deny: thenBlock isConditional.
880+ self deny: thenBlock isFinal.
881+ self assert: thenBlock statements size equals: 2 .
882+ self assert: (thenBlock statements first isOfType: FASTPyCall ).
883+ self assert: (thenBlock statements second isOfType: FASTPyBreakStatement ).
884+
885+ esleBlock := ifConditionalBlock nextFalseBlock.
886+ self deny: esleBlock isConditional.
887+ self deny: esleBlock isFinal.
888+ self assert: esleBlock statements size equals: 2 .
889+ self assert: (esleBlock statements first isOfType: FASTPyCall ).
890+ self assert: (thenBlock statements second isOfType: FASTPyBreakStatement ).
891+
892+ nullBlock := startBlock nextFalseBlock.
893+ self assert: nullBlock isNullBlock.
894+ self assert: thenBlock nextBlock equals: nullBlock.
895+ self assert: esleBlock nextBlock equals: nullBlock.
896+ self assert: nullBlock isFinal
897+ ]
898+
899+ { #category : ' tests - while' }
900+ FASTPythonCFGTest >> testFunctionWithWhileWithBreakInIfThenElifAndElseAllBreaking [
901+
902+ | ifConditionalBlock thenBlock elifConditionalBlock elifBlock elseBlock lastBlock |
903+ self buildCFGFor: ' def f(i):
904+ while i < 4:
905+ a()
906+ if i > 2:
907+ b()
908+ break
909+ c()
910+ elif i > 1:
911+ d()
912+ break
913+ e()
914+ else:
915+ f()
916+ break
917+ g()
918+ h()' .
919+
920+ self assert: startBlock isConditional.
921+ self deny: startBlock isFinal.
922+ self assert: startBlock statements size equals: 1 .
923+ self assert: (startBlock statements first class isOfType: FASTPyComparisonOperator ).
924+ self assert: startBlock nextBlocks size equals: 2 .
925+ self assertEmpty: (startBlock nextBlocks select: #isNullBlock ).
926+
927+ ifConditionalBlock := startBlock nextTrueBlock.
928+ self assert: ifConditionalBlock isConditional.
929+ self deny: ifConditionalBlock isFinal.
930+ self assert: ifConditionalBlock statements size equals: 2 .
931+ self assert: (ifConditionalBlock statements first isOfType: FASTPyCall ).
932+ self assert: (ifConditionalBlock statements second isOfType: FASTPyComparisonOperator ).
933+
934+ thenBlock := ifConditionalBlock nextTrueBlock.
935+ self deny: thenBlock isConditional.
936+ self deny: thenBlock isFinal.
937+ self assert: thenBlock statements size equals: 2 .
938+ self assert: (thenBlock statements first isOfType: FASTPyCall ).
939+ self assert: (thenBlock statements second isOfType: FASTPyBreakStatement ).
940+
941+ elifConditionalBlock := ifConditionalBlock nextFalseBlock.
942+ self assert: elifConditionalBlock isConditional.
943+ self deny: elifConditionalBlock isFinal.
944+ self assert: elifConditionalBlock statements size equals: 1 .
945+ self assert: (elifConditionalBlock statements first isOfType: FASTPyComparisonOperator ).
946+
947+ elifBlock := elifConditionalBlock nextTrueBlock.
948+ self deny: elifBlock isConditional.
949+ self deny: elifBlock isFinal.
950+ self assert: elifBlock statements size equals: 2 .
951+ self assert: (elifBlock statements first isOfType: FASTPyCall ).
952+ self assert: (elifBlock statements second isOfType: FASTPyBreakStatement ).
953+
954+ elseBlock := elifConditionalBlock nextFalseBlock.
955+ self deny: elseBlock isConditional.
956+ self deny: elseBlock isFinal.
957+ self assert: elseBlock statements size equals: 2 .
958+ self assert: (elseBlock statements first isOfType: FASTPyCall ).
959+ self assert: (thenBlock statements second isOfType: FASTPyBreakStatement ).
960+
961+ lastBlock := startBlock nextFalseBlock.
962+ self deny: lastBlock isNullBlock.
963+ self assert: lastBlock equals: thenBlock nextBlock.
964+ self assert: lastBlock equals: elifBlock nextBlock.
965+ self assert: lastBlock equals: elseBlock nextBlock.
966+ self assert: lastBlock isFinal.
967+ self assert: lastBlock statements size equals: 1 .
968+ self assert: (lastBlock statements first isOfType: FASTPyCall )
969+ ]
0 commit comments