@eagleoutice/flowr 2.2.14 → 2.2.15

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 (83) hide show
  1. package/README.md +4 -4
  2. package/cli/repl/commands/repl-commands.js +1 -1
  3. package/cli/repl/commands/repl-execute.js +2 -1
  4. package/config.js +1 -1
  5. package/control-flow/basic-cfg-guided-visitor.d.ts +3 -3
  6. package/control-flow/cfg-dead-code.d.ts +4 -0
  7. package/control-flow/cfg-dead-code.js +81 -0
  8. package/control-flow/cfg-simplification.d.ts +17 -6
  9. package/control-flow/cfg-simplification.js +23 -19
  10. package/control-flow/control-flow-graph.d.ts +2 -1
  11. package/control-flow/control-flow-graph.js +1 -0
  12. package/control-flow/dfg-cfg-guided-visitor.d.ts +4 -4
  13. package/control-flow/dfg-cfg-guided-visitor.js +1 -1
  14. package/control-flow/extract-cfg.d.ts +1 -1
  15. package/control-flow/extract-cfg.js +60 -57
  16. package/control-flow/semantic-cfg-guided-visitor.d.ts +17 -8
  17. package/control-flow/semantic-cfg-guided-visitor.js +50 -17
  18. package/control-flow/simple-visitor.d.ts +4 -0
  19. package/control-flow/simple-visitor.js +14 -0
  20. package/control-flow/syntax-cfg-guided-visitor.d.ts +2 -2
  21. package/dataflow/environments/built-in-config.d.ts +1 -0
  22. package/dataflow/environments/built-in.d.ts +10 -1
  23. package/dataflow/environments/built-in.js +9 -3
  24. package/dataflow/environments/default-builtin-config.js +1 -1
  25. package/dataflow/environments/resolve-by-name.d.ts +0 -36
  26. package/dataflow/environments/resolve-by-name.js +0 -240
  27. package/dataflow/eval/resolve/alias-tracking.d.ts +87 -0
  28. package/dataflow/eval/resolve/alias-tracking.js +349 -0
  29. package/dataflow/eval/resolve/resolve.d.ts +34 -0
  30. package/dataflow/eval/resolve/resolve.js +93 -0
  31. package/dataflow/eval/values/general.d.ts +27 -0
  32. package/dataflow/eval/values/general.js +73 -0
  33. package/dataflow/eval/values/intervals/interval-constants.d.ts +4 -0
  34. package/dataflow/eval/values/intervals/interval-constants.js +27 -0
  35. package/dataflow/eval/values/logical/logical-constants.d.ts +7 -0
  36. package/dataflow/eval/values/logical/logical-constants.js +31 -0
  37. package/dataflow/eval/values/r-value.d.ts +58 -0
  38. package/dataflow/eval/values/r-value.js +90 -0
  39. package/dataflow/eval/values/scalar/scalar-consatnts.d.ts +15 -0
  40. package/dataflow/eval/values/scalar/scalar-consatnts.js +35 -0
  41. package/dataflow/eval/values/sets/set-constants.d.ts +7 -0
  42. package/dataflow/eval/values/sets/set-constants.js +34 -0
  43. package/dataflow/eval/values/string/string-constants.d.ts +8 -0
  44. package/dataflow/eval/values/string/string-constants.js +40 -0
  45. package/dataflow/eval/values/vectors/vector-constants.d.ts +14 -0
  46. package/dataflow/eval/values/vectors/vector-constants.js +35 -0
  47. package/dataflow/graph/unknown-replacement.d.ts +11 -0
  48. package/dataflow/graph/unknown-replacement.js +12 -0
  49. package/dataflow/graph/unknown-side-effect.d.ts +7 -0
  50. package/dataflow/graph/unknown-side-effect.js +13 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -5
  52. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +4 -2
  53. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +12 -9
  54. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -4
  55. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +9 -2
  56. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +12 -15
  57. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -0
  58. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
  59. package/documentation/doc-util/doc-query.d.ts +6 -3
  60. package/documentation/doc-util/doc-query.js +3 -1
  61. package/documentation/print-cfg-wiki.js +6 -6
  62. package/documentation/print-dataflow-graph-wiki.js +4 -3
  63. package/documentation/print-engines-wiki.js +1 -1
  64. package/documentation/print-query-wiki.js +80 -0
  65. package/linter/rules/1-deprecated-functions.js +1 -1
  66. package/linter/rules/2-file-path-validity.js +1 -1
  67. package/package.json +1 -1
  68. package/queries/catalog/control-flow-query/control-flow-query-executor.d.ts +3 -0
  69. package/queries/catalog/control-flow-query/control-flow-query-executor.js +20 -0
  70. package/queries/catalog/control-flow-query/control-flow-query-format.d.ts +81 -0
  71. package/queries/catalog/control-flow-query/control-flow-query-format.js +34 -0
  72. package/queries/catalog/dependencies-query/dependencies-query-executor.js +33 -32
  73. package/queries/catalog/linter-query/linter-query-format.js +2 -1
  74. package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +3 -3
  75. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +2 -1
  76. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +2 -22
  77. package/queries/query.d.ts +61 -1
  78. package/queries/query.js +2 -0
  79. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +11 -4
  80. package/search/search-executor/search-enrichers.js +5 -2
  81. package/slicing/criterion/parse.d.ts +8 -0
  82. package/slicing/criterion/parse.js +20 -0
  83. package/util/version.js +1 -1
