UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

85 lines 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidVertexTypeReverse = exports.ValidVertexTypes = exports.VertexType = void 0; exports.isNamedArgumentId = isNamedArgumentId; exports.isParentContainerIndex = isParentContainerIndex; exports.isAccessed = isAccessed; exports.isSameIndex = isSameIndex; exports.isValueVertex = isValueVertex; exports.isUseVertex = isUseVertex; exports.isFunctionCallVertex = isFunctionCallVertex; exports.isVariableDefinitionVertex = isVariableDefinitionVertex; exports.isFunctionDefinitionVertex = isFunctionDefinitionVertex; var VertexType; (function (VertexType) { VertexType["Value"] = "value"; VertexType["Use"] = "use"; VertexType["FunctionCall"] = "function-call"; VertexType["VariableDefinition"] = "variable-definition"; VertexType["FunctionDefinition"] = "function-definition"; })(VertexType || (exports.VertexType = VertexType = {})); exports.ValidVertexTypes = new Set(Object.values(VertexType)); exports.ValidVertexTypeReverse = Object.fromEntries(Object.entries(VertexType).map(([k, v]) => [v, k])); function isNamedArgumentId(identifier) { return 'lexeme' in identifier; } function isParentContainerIndex(index) { return 'subIndices' in index; } /** * Checks whether {@link index} is accessed by {@link accessLexeme}. * * @param index - The {@link ContainerIndex}, which is accessed * @param accessLexeme - The access lexeme * @param isIndexBasedAccess - Whether the index of the {@link ContainerIndex} is accessed i.e. the position in the container and not e.g. the name of the index * @returns true, when {@link accessLexeme} accesses the {@link index}, false otherwise */ function isAccessed(index, accessLexeme, isIndexBasedAccess) { if (isIndexBasedAccess) { return index.identifier.index === Number(accessLexeme); } if (isNamedArgumentId(index.identifier)) { return index.identifier.lexeme === accessLexeme; } return false; } function isSameIndex(a, b) { if (isNamedArgumentId(a.identifier) && isNamedArgumentId(b.identifier)) { return a.identifier.lexeme === b.identifier.lexeme; } if (a.identifier.index === undefined || b.identifier.index === undefined) { return false; } return a.identifier.index === b.identifier.index; } /** * Check if the given vertex is a {@link DataflowGraphVertexValue|value vertex}. */ function isValueVertex(vertex) { return vertex?.tag === VertexType.Value; } /** * Check if the given vertex is a {@link DataflowGraphVertexUse|use vertex}. */ function isUseVertex(vertex) { return vertex?.tag === VertexType.Use; } /** * Check if the given vertex is a {@link DataflowGraphVertexFunctionCall|function call vertex}. */ function isFunctionCallVertex(vertex) { return vertex?.tag === VertexType.FunctionCall; } /** * Check if the given vertex is a {@link DataflowGraphVertexVariableDefinition|variable definition vertex}. */ function isVariableDefinitionVertex(vertex) { return vertex?.tag === VertexType.VariableDefinition; } /** * Check if the given vertex is a {@link DataflowGraphVertexFunctionDefinition|function definition vertex}. */ function isFunctionDefinitionVertex(vertex) { return vertex?.tag === VertexType.FunctionDefinition; } //# sourceMappingURL=vertex.js.map