Skip to content

Commit

Permalink
fix(control-flow): Proper generation of CFG for constructor (#5739)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Pine authored Apr 8, 2024
1 parent 1bddb1c commit dc50171
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ public <T> void visitCtConditional(CtConditional<T> conditional) {
}

@Override
public <T> void visitCtConstructor(CtConstructor<T> c) {

public <T> void visitCtConstructor(CtConstructor<T> constructor) {
constructor.getBody().accept(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
import org.junit.jupiter.api.Test;
import spoon.processing.AbstractProcessor;
import spoon.processing.ProcessingManager;
import spoon.reflect.declaration.CtConstructor;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.factory.Factory;
import spoon.support.QueueProcessingManager;

import java.io.PrintWriter;
import java.net.URISyntaxException;

import static fr.inria.controlflow.BranchKind.BRANCH;
import static fr.inria.controlflow.BranchKind.STATEMENT;
import static fr.inria.controlflow.BranchKind.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

/**
* Created by marodrig on 14/10/2015.
Expand Down Expand Up @@ -331,6 +333,30 @@ public void testInvocation() throws Exception {
testEdges(graph, 1, 0, 0, null);
}

@Test
public void testConstructor() throws URISyntaxException, ClassNotFoundException, IllegalAccessException, InstantiationException {
ControlFlowBuilder visitor = new ControlFlowBuilder();

Factory factory = new SpoonMetaFactory().buildNewFactory(this.getClass().getResource("/control-flow").toURI().getPath(), 17);
ProcessingManager pm = new QueueProcessingManager(factory);
pm.addProcessor(new AbstractProcessor<CtConstructor<?>>() {
@Override
public void process(CtConstructor<?> element) {
if (!element.getBody().getStatements().isEmpty()) {
visitor.build(element);
}
}

});
pm.process(factory.getModel().getRootPackage());

ControlFlowGraph graph = visitor.getResult();
ControlFlowNode entryNode = graph.findNodesOfKind(BEGIN).get(0);
ControlFlowNode exitNode = graph.getExitNode();

assertFalse(graph.containsEdge(entryNode, exitNode), "Graph is missing statements");
}

@Test
public void testtestCase() throws Exception {
//branchCount, stmntCount, totalCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ public int simple(int a) {
return 10 * a;
}

public ControlFlowArithmetic() {
int a = 1;
}

///////////////////////////////////////////////////////////////////////////////////////////


Expand Down

0 comments on commit dc50171

Please sign in to comment.