@eagleoutice/flowr 2.2.16 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +48 -20
  2. package/abstract-interpretation/data-frame/absint-info.d.ts +109 -0
  3. package/abstract-interpretation/data-frame/absint-info.js +31 -0
  4. package/abstract-interpretation/data-frame/absint-visitor.d.ts +58 -0
  5. package/abstract-interpretation/data-frame/absint-visitor.js +171 -0
  6. package/abstract-interpretation/data-frame/domain.d.ts +107 -0
  7. package/abstract-interpretation/data-frame/domain.js +315 -0
  8. package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +17 -0
  9. package/abstract-interpretation/data-frame/mappers/access-mapper.js +166 -0
  10. package/abstract-interpretation/data-frame/mappers/arguments.d.ts +117 -0
  11. package/abstract-interpretation/data-frame/mappers/arguments.js +188 -0
  12. package/abstract-interpretation/data-frame/mappers/assignment-mapper.d.ts +20 -0
  13. package/abstract-interpretation/data-frame/mappers/assignment-mapper.js +34 -0
  14. package/abstract-interpretation/data-frame/mappers/function-mapper.d.ts +261 -0
  15. package/abstract-interpretation/data-frame/mappers/function-mapper.js +1219 -0
  16. package/abstract-interpretation/data-frame/mappers/replacement-mapper.d.ts +12 -0
  17. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +206 -0
  18. package/abstract-interpretation/data-frame/resolve-args.d.ts +42 -0
  19. package/abstract-interpretation/data-frame/resolve-args.js +118 -0
  20. package/abstract-interpretation/data-frame/semantics.d.ts +213 -0
  21. package/abstract-interpretation/data-frame/semantics.js +363 -0
  22. package/abstract-interpretation/data-frame/shape-inference.d.ts +38 -0
  23. package/abstract-interpretation/data-frame/shape-inference.js +111 -0
  24. package/benchmark/slicer.d.ts +15 -1
  25. package/benchmark/slicer.js +137 -0
  26. package/benchmark/stats/print.js +123 -45
  27. package/benchmark/stats/size-of.d.ts +7 -0
  28. package/benchmark/stats/size-of.js +1 -0
  29. package/benchmark/stats/stats.d.ts +30 -1
  30. package/benchmark/stats/stats.js +4 -2
  31. package/benchmark/summarizer/data.d.ts +33 -2
  32. package/benchmark/summarizer/first-phase/input.js +5 -1
  33. package/benchmark/summarizer/first-phase/process.js +47 -1
  34. package/benchmark/summarizer/second-phase/graph.js +1 -1
  35. package/benchmark/summarizer/second-phase/process.js +102 -4
  36. package/cli/benchmark-app.d.ts +2 -0
  37. package/cli/benchmark-app.js +2 -0
  38. package/cli/benchmark-helper-app.d.ts +2 -0
  39. package/cli/benchmark-helper-app.js +10 -3
  40. package/cli/common/options.js +4 -0
  41. package/cli/repl/commands/repl-query.js +1 -1
  42. package/cli/repl/server/connection.js +14 -5
  43. package/config.d.ts +31 -0
  44. package/config.js +21 -1
  45. package/control-flow/basic-cfg-guided-visitor.d.ts +1 -2
  46. package/control-flow/basic-cfg-guided-visitor.js +0 -6
  47. package/control-flow/cfg-simplification.d.ts +6 -0
  48. package/control-flow/cfg-simplification.js +18 -9
  49. package/control-flow/control-flow-graph.d.ts +3 -8
  50. package/control-flow/control-flow-graph.js +5 -6
  51. package/control-flow/dfg-cfg-guided-visitor.js +1 -1
  52. package/control-flow/extract-cfg.d.ts +2 -2
  53. package/control-flow/extract-cfg.js +52 -63
  54. package/control-flow/semantic-cfg-guided-visitor.d.ts +1 -1
  55. package/control-flow/semantic-cfg-guided-visitor.js +1 -1
  56. package/core/steps/all/static-slicing/00-slice.d.ts +7 -1
  57. package/core/steps/all/static-slicing/00-slice.js +9 -3
  58. package/core/steps/pipeline/default-pipelines.d.ts +74 -74
  59. package/dataflow/environments/built-in.d.ts +7 -5
  60. package/dataflow/environments/built-in.js +16 -13
  61. package/dataflow/eval/resolve/alias-tracking.js +2 -2
  62. package/dataflow/eval/resolve/resolve.d.ts +53 -9
  63. package/dataflow/eval/resolve/resolve.js +132 -38
  64. package/dataflow/graph/dataflowgraph-builder.js +2 -2
  65. package/dataflow/graph/graph.js +1 -1
  66. package/dataflow/graph/invert-dfg.d.ts +2 -0
  67. package/dataflow/graph/invert-dfg.js +17 -0
  68. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +1 -0
  69. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +4 -0
  70. package/documentation/doc-util/doc-query.js +11 -1
  71. package/documentation/doc-util/doc-search.js +2 -2
  72. package/documentation/print-cfg-wiki.js +3 -4
  73. package/documentation/print-core-wiki.js +2 -2
  74. package/documentation/print-dataflow-graph-wiki.js +7 -0
  75. package/documentation/print-faq-wiki.js +4 -0
  76. package/documentation/print-interface-wiki.js +11 -0
  77. package/documentation/print-linter-wiki.js +36 -4
  78. package/documentation/print-linting-and-testing-wiki.js +13 -1
  79. package/documentation/print-onboarding-wiki.js +4 -0
  80. package/documentation/print-query-wiki.js +29 -3
  81. package/linter/linter-executor.js +1 -2
  82. package/linter/linter-format.d.ts +26 -4
  83. package/linter/linter-format.js +25 -6
  84. package/linter/linter-rules.d.ts +63 -12
  85. package/linter/linter-rules.js +5 -1
  86. package/linter/rules/absolute-path.d.ts +4 -7
  87. package/linter/rules/absolute-path.js +9 -6
  88. package/linter/rules/dataframe-access-validation.d.ts +55 -0
  89. package/linter/rules/dataframe-access-validation.js +118 -0
  90. package/linter/rules/dead-code.d.ts +43 -0
  91. package/linter/rules/dead-code.js +50 -0
  92. package/linter/rules/deprecated-functions.d.ts +3 -2
  93. package/linter/rules/deprecated-functions.js +3 -1
  94. package/linter/rules/file-path-validity.d.ts +4 -4
  95. package/linter/rules/file-path-validity.js +8 -6
  96. package/linter/rules/naming-convention.d.ts +5 -4
  97. package/linter/rules/naming-convention.js +8 -2
  98. package/linter/rules/seeded-randomness.d.ts +4 -3
  99. package/linter/rules/seeded-randomness.js +3 -1
  100. package/linter/rules/unused-definition.d.ts +2 -0
  101. package/linter/rules/unused-definition.js +3 -1
  102. package/package.json +2 -2
  103. package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -1
  104. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -0
  105. package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
  106. package/queries/catalog/df-shape-query/df-shape-query-executor.d.ts +3 -0
  107. package/queries/catalog/df-shape-query/df-shape-query-executor.js +46 -0
  108. package/queries/catalog/df-shape-query/df-shape-query-format.d.ts +72 -0
  109. package/queries/catalog/df-shape-query/df-shape-query-format.js +31 -0
  110. package/queries/catalog/linter-query/linter-query-format.js +1 -1
  111. package/queries/catalog/location-map-query/location-map-query-executor.js +7 -5
  112. package/queries/catalog/location-map-query/location-map-query-format.d.ts +3 -0
  113. package/queries/catalog/location-map-query/location-map-query-format.js +1 -0
  114. package/queries/catalog/search-query/search-query-executor.js +1 -1
  115. package/queries/catalog/static-slice-query/static-slice-query-executor.js +2 -1
  116. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +3 -0
  117. package/queries/catalog/static-slice-query/static-slice-query-format.js +3 -1
  118. package/queries/query-print.d.ts +1 -1
  119. package/queries/query-print.js +0 -1
  120. package/queries/query.d.ts +77 -6
  121. package/queries/query.js +26 -11
  122. package/search/flowr-search-builder.d.ts +6 -6
  123. package/search/flowr-search-executor.d.ts +2 -2
  124. package/search/flowr-search-executor.js +1 -1
  125. package/search/flowr-search.d.ts +13 -8
  126. package/search/flowr-search.js +21 -0
  127. package/search/search-executor/search-enrichers.d.ts +87 -20
  128. package/search/search-executor/search-enrichers.js +44 -5
  129. package/search/search-executor/search-generators.d.ts +4 -4
  130. package/search/search-executor/search-generators.js +12 -7
  131. package/search/search-executor/search-mappers.js +3 -2
  132. package/search/search-executor/search-transformer.d.ts +3 -3
  133. package/search/search-executor/search-transformer.js +2 -2
  134. package/slicing/static/static-slicer.d.ts +4 -2
  135. package/slicing/static/static-slicer.js +10 -4
  136. package/util/collections/arrays.d.ts +2 -0
  137. package/util/collections/arrays.js +9 -0
  138. package/util/files.d.ts +8 -2
  139. package/util/files.js +22 -4
  140. package/util/mermaid/dfg.js +4 -2
  141. package/util/r-value.d.ts +23 -0
  142. package/util/r-value.js +113 -0
  143. package/util/range.d.ts +1 -0
  144. package/util/range.js +5 -1
  145. package/util/version.js +1 -1
  146. package/util/cfg/cfg.d.ts +0 -0
  147. package/util/cfg/cfg.js +0 -2
