ControlFlowGraph { public CfgBlock start() { return start; } ControlFlowGraph(ImmutableSet<CfgBlock> blocks, CfgBlock start, PhpCfgEndBlock end); @VisibleForTesting static ControlFlowGraph build(BlockTree body); @CheckForNull static ControlFlowGraph build(Tree tree, CheckContext context); CfgBlock start(); CfgBlock end(); Set<CfgBlock> blocks(); static final Set<Tree.Kind> KINDS_WITH_CONTROL_FLOW; }
@Test public void test_start_is_first_block() { ControlFlowGraph cfg = cfgForBlock("" + "foo();" + "if (a) {" + " $x = 1;" + "}"); CfgBlock startBlock = cfg.start(); assertThat(startBlock.elements()).isNotEmpty(); Tree firstElement = startBlock.elements().get(0); assertThat(firstElement.getKind()).isEqualTo(Tree.Kind.EXPRESSION_STATEMENT); ExpressionStatementTree statement = (ExpressionStatementTree) firstElement; assertThat(statement.expression().getKind()).isEqualTo(Tree.Kind.FUNCTION_CALL); }
@Test public void test_branching_tree() { ControlFlowGraph cfg = cfgForBlock("" + "if (a) {" + " qix();" + "}"); CfgBlock block = cfg.start(); assertThat(block instanceof PhpCfgBranchingBlock).isTrue(); PhpCfgBranchingBlock ifBlock = (PhpCfgBranchingBlock) block; assertThat(ifBlock.branchingTree().getKind()).isEqualTo(Tree.Kind.IF_STATEMENT); }