@@ -0,0 +1,34 @@
1
+ import type { AstIdMap, RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
+ import type { REnvironmentInformation } from '../../environments/environment';
3
+ import type { DataflowGraph } from '../../graph/graph';
4
+ import type { Value } from '../values/r-value';
5
+ /**
6
+ * Helper function used by {@link resolveIdToValue}, please use that instead, if
7
+ * you want to resolve the value of a identifier / node
8
+ *
9
+ * This function converts an RNode to its Value, but also recursivly resolves
10
+ * aliases and vectors (in case of a vector).
11
+ *
12
+ * @param a - Ast node to resolve
13
+ * @param env - Environment to use
14
+ * @param graph - Dataflow Graph to use
15
+ * @param map - Idmap of Dataflow Graph
16
+ * @returns resolved value or top/bottom
17
+ */
18
+ export declare function resolveNode(a: RNodeWithParent, env?: REnvironmentInformation, graph?: DataflowGraph, map?: AstIdMap): Value;
19
+ /**
20
+ * Helper function used by {@link resolveIdToValue}, please use that instead, if
21
+ * you want to resolve the value of a identifier / node
22
+ *
23
+ * This function converts an rnode to a Value Vector {@link vectorFrom}
24
+ * It also recursivly resolves any symbols, values, function calls (only c), in
25
+ * order to construct the value of the vector to resolve by calling {@link resolveIdToValue}
26
+ * or {@link resolveNode}
27
+ *
28
+ * @param a - Node of the vector to resolve
29
+ * @param env - Environment to use
30
+ * @param graph - Dataflow graph
31
+ * @param map - Idmap of Dataflow Graph
32
+ * @returns ValueVector or Top
33
+ */
34
+ export declare function resolveAsVector(a: RNodeWithParent, env: REnvironmentInformation, graph?: DataflowGraph, map?: AstIdMap): Value;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveNode = resolveNode;
4
+ exports.resolveAsVector = resolveAsVector;
5
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
6
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
7
+ const assert_1 = require("../../../util/assert");
8
+ const built_in_1 = require("../../environments/built-in");
9
+ const dfg_get_origin_1 = require("../../origin/dfg-get-origin");
10
+ const interval_constants_1 = require("../values/intervals/interval-constants");
11
+ const logical_constants_1 = require("../values/logical/logical-constants");
12
+ const r_value_1 = require("../values/r-value");
13
+ const string_constants_1 = require("../values/string/string-constants");
14
+ const vector_constants_1 = require("../values/vectors/vector-constants");
15
+ const alias_tracking_1 = require("./alias-tracking");
16
+ /**
17
+ * Helper function used by {@link resolveIdToValue}, please use that instead, if
18
+ * you want to resolve the value of a identifier / node
19
+ *
20
+ * This function converts an RNode to its Value, but also recursivly resolves
21
+ * aliases and vectors (in case of a vector).
22
+ *
23
+ * @param a - Ast node to resolve
24
+ * @param env - Environment to use
25
+ * @param graph - Dataflow Graph to use
26
+ * @param map - Idmap of Dataflow Graph
27
+ * @returns resolved value or top/bottom
28
+ */
29
+ function resolveNode(a, env, graph, map) {
30
+ if (a.type === type_1.RType.String) {
31
+ return (0, string_constants_1.stringFrom)(a.content.str);
32
+ }
33
+ else if (a.type === type_1.RType.Number) {
34
+ return (0, interval_constants_1.intervalFrom)(a.content.num, a.content.num);
35
+ }
36
+ else if (a.type === type_1.RType.Logical) {
37
+ return a.content.valueOf() ? logical_constants_1.ValueLogicalTrue : logical_constants_1.ValueLogicalFalse;
38
+ }
39
+ else if (a.type === type_1.RType.FunctionCall && env && graph) {
40
+ const origin = (0, dfg_get_origin_1.getOriginInDfg)(graph, a.info.id)?.[0];
41
+ if (origin === undefined || origin.type !== 3 /* OriginType.BuiltInFunctionOrigin */) {
42
+ return r_value_1.Top;
43
+ }
44
+ if (origin.proc in built_in_1.BuiltInEvalHandlerMapper) {
45
+ const handler = built_in_1.BuiltInEvalHandlerMapper[origin.proc];
46
+ return handler(a, env, graph, map);
47
+ }
48
+ }
49
+ return r_value_1.Top;
50
+ }
51
+ /**
52
+ * Helper function used by {@link resolveIdToValue}, please use that instead, if
53
+ * you want to resolve the value of a identifier / node
54
+ *
55
+ * This function converts an rnode to a Value Vector {@link vectorFrom}
56
+ * It also recursivly resolves any symbols, values, function calls (only c), in
57
+ * order to construct the value of the vector to resolve by calling {@link resolveIdToValue}
58
+ * or {@link resolveNode}
59
+ *
60
+ * @param a - Node of the vector to resolve
61
+ * @param env - Environment to use
62
+ * @param graph - Dataflow graph
63
+ * @param map - Idmap of Dataflow Graph
64
+ * @returns ValueVector or Top
65
+ */
66
+ function resolveAsVector(a, env, graph, map) {
67
+ (0, assert_1.guard)(a.type === type_1.RType.FunctionCall);
68
+ const values = [];
69
+ for (const arg of a.arguments) {
70
+ if (arg === r_function_call_1.EmptyArgument) {
71
+ continue;
72
+ }
73
+ if (arg.value === undefined) {
74
+ return r_value_1.Top;
75
+ }
76
+ if (arg.value.type === type_1.RType.Symbol) {
77
+ const value = (0, alias_tracking_1.resolveIdToValue)(arg.info.id, { environment: env, idMap: map, graph: graph, full: true });
78
+ if ((0, r_value_1.isTop)(value)) {
79
+ return r_value_1.Top;
80
+ }
81
+ values.push(value);
82
+ }
83
+ else {
84
+ const val = resolveNode(arg.value, env, graph, map);
85
+ if ((0, r_value_1.isTop)(val)) {
86
+ return r_value_1.Top;
87
+ }
88
+ values.push(val);
89
+ }
90
+ }
91
+ return (0, vector_constants_1.vectorFrom)((0, vector_constants_1.flattenVectorElements)(values));
92
+ }
93
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1,27 @@
1
+ import type { RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
+ import type { Lift, Value, ValueSet } from './r-value';
3
+ import { Bottom, Top } from './r-value';
4
+ /**
5
+ * Takes n potentially lifted ops and returns `Top` or `Bottom` if any is `Top` or `Bottom`.
6
+ */
7
+ export declare function bottomTopGuard(...a: Lift<unknown>[]): typeof Top | typeof Bottom | undefined;
8
+ /**
9
+ * Returns a value set, if a is not bottom or top, otherwise undefined.
10
+ * Useful when working with values returned by {@link resolveIdToValue}
11
+ *
12
+ * @param a - value set to check
13
+ * @returns value set if a is not top or bottom
14
+ */
15
+ export declare function valueSetGuard(a: Lift<ValueSet<Value[]>>): ValueSet<Value[]> | undefined;
16
+ /**
17
+ * Constructs an Abstract Value from a normal TS value
18
+ * @param a - ts value
19
+ * @returns abstract value
20
+ */
21
+ export declare function valueFromTsValue(a: unknown): Value;
22
+ /**
23
+ * Converts a constant from an RNode into an abstract value
24
+ * @param a - RNode constant
25
+ * @returns abstract value
26
+ */
27
+ export declare function valueFromRNodeConstant(a: RNodeWithParent): Value;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bottomTopGuard = bottomTopGuard;
4
+ exports.valueSetGuard = valueSetGuard;
5
+ exports.valueFromTsValue = valueFromTsValue;
6
+ exports.valueFromRNodeConstant = valueFromRNodeConstant;
7
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
8
+ const interval_constants_1 = require("./intervals/interval-constants");
9
+ const logical_constants_1 = require("./logical/logical-constants");
10
+ const r_value_1 = require("./r-value");
11
+ const string_constants_1 = require("./string/string-constants");
12
+ /**
13
+ * Takes n potentially lifted ops and returns `Top` or `Bottom` if any is `Top` or `Bottom`.
14
+ */
15
+ function bottomTopGuard(...a) {
16
+ if (a.some(r_value_1.isBottom)) {
17
+ return r_value_1.Bottom;
18
+ }
19
+ else if (a.some(r_value_1.isTop)) {
20
+ return r_value_1.Top;
21
+ }
22
+ }
23
+ /**
24
+ * Returns a value set, if a is not bottom or top, otherwise undefined.
25
+ * Useful when working with values returned by {@link resolveIdToValue}
26
+ *
27
+ * @param a - value set to check
28
+ * @returns value set if a is not top or bottom
29
+ */
30
+ function valueSetGuard(a) {
31
+ return ((0, r_value_1.isBottom)(a) || (0, r_value_1.isTop)(a)) ? undefined : a;
32
+ }
33
+ /**
34
+ * Constructs an Abstract Value from a normal TS value
35
+ * @param a - ts value
36
+ * @returns abstract value
37
+ */
38
+ function valueFromTsValue(a) {
39
+ if (a === undefined) {
40
+ return r_value_1.Bottom;
41
+ }
42
+ else if (a === null) {
43
+ return r_value_1.Top;
44
+ }
45
+ else if (typeof a === 'string') {
46
+ return (0, string_constants_1.stringFrom)(a);
47
+ }
48
+ else if (typeof a === 'number') {
49
+ return (0, interval_constants_1.intervalFrom)(a, a);
50
+ }
51
+ else if (typeof a === 'boolean') {
52
+ return a ? logical_constants_1.ValueLogicalTrue : logical_constants_1.ValueLogicalFalse;
53
+ }
54
+ return r_value_1.Top;
55
+ }
56
+ /**
57
+ * Converts a constant from an RNode into an abstract value
58
+ * @param a - RNode constant
59
+ * @returns abstract value
60
+ */
61
+ function valueFromRNodeConstant(a) {
62
+ if (a.type === type_1.RType.String) {
63
+ return (0, string_constants_1.stringFrom)(a.content.str);
64
+ }
65
+ else if (a.type === type_1.RType.Number) {
66
+ return (0, interval_constants_1.intervalFrom)(a.content.num, a.content.num);
67
+ }
68
+ else if (a.type === type_1.RType.Logical) {
69
+ return a.content.valueOf() ? logical_constants_1.ValueLogicalTrue : logical_constants_1.ValueLogicalFalse;
70
+ }
71
+ return r_value_1.Top;
72
+ }
73
+ //# sourceMappingURL=general.js.map
@@ -0,0 +1,4 @@
1
+ import type { RNumberValue } from '../../../../r-bridge/lang-4.x/convert-values';
2
+ import type { Lift, ValueInterval, ValueNumber } from '../r-value';
3
+ export declare function intervalFrom(start: RNumberValue | number, end?: number | RNumberValue, startInclusive?: boolean, endInclusive?: boolean): ValueInterval;
4
+ export declare function intervalFromValues(start: Lift<ValueNumber>, end?: Lift<ValueNumber<Lift<RNumberValue>>>, startInclusive?: boolean, endInclusive?: boolean): ValueInterval;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.intervalFrom = intervalFrom;
4
+ exports.intervalFromValues = intervalFromValues;
5
+ const r_value_1 = require("../r-value");
6
+ const scalar_consatnts_1 = require("../scalar/scalar-consatnts");
7
+ function intervalFrom(start, end = start, startInclusive = true, endInclusive = true) {
8
+ return intervalFromValues(typeof start === 'number' ? (0, scalar_consatnts_1.getScalarFromInteger)(start) : (0, scalar_consatnts_1.liftScalar)(start), typeof end === 'number' ? (0, scalar_consatnts_1.getScalarFromInteger)(end) : (0, scalar_consatnts_1.liftScalar)(end), startInclusive, endInclusive);
9
+ }
10
+ function shiftNum(v) {
11
+ if ((0, r_value_1.isBottom)(v) || (0, r_value_1.isTop)(v)) {
12
+ return (0, scalar_consatnts_1.liftScalar)(v);
13
+ }
14
+ else {
15
+ return v;
16
+ }
17
+ }
18
+ function intervalFromValues(start, end = start, startInclusive = true, endInclusive = true) {
19
+ return {
20
+ type: 'interval',
21
+ start: shiftNum(start),
22
+ end: shiftNum(end),
23
+ startInclusive,
24
+ endInclusive,
25
+ };
26
+ }
27
+ //# sourceMappingURL=interval-constants.js.map
@@ -0,0 +1,7 @@
1
+ import type { Lift, TernaryLogical, ValueLogical } from '../r-value';
2
+ export declare function liftLogical(log: Lift<TernaryLogical>): ValueLogical;
3
+ export declare const ValueLogicalTrue: ValueLogical;
4
+ export declare const ValueLogicalFalse: ValueLogical;
5
+ export declare const ValueLogicalMaybe: ValueLogical;
6
+ export declare const ValueLogicalTop: ValueLogical;
7
+ export declare const ValueLogicalBot: ValueLogical;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueLogicalBot = exports.ValueLogicalTop = exports.ValueLogicalMaybe = exports.ValueLogicalFalse = exports.ValueLogicalTrue = void 0;
4
+ exports.liftLogical = liftLogical;
5
+ const r_value_1 = require("../r-value");
6
+ function liftLogical(log) {
7
+ if (log === r_value_1.Top) {
8
+ return exports.ValueLogicalTop;
9
+ }
10
+ else if (log === r_value_1.Bottom) {
11
+ return exports.ValueLogicalBot;
12
+ }
13
+ else if (log === 'maybe') {
14
+ return exports.ValueLogicalMaybe;
15
+ }
16
+ else {
17
+ return log ? exports.ValueLogicalTrue : exports.ValueLogicalFalse;
18
+ }
19
+ }
20
+ function makeLogical(log) {
21
+ return {
22
+ type: 'logical',
23
+ value: log
24
+ };
25
+ }
26
+ exports.ValueLogicalTrue = makeLogical(true);
27
+ exports.ValueLogicalFalse = makeLogical(false);
28
+ exports.ValueLogicalMaybe = makeLogical('maybe');
29
+ exports.ValueLogicalTop = makeLogical(r_value_1.Top);
30
+ exports.ValueLogicalBot = makeLogical(r_value_1.Bottom);
31
+ //# sourceMappingURL=logical-constants.js.map
@@ -0,0 +1,58 @@
1
+ import type { RNumberValue, RStringValue } from '../../../r-bridge/lang-4.x/convert-values';
2
+ import type { RLogicalValue } from '../../../r-bridge/lang-4.x/ast/model/nodes/r-logical';
3
+ export declare const Top: {
4
+ type: symbol;
5
+ };
6
+ export declare const Bottom: {
7
+ type: symbol;
8
+ };
9
+ export type Lift<N> = N | typeof Top | typeof Bottom;
10
+ export type Unlift<N> = N extends typeof Top ? never : N extends typeof Bottom ? never : N;
11
+ export interface ValueInterval<Limit extends ValueNumber = ValueNumber> {
12
+ type: 'interval';
13
+ start: Limit;
14
+ startInclusive: boolean;
15
+ end: Limit;
16
+ endInclusive: boolean;
17
+ }
18
+ /**
19
+ * An R vector with either a known set of elements or a known domain.
20
+ */
21
+ export interface ValueVector<Elements extends Lift<unknown[]> = Lift<Value[]>, Domain extends Lift<Value> = Lift<Value>> {
22
+ type: 'vector';
23
+ elements: Elements;
24
+ /** if we do not know the amount of elements, we can still know the domain */
25
+ elementDomain: Domain;
26
+ }
27
+ /** describes the static case of we do not know which value */
28
+ export interface ValueSet<Elements extends Lift<unknown[]> = Lift<Value[]>> {
29
+ type: 'set';
30
+ elements: Elements;
31
+ }
32
+ export interface ValueNumber<Num extends Lift<RNumberValue> = Lift<RNumberValue>> {
33
+ type: 'number';
34
+ value: Num;
35
+ }
36
+ export interface ValueString<Str extends Lift<RStringValue> = Lift<RStringValue>> {
37
+ type: 'string';
38
+ value: Str;
39
+ }
40
+ export interface ValueMissing {
41
+ type: 'missing';
42
+ }
43
+ export type TernaryLogical = RLogicalValue | 'maybe';
44
+ export interface ValueLogical {
45
+ type: 'logical';
46
+ value: Lift<TernaryLogical>;
47
+ }
48
+ export type Value = Lift<ValueInterval | ValueVector | ValueSet | ValueNumber | ValueString | ValueLogical | ValueMissing>;
49
+ export type ValueType<V> = V extends {
50
+ type: infer T;
51
+ } ? T : never;
52
+ export type ValueTypes = ValueType<Value>;
53
+ export declare function typeOfValue<V extends Value>(value: V): V['type'];
54
+ export declare function isTop<V extends Lift<unknown>>(value: V): value is typeof Top;
55
+ export declare function isBottom<V extends Lift<unknown>>(value: V): value is typeof Bottom;
56
+ export declare function isValue<V extends Lift<unknown>>(value: V): value is Unlift<V>;
57
+ export declare function asValue<V extends Lift<unknown>>(value: V): Unlift<V>;
58
+ export declare function stringifyValue(value: Lift<Value>): string;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Bottom = exports.Top = void 0;
4
+ exports.typeOfValue = typeOfValue;
5
+ exports.isTop = isTop;
6
+ exports.isBottom = isBottom;
7
+ exports.isValue = isValue;
8
+ exports.asValue = asValue;
9
+ exports.stringifyValue = stringifyValue;
10
+ const assert_1 = require("../../../util/assert");
11
+ exports.Top = { type: Symbol('⊤') };
12
+ exports.Bottom = { type: Symbol('⊥') };
13
+ function typeOfValue(value) {
14
+ return value.type;
15
+ }
16
+ // @ts-expect-error -- this is a save cast
17
+ function isTop(value) {
18
+ return value === exports.Top;
19
+ }
20
+ // @ts-expect-error -- this is a save cast
21
+ function isBottom(value) {
22
+ return value === exports.Bottom;
23
+ }
24
+ function isValue(value) {
25
+ return !isTop(value) && !isBottom(value);
26
+ }
27
+ function asValue(value) {
28
+ (0, assert_1.guard)(isValue(value), 'Expected a value, but got a top or bottom value');
29
+ return value;
30
+ }
31
+ function tryStringifyBoTop(value, otherwise, onTop = () => '⊤', onBottom = () => '⊥') {
32
+ if (isTop(value)) {
33
+ return onTop();
34
+ }
35
+ else if (isBottom(value)) {
36
+ return onBottom();
37
+ }
38
+ else {
39
+ return otherwise(value);
40
+ }
41
+ }
42
+ function stringifyRNumberSuffix(value) {
43
+ let suffix = '';
44
+ if (value.markedAsInt) {
45
+ suffix += 'L';
46
+ }
47
+ if (value.complexNumber) {
48
+ suffix += 'i';
49
+ }
50
+ // do something about iL even though it is impossible?
51
+ return suffix;
52
+ }
53
+ function renderString(value) {
54
+ const quote = value.quotes;
55
+ const raw = value.flag === 'raw';
56
+ if (raw) {
57
+ return `r${quote}(${value.str})${quote}`;
58
+ }
59
+ else {
60
+ return `${quote}${JSON.stringify(value.str).slice(1, -1)}${quote}`;
61
+ }
62
+ }
63
+ function stringifyValue(value) {
64
+ return tryStringifyBoTop(value, v => {
65
+ const t = v.type;
66
+ switch (t) {
67
+ case 'interval':
68
+ return `${v.startInclusive ? '[' : '('}${stringifyValue(v.start)}, ${stringifyValue(v.end)}${v.endInclusive ? ']' : ')'}`;
69
+ case 'vector':
70
+ return tryStringifyBoTop(v.elements, e => {
71
+ return `<${stringifyValue(v.elementDomain)}> c(${e.map(stringifyValue).join(',')})`;
72
+ }, () => `⊤ (vector, ${stringifyValue(v.elementDomain)})`, () => `⊥ (vector, ${stringifyValue(v.elementDomain)})`);
73
+ case 'set':
74
+ return tryStringifyBoTop(v.elements, e => {
75
+ return e.length === 1 ? stringifyValue(e[0]) : `{ ${e.map(stringifyValue).join(',')} }`;
76
+ }, () => '⊤ (set)', () => '⊥ (set)');
77
+ case 'number':
78
+ return tryStringifyBoTop(v.value, n => `${n.num}${stringifyRNumberSuffix(n)}`, () => '⊤ (number)', () => '⊥ (number)');
79
+ case 'string':
80
+ return tryStringifyBoTop(v.value, renderString, () => '⊤ (string)', () => '⊥ (string)');
81
+ case 'logical':
82
+ return tryStringifyBoTop(v.value, l => l === 'maybe' ? 'maybe' : l ? 'TRUE' : 'FALSE', () => '⊤ (logical)', () => '⊥ (logical)');
83
+ case 'missing':
84
+ return '(missing)';
85
+ default:
86
+ (0, assert_1.assertUnreachable)(t);
87
+ }
88
+ });
89
+ }
90
+ //# sourceMappingURL=r-value.js.map
@@ -0,0 +1,15 @@
1
+ import type { Lift, ValueNumber } from '../r-value';
2
+ import type { RNumberValue } from '../../../../r-bridge/lang-4.x/convert-values';
3
+ export declare function getScalarFromInteger(num: number, markedAsInt?: boolean, complexNumber?: boolean): ValueNumber<RNumberValue>;
4
+ export declare function liftScalar(value: Lift<RNumberValue>): ValueNumber;
5
+ export declare const ValueIntegerOne: ValueNumber<RNumberValue>;
6
+ export declare const ValueNumberComplexOne: ValueNumber<RNumberValue>;
7
+ export declare const ValueIntegerZero: ValueNumber<RNumberValue>;
8
+ export declare const ValueIntegerNegativeOne: ValueNumber<RNumberValue>;
9
+ export declare const ValueIntegerPositiveInfinity: ValueNumber<RNumberValue>;
10
+ export declare const ValueNumberPositiveInfinity: ValueNumber<RNumberValue>;
11
+ export declare const ValueIntegerNegativeInfinity: ValueNumber<RNumberValue>;
12
+ export declare const ValueNumberEpsilon: ValueNumber<RNumberValue>;
13
+ export declare const ValueNumberOneHalf: ValueNumber<RNumberValue>;
14
+ export declare const ValueIntegerTop: ValueNumber<Lift<RNumberValue>>;
15
+ export declare const ValueIntegerBottom: ValueNumber<Lift<RNumberValue>>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueIntegerBottom = exports.ValueIntegerTop = exports.ValueNumberOneHalf = exports.ValueNumberEpsilon = exports.ValueIntegerNegativeInfinity = exports.ValueNumberPositiveInfinity = exports.ValueIntegerPositiveInfinity = exports.ValueIntegerNegativeOne = exports.ValueIntegerZero = exports.ValueNumberComplexOne = exports.ValueIntegerOne = void 0;
4
+ exports.getScalarFromInteger = getScalarFromInteger;
5
+ exports.liftScalar = liftScalar;
6
+ const r_value_1 = require("../r-value");
7
+ function getScalarFromInteger(num, markedAsInt = Number.isInteger(num), complexNumber = false) {
8
+ return {
9
+ type: 'number',
10
+ value: {
11
+ markedAsInt,
12
+ num,
13
+ complexNumber
14
+ }
15
+ };
16
+ }
17
+ function liftScalar(value) {
18
+ return {
19
+ type: 'number',
20
+ value: value
21
+ };
22
+ }
23
+ const epsilon = 1e-7;
24
+ exports.ValueIntegerOne = getScalarFromInteger(1);
25
+ exports.ValueNumberComplexOne = getScalarFromInteger(1, false, true);
26
+ exports.ValueIntegerZero = getScalarFromInteger(0);
27
+ exports.ValueIntegerNegativeOne = getScalarFromInteger(-1);
28
+ exports.ValueIntegerPositiveInfinity = getScalarFromInteger(Number.POSITIVE_INFINITY);
29
+ exports.ValueNumberPositiveInfinity = getScalarFromInteger(Number.POSITIVE_INFINITY, false);
30
+ exports.ValueIntegerNegativeInfinity = getScalarFromInteger(Number.NEGATIVE_INFINITY);
31
+ exports.ValueNumberEpsilon = getScalarFromInteger(epsilon, false);
32
+ exports.ValueNumberOneHalf = getScalarFromInteger(0.5, false);
33
+ exports.ValueIntegerTop = liftScalar(r_value_1.Top);
34
+ exports.ValueIntegerBottom = liftScalar(r_value_1.Bottom);
35
+ //# sourceMappingURL=scalar-consatnts.js.map
@@ -0,0 +1,7 @@
1
+ import type { Lift, Value, ValueSet } from '../r-value';
2
+ import { Top } from '../r-value';
3
+ export declare function setFrom<V extends Value[]>(...elements: V): Lift<ValueSet<Value[]>>;
4
+ export declare function isSet<V extends Value>(element: V): boolean;
5
+ export declare const ValueEmptySet: Lift<ValueSet<Value[]>>;
6
+ export declare const ValueSetTop: ValueSet<typeof Top>;
7
+ export declare const ValueSetBottom: ValueSet<typeof Top>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueSetBottom = exports.ValueSetTop = exports.ValueEmptySet = void 0;
4
+ exports.setFrom = setFrom;
5
+ exports.isSet = isSet;
6
+ const general_1 = require("../general");
7
+ const r_value_1 = require("../r-value");
8
+ function flattenSetElements(s) {
9
+ return (0, general_1.bottomTopGuard)(s) ?? s.flatMap(e => {
10
+ return e.type === 'set' ? flattenSetElements(e.elements) : e;
11
+ });
12
+ }
13
+ function setFrom(...elements) {
14
+ const vals = elements.flatMap(e => {
15
+ return e.type === 'set' ? flattenSetElements(e.elements) : e;
16
+ });
17
+ return (0, general_1.bottomTopGuard)(...vals) ?? {
18
+ type: 'set',
19
+ elements: vals
20
+ };
21
+ }
22
+ function isSet(element) {
23
+ return element.type === 'set';
24
+ }
25
+ exports.ValueEmptySet = setFrom();
26
+ exports.ValueSetTop = {
27
+ type: 'set',
28
+ elements: r_value_1.Top
29
+ };
30
+ exports.ValueSetBottom = {
31
+ type: 'set',
32
+ elements: r_value_1.Top
33
+ };
34
+ //# sourceMappingURL=set-constants.js.map
@@ -0,0 +1,8 @@
1
+ import type { RStringValue } from '../../../../r-bridge/lang-4.x/convert-values';
2
+ import type { Lift, Value, ValueString } from '../r-value';
3
+ export declare function stringFrom(str: RStringValue | string): ValueString;
4
+ export declare function liftString(str: Lift<RStringValue>): ValueString;
5
+ export declare function collectStrings(a: Value[]): string[] | undefined;
6
+ export declare const ValueEmptyString: ValueString<Lift<RStringValue>>;
7
+ export declare const ValueStringTop: ValueString<Lift<RStringValue>>;
8
+ export declare const ValueStringBot: ValueString<Lift<RStringValue>>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValueStringBot = exports.ValueStringTop = exports.ValueEmptyString = void 0;
4
+ exports.stringFrom = stringFrom;
5
+ exports.liftString = liftString;
6
+ exports.collectStrings = collectStrings;
7
+ const general_1 = require("../general");
8
+ const r_value_1 = require("../r-value");
9
+ function stringFrom(str) {
10
+ return {
11
+ type: 'string',
12
+ value: typeof str === 'string' ? {
13
+ quotes: '"',
14
+ str: str
15
+ } : str,
16
+ };
17
+ }
18
+ function liftString(str) {
19
+ return {
20
+ type: 'string',
21
+ value: str
22
+ };
23
+ }
24
+ function collectStrings(a) {
25
+ if ((0, general_1.bottomTopGuard)(a)) {
26
+ return undefined;
27
+ }
28
+ const values = [];
29
+ for (const value of a) {
30
+ if (value.type !== 'string' || !(0, r_value_1.isValue)(value) || !(0, r_value_1.isValue)(value.value)) {
31
+ return undefined;
32
+ }
33
+ values.push(value.value.str);
34
+ }
35
+ return values;
36
+ }
37
+ exports.ValueEmptyString = stringFrom('');
38
+ exports.ValueStringTop = liftString(r_value_1.Top);
39
+ exports.ValueStringBot = liftString(r_value_1.Bottom);
40
+ //# sourceMappingURL=string-constants.js.map
@@ -0,0 +1,14 @@
1
+ import type { Lift, Value, ValueVector } from '../r-value';
2
+ /**
3
+ * Creates an abstract vector from abstract values
4
+ * @param elements - elements that the vector should contain
5
+ * @returns abstract ValueVector
6
+ */
7
+ export declare function vectorFrom<V extends Lift<Value[]>>(elements: V): ValueVector<V>;
8
+ /**
9
+ * Flattens all elements inside of a vector
10
+ * A set containing only one element is also replaced by its only element
11
+ * @param s - vector to flatten
12
+ * @returns flattened vactor, if all elements are not bottom / top
13
+ */
14
+ export declare function flattenVectorElements(s: Lift<Value[]>): Lift<Value[]>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vectorFrom = vectorFrom;
4
+ exports.flattenVectorElements = flattenVectorElements;
5
+ const r_value_1 = require("../r-value");
6
+ const assert_1 = require("../../../../util/assert");
7
+ const general_1 = require("../general");
8
+ /**
9
+ * Creates an abstract vector from abstract values
10
+ * @param elements - elements that the vector should contain
11
+ * @returns abstract ValueVector
12
+ */
13
+ function vectorFrom(elements) {
14
+ (0, assert_1.guard)((0, r_value_1.isTop)(elements) || (0, r_value_1.isBottom)(elements) || Array.isArray(elements), 'Expected array of values');
15
+ return {
16
+ type: 'vector',
17
+ elements,
18
+ elementDomain: r_value_1.Top
19
+ };
20
+ }
21
+ /**
22
+ * Flattens all elements inside of a vector
23
+ * A set containing only one element is also replaced by its only element
24
+ * @param s - vector to flatten
25
+ * @returns flattened vactor, if all elements are not bottom / top
26
+ */
27
+ function flattenVectorElements(s) {
28
+ return (0, general_1.bottomTopGuard)(s) ?? s.flatMap(e => {
29
+ return e.type === 'vector' ? flattenVectorElements(e.elements) :
30
+ e.type === 'set' && (0, r_value_1.isValue)(e.elements) && e.elements.length === 1 ?
31
+ e.elements[0].type === 'vector' ? flattenVectorElements(e.elements[0].elements) : e.elements :
32
+ e;
33
+ });
34
+ }
35
+ //# sourceMappingURL=vector-constants.js.map
@@ -0,0 +1,11 @@
1
+ import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
2
+ import type { REnvironmentInformation } from '../environments/environment';
3
+ export type ReplacementOperatorHandlerArgs = {
4
+ operator: string;
5
+ target: string | undefined;
6
+ env: REnvironmentInformation;
7
+ id: NodeId;
8
+ };
9
+ export type ReplacementOperatorHandler = (args: ReplacementOperatorHandlerArgs) => void;
10
+ export declare function onReplacementOperator(handler: ReplacementOperatorHandler): void;
11
+ export declare function handleReplacementOperator(args: ReplacementOperatorHandlerArgs): void;