@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
61 lines • 2.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.variables = void 0;
const post_process_1 = require("./post-process");
const range_1 = require("../../../../util/range");
const visitor_1 = require("../../../../r-bridge/lang-4.x/ast/model/processing/visitor");
const type_1 = require("../../../../r-bridge/lang-4.x/ast/model/type");
const r_symbol_1 = require("../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
const statistics_file_1 = require("../../../output/statistics-file");
const initialVariableInfo = {
numberOfVariableUses: 0,
numberOfDefinitions: 0,
numberOfRedefinitions: 0,
// we failed to get the type/role, maybe for function call names etc.
unknownVariables: 0
};
function visitVariables(info, input) {
(0, visitor_1.visitAst)(input.normalizedRAst.ast, node => {
if (node.type !== type_1.RType.Symbol || (0, r_symbol_1.isSpecialSymbol)(node)) {
return;
}
// search for the node in the DF graph
const mayNode = input.dataflow.graph.get(node.info.id);
if (mayNode === undefined) {
info.unknownVariables++;
(0, statistics_file_1.appendStatisticsFile)(exports.variables.name, 'unknown', [[
node.info.fullLexeme ?? node.lexeme,
(0, range_1.getRangeStart)(node.location)
]], input.filepath);
return;
}
const [dfNode] = mayNode;
if (dfNode.tag === 'variable-definition') {
info.numberOfDefinitions++;
const lexeme = node.info.fullLexeme ?? node.lexeme;
(0, statistics_file_1.appendStatisticsFile)(exports.variables.name, 'definedVariables', [[
lexeme,
(0, range_1.getRangeStart)(node.location)
]], input.filepath);
// checking for redefinitions is no longer possible in its current form!
}
else if (dfNode.tag === 'use') {
info.numberOfVariableUses++;
(0, statistics_file_1.appendStatisticsFile)(exports.variables.name, 'usedVariables', [[
node.info.fullLexeme ?? node.lexeme,
(0, range_1.getRangeStart)(node.location)
]], input.filepath);
}
});
}
exports.variables = {
name: 'Variables',
description: 'Variable Usage, Assignments, and Redefinitions',
process(existing, input) {
visitVariables(existing, input);
return existing;
},
initialValue: initialVariableInfo,
postProcess: post_process_1.postProcess
};
//# sourceMappingURL=variables.js.map