[ClavaAst] Fixes NullPointerException in ControlFlowGraph
@@ -40,12 +40,23 @@ public class ControlFlowGraph extends FlowGraph {
private CompoundStmt body;
private Map<Stmt, BasicBlockNode> bbs;
+ private static String getScopeName(CompoundStmt body) {
+ // Check if parent is a FunctionDecl
+ var parent = body.getParent();
+ if (parent instanceof FunctionDecl) {
+ return ((FunctionDecl) parent).getDeclName();
+ }
+
+ return parent.getClass().getSimpleName() + "_" + parent.getId();
+ }
+
public ControlFlowGraph(FunctionDecl func) {
this(func.getBody().get()); // exception if func doesn't have body
}
public ControlFlowGraph(CompoundStmt body) {
- super("Control-flow Graph - " + ((FunctionDecl) body.getParent()).getDeclName(), "BB");
+ super("Control-flow Graph - " + getScopeName(body), "BB");
+
this.body = body;
this.bbs = new HashMap<>();
@@ -64,7 +75,7 @@ public class ControlFlowGraph extends FlowGraph {
bb.setType(BasicBlockNodeType.LOOP);
} else if (last instanceof IfStmt) {
bb.setType(BasicBlockNodeType.IF);
- IfStmt ifs = (IfStmt) last;
+ // IfStmt ifs = (IfStmt) last;
// ifs.get
} else if (last instanceof ReturnStmt) {
bb.setType(BasicBlockNodeType.EXIT);
@@ -156,9 +167,8 @@ public class ControlFlowGraph extends FlowGraph {
}
/**
- * Gets the SE, or Sibling Equivalent. This is either the first right sibling,
- * or the equivalent for CFG purposes, e.g., a scoped statement that is the
- * parent of the stmt.
+ * Gets the SE, or Sibling Equivalent. This is either the first right sibling, or the equivalent for CFG purposes,
+ * e.g., a scoped statement that is the parent of the stmt.
*
* @param stmt
* @return Some Stmt if the SE is found, Empty if it is not (end of function?)
