@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
43 lines • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeIdToNumberIfPossible = normalizeIdToNumberIfPossible;
exports.recoverName = recoverName;
exports.recoverContent = recoverContent;
const vertex_1 = require("../../../../../dataflow/graph/vertex");
const retriever_1 = require("../../../../retriever");
const numIdRegex = /^\d+$/;
/** used so that we do not have to store strings for the default numeric ids */
function normalizeIdToNumberIfPossible(id) {
// check if string is number
if (typeof id === 'string' && numIdRegex.test(id)) {
return Number(id);
}
return id;
}
/**
* Recovers the lexeme of a {@link RNode|node} from its id in the {@link AstIdMap|id map}.
*
* @see {@link recoverContent} - to recover the content of a node
*/
function recoverName(id, idMap) {
return idMap?.get(id)?.lexeme;
}
/**
* Recovers the content of a {@link RNode|node} from its id in the {@link DataflowGraph|dataflow graph}.
*/
function recoverContent(id, graph) {
const vertex = graph.getVertex(id);
if (vertex && vertex.tag === vertex_1.VertexType.FunctionCall && vertex.name) {
return vertex.name;
}
const node = graph.idMap?.get(id);
if (node === undefined) {
return undefined;
}
const lexeme = node.lexeme ?? node.info.fullLexeme ?? '';
if (vertex?.tag === vertex_1.VertexType.Use) {
return (0, retriever_1.removeRQuotes)(lexeme);
}
return lexeme;
}
//# sourceMappingURL=node-id.js.map