@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
71 lines • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataflowAwareCfgGuidedVisitor = void 0;
const vertex_1 = require("../dataflow/graph/vertex");
const basic_cfg_guided_visitor_1 = require("./basic-cfg-guided-visitor");
const assert_1 = require("../util/assert");
/**
* This visitor extends on the {@link BasicCfgGuidedVisitor} by dispatching visitors based on the dataflow graph.
*
* Use {@link BasicCfgGuidedVisitor#start} to start the traversal.
*/
class DataflowAwareCfgGuidedVisitor extends basic_cfg_guided_visitor_1.BasicCfgGuidedVisitor {
/**
* Get the dataflow graph vertex for the given id
*/
getDataflowGraph(id) {
return this.config.dfg.getVertex(id);
}
onStatementNode(node) {
super.onStatementNode(node);
this.onExprOrStmtNode(node);
}
onExpressionNode(node) {
super.onExpressionNode(node);
this.onExprOrStmtNode(node);
}
onExprOrStmtNode(node) {
const dfgVertex = this.getDataflowGraph(node.id);
if (!dfgVertex) {
this.visitUnknown(node);
return;
}
const tag = dfgVertex.tag;
switch (tag) {
case vertex_1.VertexType.Use:
this.visitVariableUse(dfgVertex);
break;
case vertex_1.VertexType.VariableDefinition:
this.visitVariableDefinition(dfgVertex);
break;
case vertex_1.VertexType.FunctionDefinition:
this.visitFunctionDefinition(dfgVertex);
break;
case vertex_1.VertexType.FunctionCall:
this.visitFunctionCall(dfgVertex);
break;
case vertex_1.VertexType.Value:
this.visitValue(dfgVertex);
break;
default:
(0, assert_1.assertUnreachable)(tag);
}
}
/**
* called for every cfg vertex that has no corresponding dataflow vertex.
*/
visitUnknown(_vertex) {
}
visitValue(_val) {
}
visitVariableUse(_use) {
}
visitVariableDefinition(_def) {
}
visitFunctionDefinition(_def) {
}
visitFunctionCall(_call) {
}
}
exports.DataflowAwareCfgGuidedVisitor = DataflowAwareCfgGuidedVisitor;
//# sourceMappingURL=dfg-cfg-guided-visitor.js.map