@cobol-ts/size 0.0.3 → 0.0.5
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.
- package/dist/index.js.map +1 -0
- package/dist/src/size.expression.grammer.d.ts +78 -0
- package/dist/src/size.expression.grammer.js +7 -0
- package/dist/src/size.expression.grammer.js.map +1 -0
- package/dist/src/storage.size.expression.canonicalise.d.ts +10 -0
- package/dist/src/storage.size.expression.canonicalise.js +114 -0
- package/dist/src/storage.size.expression.canonicalise.js.map +1 -0
- package/dist/src/storage.size.expression.canonicalise.spec.d.ts +1 -0
- package/dist/src/storage.size.expression.canonicalise.spec.js +759 -0
- package/dist/src/storage.size.expression.canonicalise.spec.js.map +1 -0
- package/dist/src/storage.size.expression.evaluate.d.ts +7 -0
- package/dist/src/storage.size.expression.evaluate.js +114 -0
- package/dist/src/storage.size.expression.evaluate.js.map +1 -0
- package/dist/src/storage.size.expression.evaluator.spec.d.ts +1 -0
- package/dist/src/storage.size.expression.evaluator.spec.js +913 -0
- package/dist/src/storage.size.expression.evaluator.spec.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yEAAsD;AACtD,gEAA6C;AAC7C,6EAA0D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Symbolic COBOL storage sizes, measured in bits.
|
|
3
|
+
*
|
|
4
|
+
* A variable refers to an enclosing indexed repetition by relative depth:
|
|
5
|
+
* depth 0 is the innermost enclosing repetition; depth 1 is its parent.
|
|
6
|
+
* Variable depths in paths are validated when metadata is built.
|
|
7
|
+
*/
|
|
8
|
+
export type StorageSizeExpression = ConstantSizeExpression | SumSizeExpression | OccursSizeExpression | MaxSizeExpression | DependingOnSizeExpression | AlignSizeExpression | DifferenceSizeExpression;
|
|
9
|
+
/**
|
|
10
|
+
* A symbolic count-field path:
|
|
11
|
+
* - string: a literal COBOL field name;
|
|
12
|
+
* - number: relative depth of an enclosing OCCURS repetition
|
|
13
|
+
* (0 = nearest, 1 = its parent, and so on).
|
|
14
|
+
*
|
|
15
|
+
* Unlike ResolvedPath, numbers here are NOT literal array indices.
|
|
16
|
+
*/
|
|
17
|
+
export type DependsOnPathItem = string | number;
|
|
18
|
+
export type DependsOnPath = readonly DependsOnPathItem[];
|
|
19
|
+
/** Fixed non-negative storage size in bits. */
|
|
20
|
+
export type ConstantSizeExpression = number;
|
|
21
|
+
export declare function isConstantSizeExpression(value: unknown): value is ConstantSizeExpression;
|
|
22
|
+
/** Adjacent fields occupy the sum of their sizes. */
|
|
23
|
+
export interface SumSizeExpression {
|
|
24
|
+
readonly kind: "sum";
|
|
25
|
+
readonly terms: readonly StorageSizeExpression[];
|
|
26
|
+
}
|
|
27
|
+
/** Fixed OCCURS: sum the size of each occurrence with its index bound. */
|
|
28
|
+
export interface OccursSizeExpression {
|
|
29
|
+
readonly kind: "occurs";
|
|
30
|
+
readonly count: number;
|
|
31
|
+
readonly expression: StorageSizeExpression;
|
|
32
|
+
}
|
|
33
|
+
/** REDEFINES storage is the maximum size of its alternative views. */
|
|
34
|
+
export interface MaxSizeExpression {
|
|
35
|
+
readonly kind: "max";
|
|
36
|
+
readonly terms: readonly StorageSizeExpression[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* OCCURS DEPENDING ON: read count at path, then evaluate expression once
|
|
40
|
+
* for every occurrence and sum the sizes. The expression is an implicit lambda:
|
|
41
|
+
* its current zero-based occurrence index is pushed onto the variable stack.
|
|
42
|
+
* The path itself is resolved before this new index is pushed.
|
|
43
|
+
*/
|
|
44
|
+
export interface DependingOnSizeExpression {
|
|
45
|
+
readonly kind: "depending-on";
|
|
46
|
+
readonly path: DependsOnPath;
|
|
47
|
+
readonly expression: StorageSizeExpression;
|
|
48
|
+
/** Declared count bounds, when available from a copybook. */
|
|
49
|
+
readonly min?: number;
|
|
50
|
+
readonly max?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Additional storage required to align a position or extent to a boundary.
|
|
54
|
+
*
|
|
55
|
+
* Both size and boundary are measured in bits. The boundary must be a
|
|
56
|
+
* positive integer.
|
|
57
|
+
*
|
|
58
|
+
* Evaluates to:
|
|
59
|
+
*
|
|
60
|
+
* (boundary - (size % boundary)) % boundary
|
|
61
|
+
*
|
|
62
|
+
* The result is zero when size is already aligned.
|
|
63
|
+
*
|
|
64
|
+
* When size is symbolic, alignment is evaluated using its resolved value.
|
|
65
|
+
* This allows padding after variable-length OCCURS DEPENDING ON tables
|
|
66
|
+
* to depend on the actual occurrence count.
|
|
67
|
+
*/
|
|
68
|
+
export interface AlignSizeExpression {
|
|
69
|
+
readonly kind: "align";
|
|
70
|
+
readonly size: StorageSizeExpression;
|
|
71
|
+
readonly boundary: number;
|
|
72
|
+
}
|
|
73
|
+
/** Nonnegative distance between two storage extents (left >= right). */
|
|
74
|
+
export interface DifferenceSizeExpression {
|
|
75
|
+
readonly kind: "difference";
|
|
76
|
+
readonly left: StorageSizeExpression;
|
|
77
|
+
readonly right: StorageSizeExpression;
|
|
78
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isConstantSizeExpression = isConstantSizeExpression;
|
|
4
|
+
function isConstantSizeExpression(value) {
|
|
5
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=size.expression.grammer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.expression.grammer.js","sourceRoot":"","sources":["../../src/size.expression.grammer.ts"],"names":[],"mappings":";;AAgCA,4DAIC;AAJD,SAAgB,wBAAwB,CACpC,KAAc;IAEd,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StorageSizeExpression } from "./size.expression.grammer";
|
|
2
|
+
/**
|
|
3
|
+
* Simplify a symbolic storage-size expression without consulting a record.
|
|
4
|
+
* Does not mutate the input. Expressions are assumed to have been validated.
|
|
5
|
+
*
|
|
6
|
+
* An OCCURS binds an occurrence index. Do not remove that binding unless
|
|
7
|
+
* the entire repeated expression is a constant: relative numeric references
|
|
8
|
+
* in nested DEPENDING ON paths would otherwise change meaning.
|
|
9
|
+
*/
|
|
10
|
+
export declare function canonicaliseStorageSize(expression: StorageSizeExpression): StorageSizeExpression;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicaliseStorageSize = canonicaliseStorageSize;
|
|
4
|
+
/**
|
|
5
|
+
* Simplify a symbolic storage-size expression without consulting a record.
|
|
6
|
+
* Does not mutate the input. Expressions are assumed to have been validated.
|
|
7
|
+
*
|
|
8
|
+
* An OCCURS binds an occurrence index. Do not remove that binding unless
|
|
9
|
+
* the entire repeated expression is a constant: relative numeric references
|
|
10
|
+
* in nested DEPENDING ON paths would otherwise change meaning.
|
|
11
|
+
*/
|
|
12
|
+
function canonicaliseStorageSize(expression) {
|
|
13
|
+
if (typeof expression === "number") {
|
|
14
|
+
return expression;
|
|
15
|
+
}
|
|
16
|
+
switch (expression.kind) {
|
|
17
|
+
case "sum": {
|
|
18
|
+
const terms = [];
|
|
19
|
+
let constant = 0;
|
|
20
|
+
for (const term of expression.terms) {
|
|
21
|
+
const simplified = canonicaliseStorageSize(term);
|
|
22
|
+
const members = typeof simplified !== "number" && simplified.kind === "sum"
|
|
23
|
+
? simplified.terms
|
|
24
|
+
: [simplified];
|
|
25
|
+
for (const member of members) {
|
|
26
|
+
if (typeof member === "number") {
|
|
27
|
+
constant += member;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
terms.push(member);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (constant !== 0)
|
|
35
|
+
terms.push(constant);
|
|
36
|
+
if (terms.length === 0)
|
|
37
|
+
return 0;
|
|
38
|
+
if (terms.length === 1)
|
|
39
|
+
return terms[0];
|
|
40
|
+
return { kind: "sum", terms };
|
|
41
|
+
}
|
|
42
|
+
case "max": {
|
|
43
|
+
const terms = [];
|
|
44
|
+
let constant = 0;
|
|
45
|
+
for (const term of expression.terms) {
|
|
46
|
+
const simplified = canonicaliseStorageSize(term);
|
|
47
|
+
const members = typeof simplified !== "number" && simplified.kind === "max"
|
|
48
|
+
? simplified.terms
|
|
49
|
+
: [simplified];
|
|
50
|
+
for (const member of members) {
|
|
51
|
+
if (typeof member === "number") {
|
|
52
|
+
constant = Math.max(constant, member);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
terms.push(member);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (terms.length === 0)
|
|
60
|
+
return constant;
|
|
61
|
+
if (constant !== 0)
|
|
62
|
+
terms.push(constant);
|
|
63
|
+
if (terms.length === 1)
|
|
64
|
+
return terms[0];
|
|
65
|
+
return { kind: "max", terms };
|
|
66
|
+
}
|
|
67
|
+
case "occurs": {
|
|
68
|
+
if (expression.count === 0)
|
|
69
|
+
return 0;
|
|
70
|
+
const child = canonicaliseStorageSize(expression.expression);
|
|
71
|
+
if (typeof child === "number") {
|
|
72
|
+
return expression.count * child;
|
|
73
|
+
}
|
|
74
|
+
// The body may use this occurrence's index. Never rewrite
|
|
75
|
+
// OCCURS(1, body) to body without rebasing relative depths.
|
|
76
|
+
return { kind: "occurs", count: expression.count, expression: child };
|
|
77
|
+
}
|
|
78
|
+
case "depending-on": {
|
|
79
|
+
const child = canonicaliseStorageSize(expression.expression);
|
|
80
|
+
// Zero-sized occurrences still require resolving the count for
|
|
81
|
+
// full evaluation semantics; leave the dependent node in place.
|
|
82
|
+
return {
|
|
83
|
+
kind: "depending-on",
|
|
84
|
+
path: expression.path,
|
|
85
|
+
expression: child,
|
|
86
|
+
...(expression.min === undefined ? {} : { min: expression.min }),
|
|
87
|
+
...(expression.max === undefined ? {} : { max: expression.max }),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
case "difference": {
|
|
91
|
+
const left = canonicaliseStorageSize(expression.left);
|
|
92
|
+
const right = canonicaliseStorageSize(expression.right);
|
|
93
|
+
if (left === right || JSON.stringify(left) === JSON.stringify(right))
|
|
94
|
+
return 0;
|
|
95
|
+
if (right === 0)
|
|
96
|
+
return left;
|
|
97
|
+
if (typeof left === "number" && typeof right === "number") {
|
|
98
|
+
if (right > left)
|
|
99
|
+
throw new Error("Negative storage-size difference");
|
|
100
|
+
return left - right;
|
|
101
|
+
}
|
|
102
|
+
return { kind: "difference", left, right };
|
|
103
|
+
}
|
|
104
|
+
case "align": {
|
|
105
|
+
const size = canonicaliseStorageSize(expression.size);
|
|
106
|
+
const boundary = expression.boundary;
|
|
107
|
+
if (typeof size === "number") {
|
|
108
|
+
return (boundary - size % boundary) % boundary;
|
|
109
|
+
}
|
|
110
|
+
return { kind: "align", size, boundary };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=storage.size.expression.canonicalise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.size.expression.canonicalise.js","sourceRoot":"","sources":["../../src/storage.size.expression.canonicalise.ts"],"names":[],"mappings":";;AAWA,0DAmGC;AA3GD;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CACnC,UAAiC;IAEjC,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,UAAU,CAAC;IACtB,CAAC;IAED,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,KAAK,CAAC,CAAC,CAAC;YACT,M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