UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

62 lines 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.variables = void 0; const post_process_1 = require("./post-process"); const statistics_file_1 = require("../../../output/statistics-file"); const vertex_1 = require("../../../../dataflow/graph/vertex"); const range_1 = require("../../../../util/range"); const r_project_1 = require("../../../../r-bridge/lang-4.x/ast/model/nodes/r-project"); const r_symbol_1 = require("../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol"); const model_1 = require("../../../../r-bridge/lang-4.x/ast/model/model"); 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) { r_project_1.RProject.visitAst(input.normalizedRAst.ast, node => { if (!r_symbol_1.RSymbol.is(node) || r_symbol_1.RSymbol.isSpecial(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', [[ model_1.RNode.lexeme(node), range_1.SourceRange.getStart(node.location) ]], input.filepath); return; } const [dfNode] = mayNode; if (dfNode.tag === vertex_1.VertexType.VariableDefinition) { info.numberOfDefinitions++; const lexeme = model_1.RNode.lexeme(node); (0, statistics_file_1.appendStatisticsFile)(exports.variables.name, 'definedVariables', [[ lexeme, range_1.SourceRange.getStart(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', [[ model_1.RNode.lexeme(node), range_1.SourceRange.getStart(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