UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

111 lines 4.73 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.values = void 0; const xpath = __importStar(require("xpath-ts2")); const post_process_1 = require("./post-process"); const assert_1 = require("../../../../util/assert"); const convert_values_1 = require("../../../../r-bridge/lang-4.x/convert-values"); const statistics_file_1 = require("../../../output/statistics-file"); const initialValueInfo = { allNumerics: 0, imaginaryNumbers: 0, integers: 0, floatHex: 0, logical: 0, specialConstants: 0, strings: 0 }; const numericConstantQuery = xpath.parse('//NUM_CONST'); const stringConstantQuery = xpath.parse('//STR_CONST'); const specialConstantsQuery = xpath.parse('//NULL_CONST'); const shortLogicalSymbolQuery = xpath.parse('//SYMBOL[text() = \'T\' or text() = \'F\']'); function classifyNumericConstants(numeric, existing) { if (numeric === convert_values_1.RTrue || numeric === convert_values_1.RFalse) { return 'logical'; } if (numeric === convert_values_1.RNa || numeric === 'NaN' || numeric === convert_values_1.RNull || numeric === 'Inf' || numeric === '-Inf') { return 'special-constants'; } if (numeric.includes('i')) { existing.imaginaryNumbers++; } else if (numeric.endsWith('L')) { existing.integers++; } else if (convert_values_1.RNumHexFloatRegex.test(numeric)) { existing.floatHex++; } return 'allNumerics'; } exports.values = { name: 'Values', description: 'All values used (as constants etc.)', process(existing, input) { const strings = stringConstantQuery.select({ node: input.parsedRAst }); const numerics = numericConstantQuery.select({ node: input.parsedRAst }); const specialConstants = specialConstantsQuery.select({ node: input.parsedRAst }); const specialLogicalSymbols = shortLogicalSymbolQuery.select({ node: input.parsedRAst }); const numbers = []; numerics.map(n => [n, classifyNumericConstants(n.textContent ?? '<unknown>', existing)]) .forEach(([n, type]) => { switch (type) { case 'allNumerics': numbers.push(n); break; case 'logical': specialLogicalSymbols.push(n); break; case 'special-constants': specialConstants.push(n); break; default: (0, assert_1.assertUnreachable)(type); } }); existing.strings += strings.length; existing.allNumerics += numerics.length; existing.specialConstants += specialConstants.length; existing.logical += specialLogicalSymbols.length; (0, statistics_file_1.appendStatisticsFile)(this.name, 'numeric', numbers, input.filepath); (0, statistics_file_1.appendStatisticsFile)(this.name, 'string', strings, input.filepath); (0, statistics_file_1.appendStatisticsFile)(this.name, 'specialConstant', specialConstants, input.filepath); (0, statistics_file_1.appendStatisticsFile)(this.name, 'logical', specialLogicalSymbols, input.filepath); return existing; }, initialValue: initialValueInfo, postProcess: post_process_1.postProcess }; //# sourceMappingURL=values.js.map