@@ -0,0 +1,12 @@
1
+ import type { DataflowGraph } from '../../../dataflow/graph/graph';
2
+ import type { RNode } from '../../../r-bridge/lang-4.x/ast/model/model';
3
+ import type { ParentInformation } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
+ import type { DataFrameExpressionInfo } from '../absint-info';
5
+ /**
6
+ * Maps a concrete data frame replacement function to abstract data frame operations.
7
+ *
8
+ * @param node - The R node of the replacement function
9
+ * @param dfg - The data flow graph for resolving the arguments
10
+ * @returns Data frame expression info containing the mapped abstract data frame operations, or `undefined` if the node does not represent a data frame replacement function
11
+ */
12
+ export declare function mapDataFrameReplacementFunction(node: RNode<ParentInformation>, expression: RNode<ParentInformation>, dfg: DataflowGraph): DataFrameExpressionInfo | undefined;
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapDataFrameReplacementFunction = mapDataFrameReplacementFunction;
4
+ const config_1 = require("../../../config");
5
+ const vertex_1 = require("../../../dataflow/graph/vertex");
6
+ const make_argument_1 = require("../../../dataflow/internal/process/functions/call/argument/make-argument");
7
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
8
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
9
+ const resolve_args_1 = require("../resolve-args");
10
+ const semantics_1 = require("../semantics");
11
+ const access_mapper_1 = require("./access-mapper");
12
+ const arguments_1 = require("./arguments");
13
+ /** Mapper for mapping the supported data frame replacement functions to mapper functions */
14
+ const DataFrameReplacementFunctionMapper = {
15
+ 'colnames': mapDataFrameColNamesAssignment,
16
+ 'names': mapDataFrameColNamesAssignment,
17
+ 'rownames': mapDataFrameRowNamesAssignment,
18
+ 'dimnames': mapDataFrameDimNamesAssignment
19
+ };
20
+ /**
21
+ * Maps a concrete data frame replacement function to abstract data frame operations.
22
+ *
23
+ * @param node - The R node of the replacement function
24
+ * @param dfg - The data flow graph for resolving the arguments
25
+ * @returns Data frame expression info containing the mapped abstract data frame operations, or `undefined` if the node does not represent a data frame replacement function
26
+ */
27
+ function mapDataFrameReplacementFunction(node, expression, dfg) {
28
+ const parent = hasParentReplacement(node, dfg) ? dfg.idMap?.get(node.info.parent) : undefined;
29
+ const resolveInfo = { graph: dfg, idMap: dfg.idMap, full: true, resolve: config_1.VariableResolve.Alias };
30
+ let operations;
31
+ if (node.type === type_1.RType.Access) {
32
+ if (node.access.every(arg => arg === r_function_call_1.EmptyArgument)) {
33
+ operations = mapDataFrameContentAssignment(node, expression, resolveInfo);
34
+ }
35
+ else if ((0, access_mapper_1.isStringBasedAccess)(node)) {
36
+ operations = mapDataFrameNamedColumnAssignment(node, expression, resolveInfo);
37
+ }
38
+ else {
39
+ operations = mapDataFrameIndexColRowAssignment(node, expression, resolveInfo);
40
+ }
41
+ }
42
+ else if (node.type === type_1.RType.FunctionCall && node.named && node.arguments.length === 1 && node.arguments[0] !== r_function_call_1.EmptyArgument) {
43
+ if (isDataFrameReplacement(node.functionName.content)) {
44
+ const functionName = node.functionName.content;
45
+ const functionMapping = DataFrameReplacementFunctionMapper[functionName];
46
+ operations = functionMapping(node.arguments[0], expression, resolveInfo, parent);
47
+ }
48
+ else {
49
+ operations = mapDataFrameUnknownAssignment(node.arguments[0], expression, resolveInfo);
50
+ }
51
+ }
52
+ if (operations !== undefined) {
53
+ return { type: 'expression', operations: operations };
54
+ }
55
+ }
56
+ function isDataFrameReplacement(functionName) {
57
+ // a check with `functionName in DataFrameReplacementFunctionMapper` would return true for "toString"
58
+ return Object.prototype.hasOwnProperty.call(DataFrameReplacementFunctionMapper, functionName);
59
+ }
60
+ function hasParentReplacement(node, dfg) {
61
+ const parentVertex = node.info.parent ? dfg.getVertex(node.info.parent) : undefined;
62
+ return (0, vertex_1.isFunctionCallVertex)(parentVertex) && parentVertex.origin.includes('builtin:replacement');
63
+ }
64
+ function mapDataFrameContentAssignment(access, expression, info) {
65
+ const dataFrame = access.accessed;
66
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, info)) {
67
+ return;
68
+ }
69
+ if ((0, arguments_1.isRNull)(expression)) {
70
+ return [{
71
+ operation: 'subsetCols',
72
+ operand: dataFrame.info.id,
73
+ colnames: [],
74
+ type: semantics_1.ConstraintType.OperandModification
75
+ }];
76
+ }
77
+ else {
78
+ return [{
79
+ operation: 'identity',
80
+ operand: dataFrame.info.id,
81
+ type: semantics_1.ConstraintType.OperandModification
82
+ }];
83
+ }
84
+ }
85
+ function mapDataFrameNamedColumnAssignment(access, expression, info) {
86
+ const dataFrame = access.accessed;
87
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, info)) {
88
+ return;
89
+ }
90
+ const colname = (0, resolve_args_1.resolveIdToArgValueSymbolName)(access.access[0], info);
91
+ if ((0, arguments_1.isRNull)(expression)) {
92
+ return [{
93
+ operation: 'removeCols',
94
+ operand: dataFrame.info.id,
95
+ colnames: colname ? [colname] : undefined,
96
+ type: semantics_1.ConstraintType.OperandModification,
97
+ options: { maybe: true }
98
+ }];
99
+ }
100
+ else {
101
+ return [{
102
+ operation: 'assignCols',
103
+ operand: dataFrame.info.id,
104
+ columns: colname ? [colname] : undefined
105
+ }];
106
+ }
107
+ }
108
+ function mapDataFrameIndexColRowAssignment(access, expression, info) {
109
+ const dataFrame = access.accessed;
110
+ const args = access.access;
111
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, info) || args.every(arg => arg === r_function_call_1.EmptyArgument)) {
112
+ return;
113
+ }
114
+ const result = [];
115
+ const rowArg = args.length < 2 ? undefined : args[0];
116
+ const colArg = args.length < 2 ? args[0] : args[1];
117
+ if (rowArg !== undefined && rowArg !== r_function_call_1.EmptyArgument) {
118
+ const rowValue = (0, resolve_args_1.resolveIdToArgValue)(rowArg, info);
119
+ let rows = undefined;
120
+ if (typeof rowValue === 'number') {
121
+ rows = [rowValue];
122
+ }
123
+ else if (Array.isArray(rowValue) && rowValue.every(row => typeof row === 'number')) {
124
+ rows = rowValue;
125
+ }
126
+ result.push({
127
+ operation: 'assignRows',
128
+ operand: dataFrame.info.id,
129
+ rows
130
+ });
131
+ }
132
+ if (colArg !== undefined && colArg !== r_function_call_1.EmptyArgument) {
133
+ const colValue = (0, resolve_args_1.resolveIdToArgValue)(colArg, info);
134
+ let columns = undefined;
135
+ if (typeof colValue === 'string') {
136
+ columns = [colValue];
137
+ }
138
+ else if (typeof colValue === 'number') {
139
+ columns = [colValue];
140
+ }
141
+ else if (Array.isArray(colValue) && (colValue.every(col => typeof col === 'string') || colValue.every(col => typeof col === 'number'))) {
142
+ columns = colValue;
143
+ }
144
+ if ((0, arguments_1.isRNull)(expression)) {
145
+ result.push({
146
+ operation: 'removeCols',
147
+ operand: dataFrame.info.id,
148
+ colnames: columns?.map(col => typeof col === 'string' ? col : undefined),
149
+ type: semantics_1.ConstraintType.OperandModification,
150
+ options: { maybe: true }
151
+ });
152
+ }
153
+ else {
154
+ result.push({
155
+ operation: 'assignCols',
156
+ operand: dataFrame.info.id,
157
+ columns
158
+ });
159
+ }
160
+ }
161
+ return result;
162
+ }
163
+ function mapDataFrameColNamesAssignment(operand, expression, info, parent) {
164
+ if (!(0, arguments_1.isDataFrameArgument)(operand, info)) {
165
+ return;
166
+ }
167
+ const argument = info.idMap !== undefined ? (0, make_argument_1.toUnnamedArgument)(expression, info.idMap) : r_function_call_1.EmptyArgument;
168
+ const assignedNames = (0, resolve_args_1.resolveIdToArgStringVector)(argument, info);
169
+ return [{
170
+ operation: 'setColNames',
171
+ operand: operand.value?.info.id,
172
+ colnames: assignedNames,
173
+ ...(parent !== undefined ? { options: { partial: true } } : {})
174
+ }];
175
+ }
176
+ function mapDataFrameRowNamesAssignment(operand, expression, info) {
177
+ if (!(0, arguments_1.isDataFrameArgument)(operand, info)) {
178
+ return;
179
+ }
180
+ return [{
181
+ operation: 'identity',
182
+ operand: operand.value?.info.id,
183
+ type: semantics_1.ConstraintType.OperandModification
184
+ }];
185
+ }
186
+ function mapDataFrameDimNamesAssignment(operand, expression, info) {
187
+ if (!(0, arguments_1.isDataFrameArgument)(operand, info)) {
188
+ return;
189
+ }
190
+ return [{
191
+ operation: 'setColNames',
192
+ operand: operand.value?.info.id,
193
+ colnames: undefined
194
+ }];
195
+ }
196
+ function mapDataFrameUnknownAssignment(operand, expression, info) {
197
+ if (!(0, arguments_1.isDataFrameArgument)(operand, info)) {
198
+ return;
199
+ }
200
+ return [{
201
+ operation: 'unknown',
202
+ operand: operand.value?.info.id,
203
+ type: semantics_1.ConstraintType.OperandModification
204
+ }];
205
+ }
206
+ //# sourceMappingURL=replacement-mapper.js.map
@@ -0,0 +1,42 @@
1
+ import type { ResolveInfo } from '../../dataflow/eval/resolve/alias-tracking';
2
+ import type { RArgument } from '../../r-bridge/lang-4.x/ast/model/nodes/r-argument';
3
+ import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
+ import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
5
+ /**
6
+ * Returns the argument name of a function argument
7
+ */
8
+ export declare function resolveIdToArgName(id: NodeId | RArgument<ParentInformation> | undefined, info: ResolveInfo): string | undefined;
9
+ /**
10
+ * Resolves the value of a function argument as string, number, boolean, or vector using {@link resolveIdToValue}
11
+ */
12
+ export declare function resolveIdToArgValue(id: NodeId | RArgument<ParentInformation> | undefined, info: ResolveInfo): string | number | boolean | (string | number | boolean)[] | undefined;
13
+ /**
14
+ * Resolves the value of a function argument to a string vector using {@link resolveIdToValue} and {@link unwrapRValueToString}
15
+ */
16
+ export declare function resolveIdToArgStringVector(id: NodeId | RArgument<ParentInformation> | undefined, info: ResolveInfo): string[] | undefined;
17
+ /**
18
+ * Returns the symbol name or string value of the value of a function argument
19
+ */
20
+ export declare function resolveIdToArgValueSymbolName(id: NodeId | RArgument<ParentInformation> | undefined, info: ResolveInfo): string | undefined;
21
+ /**
22
+ * Resolves the vector length of the value of a function argument using {@link resolveIdToValue}
23
+ */
24
+ export declare function resolveIdToArgVectorLength(id: NodeId | RArgument<ParentInformation> | undefined, info: ResolveInfo): number | undefined;
25
+ /**
26
+ * Removes a leading and trailing quote like `` ` ``, `"`, `'` from a string argument
27
+ */
28
+ export declare function unquoteArgument(argument: undefined): undefined;
29
+ export declare function unquoteArgument(argument: string): string;
30
+ export declare function unquoteArgument(argument: string | undefined): string | undefined;
31
+ /**
32
+ * Unescapes escaped quotes like `\'`, `\"` back into actual single and double quotes
33
+ */
34
+ export declare function unescapeQuotes(argument: undefined): undefined;
35
+ export declare function unescapeQuotes(argument: string): string;
36
+ export declare function unescapeQuotes(argument: string | undefined): string | undefined;
37
+ /**
38
+ * Unescapes escape sequences like `\n`, `\t`, `\'`, `\"`, `\\` back into actual newlines, tabs, quotes, and backslashes
39
+ */
40
+ export declare function unescapeSpecialChars(argument: undefined): undefined;
41
+ export declare function unescapeSpecialChars(argument: string): string;
42
+ export declare function unescapeSpecialChars(argument: string | undefined): string | undefined;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveIdToArgName = resolveIdToArgName;
4
+ exports.resolveIdToArgValue = resolveIdToArgValue;
5
+ exports.resolveIdToArgStringVector = resolveIdToArgStringVector;
6
+ exports.resolveIdToArgValueSymbolName = resolveIdToArgValueSymbolName;
7
+ exports.resolveIdToArgVectorLength = resolveIdToArgVectorLength;
8
+ exports.unquoteArgument = unquoteArgument;
9
+ exports.unescapeQuotes = unescapeQuotes;
10
+ exports.unescapeSpecialChars = unescapeSpecialChars;
11
+ const alias_tracking_1 = require("../../dataflow/eval/resolve/alias-tracking");
12
+ const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
13
+ const assert_1 = require("../../util/assert");
14
+ const r_value_1 = require("../../util/r-value");
15
+ const strings_1 = require("../../util/text/strings");
16
+ /**
17
+ * Returns the argument name of a function argument
18
+ */
19
+ function resolveIdToArgName(id, info) {
20
+ const node = resolveIdToArgument(id, info);
21
+ return unquoteArgument(node?.name?.content);
22
+ }
23
+ /**
24
+ * Resolves the value of a function argument as string, number, boolean, or vector using {@link resolveIdToValue}
25
+ */
26
+ function resolveIdToArgValue(id, info) {
27
+ const node = resolveIdToArgument(id, info);
28
+ if (node?.value !== undefined) {
29
+ const resolvedValue = (0, alias_tracking_1.resolveIdToValue)(node.value, info);
30
+ const unliftedValue = (0, r_value_1.unliftRValue)(resolvedValue);
31
+ if (Array.isArray(unliftedValue)) {
32
+ return (0, r_value_1.unwrapRVector)(unliftedValue);
33
+ }
34
+ else {
35
+ return (0, r_value_1.unwrapRValue)(unliftedValue);
36
+ }
37
+ }
38
+ return undefined;
39
+ }
40
+ /**
41
+ * Resolves the value of a function argument to a string vector using {@link resolveIdToValue} and {@link unwrapRValueToString}
42
+ */
43
+ function resolveIdToArgStringVector(id, info) {
44
+ const node = resolveIdToArgument(id, info);
45
+ if (node?.value !== undefined) {
46
+ const resolvedValue = (0, alias_tracking_1.resolveIdToValue)(node.value, info);
47
+ const unliftedValue = (0, r_value_1.unliftRValue)(resolvedValue);
48
+ if (Array.isArray(unliftedValue)) {
49
+ const array = unliftedValue.map(r_value_1.unwrapRValueToString);
50
+ return array.every(assert_1.isNotUndefined) ? array : undefined;
51
+ }
52
+ else {
53
+ const result = (0, r_value_1.unwrapRValueToString)(unliftedValue);
54
+ return result !== undefined ? [result] : undefined;
55
+ }
56
+ }
57
+ return undefined;
58
+ }
59
+ /**
60
+ * Returns the symbol name or string value of the value of a function argument
61
+ */
62
+ function resolveIdToArgValueSymbolName(id, info) {
63
+ const node = resolveIdToArgument(id, info);
64
+ if (node?.value?.type === type_1.RType.Symbol) {
65
+ return unquoteArgument(node.value.content);
66
+ }
67
+ else if (node?.value?.type === type_1.RType.String) {
68
+ return node.value.content.str;
69
+ }
70
+ return undefined;
71
+ }
72
+ /**
73
+ * Resolves the vector length of the value of a function argument using {@link resolveIdToValue}
74
+ */
75
+ function resolveIdToArgVectorLength(id, info) {
76
+ const node = resolveIdToArgument(id, info);
77
+ if (node?.value !== undefined) {
78
+ const resolvedValue = (0, alias_tracking_1.resolveIdToValue)(node.value, info);
79
+ const unliftedValue = (0, r_value_1.unliftRValue)(resolvedValue);
80
+ if (Array.isArray(unliftedValue)) {
81
+ return unliftedValue.length;
82
+ }
83
+ else if ((0, r_value_1.unwrapRValue)(unliftedValue) !== undefined) {
84
+ return 1;
85
+ }
86
+ }
87
+ return undefined;
88
+ }
89
+ function resolveIdToArgument(id, { graph, idMap }) {
90
+ idMap ??= graph?.idMap;
91
+ const node = id === undefined || typeof id === 'object' ? id : idMap?.get(id);
92
+ if (node?.type === type_1.RType.Argument) {
93
+ return node;
94
+ }
95
+ return undefined;
96
+ }
97
+ function unquoteArgument(argument) {
98
+ if (argument === undefined) {
99
+ return undefined;
100
+ }
101
+ else if ((0, strings_1.startAndEndsWith)(argument, '`') || (0, strings_1.startAndEndsWith)(argument, '"') || (0, strings_1.startAndEndsWith)(argument, '\'')) {
102
+ return argument.slice(1, -1);
103
+ }
104
+ return argument;
105
+ }
106
+ function unescapeQuotes(argument) {
107
+ if (argument === undefined) {
108
+ return undefined;
109
+ }
110
+ return argument.replaceAll('\\\'', '\'').replaceAll('\\"', '"');
111
+ }
112
+ function unescapeSpecialChars(argument) {
113
+ if (argument === undefined) {
114
+ return undefined;
115
+ }
116
+ return unescapeQuotes(argument).replaceAll('\\n', '\n').replaceAll('\\t', '\t').replaceAll('\\\\', '\\');
117
+ }
118
+ //# sourceMappingURL=resolve-args.js.map
@@ -0,0 +1,213 @@
1
+ import type { DataFrameDomain } from './domain';
2
+ /**
3
+ * Represents the different types of resulting constraints that are inferred by abstract data frame operations.
4
+ */
5
+ export declare enum ConstraintType {
6
+ /** The inferred constraints must hold for the operand at the point of the operation */
7
+ OperandPrecondition = 0,
8
+ /** The inferred constraints are applied to the operand during the operation */
9
+ OperandModification = 1,
10
+ /** The inferred constraints must hold for the returned result of the operation */
11
+ ResultPostcondition = 2
12
+ }
13
+ /**
14
+ * Mapper for defining the abstract data frame operations and mapping them to semantics applier functions,
15
+ * including information about the type of the resulting constraints that are inferred by the operation.
16
+ */
17
+ declare const DataFrameSemanticsMapper: {
18
+ readonly create: {
19
+ readonly apply: typeof applyCreateSemantics;
20
+ readonly type: ConstraintType.ResultPostcondition;
21
+ };
22
+ readonly read: {
23
+ readonly apply: typeof applyReadSemantics;
24
+ readonly type: ConstraintType.ResultPostcondition;
25
+ };
26
+ readonly accessCols: {
27
+ readonly apply: typeof applyAccessColsSemantics;
28
+ readonly type: ConstraintType.OperandPrecondition;
29
+ };
30
+ readonly accessRows: {
31
+ readonly apply: typeof applyAccessRowsSemantics;
32
+ readonly type: ConstraintType.OperandPrecondition;
33
+ };
34
+ readonly assignCols: {
35
+ readonly apply: typeof applyAssignColsSemantics;
36
+ readonly type: ConstraintType.OperandModification;
37
+ };
38
+ readonly assignRows: {
39
+ readonly apply: typeof applyAssignRowsSemantics;
40
+ readonly type: ConstraintType.OperandModification;
41
+ };
42
+ readonly setColNames: {
43
+ readonly apply: typeof applySetColNamesSemantics;
44
+ readonly type: ConstraintType.OperandModification;
45
+ };
46
+ readonly addCols: {
47
+ readonly apply: typeof applyAddColsSemantics;
48
+ readonly type: ConstraintType.ResultPostcondition;
49
+ };
50
+ readonly addRows: {
51
+ readonly apply: typeof applyAddRowsSemantics;
52
+ readonly type: ConstraintType.ResultPostcondition;
53
+ };
54
+ readonly removeCols: {
55
+ readonly apply: typeof applyRemoveColsSemantics;
56
+ readonly type: ConstraintType.ResultPostcondition;
57
+ };
58
+ readonly removeRows: {
59
+ readonly apply: typeof applyRemoveRowsSemantics;
60
+ readonly type: ConstraintType.ResultPostcondition;
61
+ };
62
+ readonly concatCols: {
63
+ readonly apply: typeof applyConcatColsSemantics;
64
+ readonly type: ConstraintType.ResultPostcondition;
65
+ };
66
+ readonly concatRows: {
67
+ readonly apply: typeof applyConcatRowsSemantics;
68
+ readonly type: ConstraintType.ResultPostcondition;
69
+ };
70
+ readonly subsetCols: {
71
+ readonly apply: typeof applySubsetColsSemantics;
72
+ readonly type: ConstraintType.ResultPostcondition;
73
+ };
74
+ readonly subsetRows: {
75
+ readonly apply: typeof applySubsetRowsSemantics;
76
+ readonly type: ConstraintType.ResultPostcondition;
77
+ };
78
+ readonly filterRows: {
79
+ readonly apply: typeof applyFilterRowsSemantics;
80
+ readonly type: ConstraintType.ResultPostcondition;
81
+ };
82
+ readonly mutateCols: {
83
+ readonly apply: typeof applyMutateColsSemantics;
84
+ readonly type: ConstraintType.ResultPostcondition;
85
+ };
86
+ readonly groupBy: {
87
+ readonly apply: typeof applyGroupBySemantics;
88
+ readonly type: ConstraintType.ResultPostcondition;
89
+ };
90
+ readonly summarize: {
91
+ readonly apply: typeof applySummarizeSemantics;
92
+ readonly type: ConstraintType.ResultPostcondition;
93
+ };
94
+ readonly join: {
95
+ readonly apply: typeof applyJoinSemantics;
96
+ readonly type: ConstraintType.ResultPostcondition;
97
+ };
98
+ readonly unknown: {
99
+ readonly apply: typeof applyUnknownSemantics;
100
+ readonly type: ConstraintType.ResultPostcondition;
101
+ };
102
+ readonly identity: {
103
+ readonly apply: typeof applyIdentitySemantics;
104
+ readonly type: ConstraintType.ResultPostcondition;
105
+ };
106
+ };
107
+ /** All available abstract data frame operations */
108
+ export type DataFrameOperationName = keyof typeof DataFrameSemanticsMapper;
109
+ /** The names of all abstract data frame operations */
110
+ export declare const DataFrameOperationNames: DataFrameOperationName[];
111
+ /** The required arguments for an abstract data frame operation */
112
+ export type DataFrameOperationArgs<N extends DataFrameOperationName> = Parameters<typeof DataFrameSemanticsMapper[N]['apply']>[1];
113
+ /** The optional addition options for an abstract data frame operation */
114
+ export type DataFrameOperationOptions<N extends DataFrameOperationName> = Parameters<typeof DataFrameSemanticsMapper[N]['apply']>[2];
115
+ /**
116
+ * Applies the abstract semantics of an abstract data frame operation with respect to the data frame shape domain.
117
+ * This expects that all arguments have already been sanitized according to the original concrete data frame function (e.g. by replacing duplicate/invalid column names).
118
+ *
119
+ * @param operation - The name of the abstract operation to apply the semantics of
120
+ * @param value - The abstract data frame shape of the operand of the abstract operation
121
+ * @param args - The arguments for applying the abstract semantics of the abstract operation
122
+ * @param options - The optional additional options of the abstract operation
123
+ * @returns The resulting new data frame shape constraints.
124
+ * The semantic type of the resulting constraints depends on the {@link ConstraintType} of the abstract operation.
125
+ */
126
+ export declare function applyDataFrameSemantics<Name extends DataFrameOperationName>(operation: Name, value: DataFrameDomain, args: DataFrameOperationArgs<Name>, options?: DataFrameOperationOptions<Name>): DataFrameDomain;
127
+ /**
128
+ * Gets the default resulting constraint type for an abstract data frame operation.
129
+ */
130
+ export declare function getConstraintType(operation: DataFrameOperationName): ConstraintType;
131
+ declare function applyCreateSemantics(value: DataFrameDomain, { colnames, rows }: {
132
+ colnames: (string | undefined)[] | undefined;
133
+ rows: number | [number, number] | undefined;
134
+ }): DataFrameDomain;
135
+ declare function applyReadSemantics(value: DataFrameDomain, { colnames, rows }: {
136
+ source: string | undefined;
137
+ colnames: (string | undefined)[] | undefined;
138
+ rows: number | [number, number] | undefined;
139
+ }): DataFrameDomain;
140
+ declare function applyAccessColsSemantics(value: DataFrameDomain, { columns }: {
141
+ columns: string[] | number[] | undefined;
142
+ }): DataFrameDomain;
143
+ declare function applyAccessRowsSemantics(value: DataFrameDomain, { rows }: {
144
+ rows: number[] | undefined;
145
+ }): DataFrameDomain;
146
+ declare function applyAssignColsSemantics(value: DataFrameDomain, { columns }: {
147
+ columns: string[] | number[] | undefined;
148
+ }): DataFrameDomain;
149
+ declare function applyAssignRowsSemantics(value: DataFrameDomain, { rows }: {
150
+ rows: number[] | undefined;
151
+ }): DataFrameDomain;
152
+ declare function applySetColNamesSemantics(value: DataFrameDomain, { colnames }: {
153
+ colnames: (string | undefined)[] | undefined;
154
+ }, options?: {
155
+ partial?: boolean;
156
+ }): DataFrameDomain;
157
+ declare function applyAddColsSemantics(value: DataFrameDomain, { colnames }: {
158
+ colnames: (string | undefined)[] | undefined;
159
+ }): DataFrameDomain;
160
+ declare function applyAddRowsSemantics(value: DataFrameDomain, { rows }: {
161
+ rows: number | undefined;
162
+ }): DataFrameDomain;
163
+ declare function applyRemoveColsSemantics(value: DataFrameDomain, { colnames }: {
164
+ colnames: (string | undefined)[] | undefined;
165
+ }, options?: {
166
+ maybe?: boolean;
167
+ }): DataFrameDomain;
168
+ declare function applyRemoveRowsSemantics(value: DataFrameDomain, { rows }: {
169
+ rows: number | undefined;
170
+ }, options?: {
171
+ maybe?: boolean;
172
+ }): DataFrameDomain;
173
+ declare function applyConcatColsSemantics(value: DataFrameDomain, { other }: {
174
+ other: DataFrameDomain;
175
+ }): DataFrameDomain;
176
+ declare function applyConcatRowsSemantics(value: DataFrameDomain, { other }: {
177
+ other: DataFrameDomain;
178
+ }): DataFrameDomain;
179
+ declare function applySubsetColsSemantics(value: DataFrameDomain, { colnames }: {
180
+ colnames: (string | undefined)[] | undefined;
181
+ }, options?: {
182
+ duplicateCols?: boolean;
183
+ renamedCols?: boolean;
184
+ }): DataFrameDomain;
185
+ declare function applySubsetRowsSemantics(value: DataFrameDomain, { rows }: {
186
+ rows: number | undefined;
187
+ }, options?: {
188
+ duplicateRows?: boolean;
189
+ }): DataFrameDomain;
190
+ declare function applyFilterRowsSemantics(value: DataFrameDomain, { condition }: {
191
+ condition: boolean | undefined;
192
+ }): DataFrameDomain;
193
+ declare function applyMutateColsSemantics(value: DataFrameDomain, { colnames }: {
194
+ colnames: (string | undefined)[] | undefined;
195
+ }): DataFrameDomain;
196
+ declare function applyGroupBySemantics(value: DataFrameDomain, { by }: {
197
+ by: (string | undefined)[];
198
+ }, options?: {
199
+ mutatedCols?: boolean;
200
+ }): DataFrameDomain;
201
+ declare function applySummarizeSemantics(value: DataFrameDomain, { colnames }: {
202
+ colnames: (string | undefined)[] | undefined;
203
+ }): DataFrameDomain;
204
+ declare function applyJoinSemantics(value: DataFrameDomain, { other, by }: {
205
+ other: DataFrameDomain;
206
+ by: (string | undefined)[] | undefined;
207
+ }, options?: {
208
+ join?: 'inner' | 'left' | 'right' | 'full';
209
+ natural?: boolean;
210
+ }): DataFrameDomain;
211
+ declare function applyIdentitySemantics(value: DataFrameDomain, _args: {}): DataFrameDomain;
212
+ declare function applyUnknownSemantics(_value: DataFrameDomain, _args: {}): DataFrameDomain;
213
+ export {};