Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/language_status/cobolrt_api.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schema": "cobolrt-api/1",
"about": ["The cobolrt public API (#4718). Written by tests/tools/cobolrt_api.py generate: edit only a `visibility`, to public or internal; docs/cobolrt_api_contract.md says what they promise.", "`evidence` records who called the item when it was last refreshed, and is never checked: det-port, model-port (committed ports), frozen-overlay (a frozen runtime copy's call to a live class), generated (translator output), emitter (a translator string), emitter-dynamic (a name a computed emission may take), runtime, harness; empty: no caller was found."],
"summary": {"types": 143, "types_public": 112, "members": 1319, "members_public": 863, "members_internal": 456},
"summary": {"types": 143, "types_public": 112, "members": 1321, "members_public": 864, "members_internal": 457},
"types": [
{"id": "batch.CobolAbend", "kind": "class", "source": "gitgalaxy/tools/cobol_to_java/cobol_to_java_batch_forge.py", "variants": ["forge-batch-jobs", "forge-batch-files"], "supers": ["RuntimeException"], "visibility": "public", "evidence": ["det-port", "emitter", "model-port", "signature", "harness", "runtime"], "members": [
{"id": "batch.CobolAbend.<init>(String,String)", "kind": "constructor", "visibility": "internal", "evidence": []},
Expand Down Expand Up @@ -56,10 +56,11 @@
{"id": "batch.Dd.status()", "kind": "method", "returns": "String", "visibility": "public", "evidence": ["emitter-dynamic", "harness", "runtime"]}
]},
{"id": "batch.JclConditions", "kind": "class", "source": "gitgalaxy/tools/cobol_to_java/cobol_to_java_batch_forge.py", "variants": ["forge-batch-jobs", "forge-batch-files"], "supers": [], "visibility": "public", "evidence": ["emitter", "harness", "runtime"], "members": [
{"id": "batch.JclConditions.bypass(String,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["emitter", "harness", "runtime"]},
{"id": "batch.JclConditions.holds(String,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["emitter", "harness", "runtime"]},
{"id": "batch.JclConditions.holds(String,Map,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["emitter", "harness", "runtime"]},
{"id": "batch.JclConditions.startsAfterAbend(String,String,String,Map,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["emitter", "harness", "runtime"]}
{"id": "batch.JclConditions.bypass(String,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["harness", "runtime"]},
{"id": "batch.JclConditions.bypassed(String,String,String,String[][],Map,Map,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["emitter", "harness", "runtime"]},
{"id": "batch.JclConditions.holds(String,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["harness", "runtime"]},
{"id": "batch.JclConditions.holds(String,Map,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["harness", "runtime"]},
{"id": "batch.JclConditions.startsAfterAbend(String,String,String,Map,Map)", "kind": "method", "static": true, "returns": "boolean", "visibility": "public", "evidence": ["runtime"]}
]},
{"id": "batch.JclJobLauncher", "kind": "class", "source": "gitgalaxy/tools/cobol_to_java/cobol_to_java_batch_forge.py", "variants": ["forge-batch-jobs"], "supers": [], "visibility": "public", "evidence": ["harness"], "members": [
{"id": "batch.JclJobLauncher.<init>(JobLauncher,List)", "kind": "constructor", "visibility": "internal", "evidence": []},
Expand All @@ -75,6 +76,7 @@
{"id": "batch.JclSteps.idcams(String,String,String,String,String,List,String)", "kind": "method", "returns": "Tasklet", "visibility": "internal", "evidence": ["harness"]},
{"id": "batch.JclSteps.idcams(String,String,String,String,String,List,String,String)", "kind": "method", "returns": "Tasklet", "visibility": "internal", "evidence": ["harness", "runtime"]},
{"id": "batch.JclSteps.iefbr14(String,String,String,String,String,List)", "kind": "method", "returns": "Tasklet", "visibility": "public", "evidence": ["harness"]},
{"id": "batch.JclSteps.ifChain(String,String,String[][])", "kind": "method", "returns": "void", "visibility": "internal", "evidence": []},
{"id": "batch.JclSteps.program(String,String,String,String,String,IntSupplier)", "kind": "method", "returns": "Tasklet", "visibility": "public", "evidence": ["harness"]},
{"id": "batch.JclSteps.utility(String,String,String,String,String,String,String)", "kind": "method", "returns": "Tasklet", "visibility": "public", "evidence": ["harness"]}
]},
Expand Down
7 changes: 6 additions & 1 deletion gitgalaxy/core/fact_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ def _file_control_select(cursor, has_table, has_column):
line_number INTEGER,
disp_normal TEXT,
sysout TEXT,
if_chain TEXT,
FOREIGN KEY(file_id) REFERENCES file_data(id) ON DELETE CASCADE
)
"""
Expand Down Expand Up @@ -828,6 +829,7 @@ def col(probe, *names):
col("sysout", "sysout"),
col("restart", "restart", "restart_checkid", "rd", "parm_overrides", "cond_overrides"),
col("output_params", "output_params", "output_refs"),
col("if_chain", "if_chain"),
)
)
return (
Expand Down Expand Up @@ -2221,6 +2223,7 @@ def _transaction_select(_cursor, _has_table, _has_column):
("sysout TEXT",),
("restart TEXT", "restart_checkid TEXT", "rd TEXT", "parm_overrides TEXT", "cond_overrides TEXT"),
("output_params TEXT", "output_refs TEXT"),
("if_chain TEXT",), # #8886
),
indexes=(
"CREATE INDEX IF NOT EXISTS idx_job_flow_file_id ON job_flow_data(file_id);",
Expand Down Expand Up @@ -2259,6 +2262,7 @@ def _transaction_select(_cursor, _has_table, _has_column):
"cond_overrides",
"output_params",
"output_refs",
"if_chain",
),
to_row=lambda j: (
j.get("kind"),
Expand Down Expand Up @@ -2291,6 +2295,7 @@ def _transaction_select(_cursor, _has_table, _has_column):
json.dumps(j["cond_overrides"]) if j.get("cond_overrides") else None,
json.dumps(j["output_params"]) if j.get("output_params") else None,
json.dumps(j["output_refs"]) if j.get("output_refs") else None,
json.dumps(j["if_chain"]) if j.get("if_chain") else None, # #8886
),
restore_select=_job_flow_select,
to_payload=lambda r: {
Expand All @@ -2316,7 +2321,7 @@ def _transaction_select(_cursor, _has_table, _has_column):
},
**{
k: json.loads(r[k])
for k in ("parm_overrides", "cond_overrides", "output_params", "output_refs")
for k in ("parm_overrides", "cond_overrides", "output_params", "output_refs", "if_chain")
if r[k]
},
**{k: r[k] for k in ("restart", "restart_checkid", "rd") if r[k]},
Expand Down
8 changes: 7 additions & 1 deletion gitgalaxy/tools/cobol_to_cobol/galaxy_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ class EngineJobFlow:
instream: str | None = None # #4268: an INSTREAM row's SYSIN / SYMNAMES / SORTCNTL / DFSPARM body, as written
lrecl: int | None = None # #4268: the record length a DD row states (DCB / LRECL=), None when not stated
recfm: str | None = None # #4268: the record format a DD row states (FB / VB / ...), None when not stated
# #8886: a STEP row's enclosing IF constructs, outermost first: [line of the IF, its condition, in its ELSE clause]
if_chain: list | None = None


@dataclass
Expand Down Expand Up @@ -4522,6 +4524,7 @@ def job_steps(self) -> list:
"line": r.line,
"parm": r.parm, # #3624
"runner_programs": self.runner_runs(r, f.file_path), # #3710
**({"if_chain": r.if_chain} if r.if_chain else {}), # #8886: presence-keyed
}
if r.proc:
where, inner = self._proc_steps(f, r.proc)
Expand All @@ -4534,6 +4537,7 @@ def job_steps(self) -> list:
"if_cond": s_.if_cond,
"parm": s_.parm,
"runner_programs": self.runner_runs(s_, where or f.file_path),
**({"if_chain": s_.if_chain} if s_.if_chain else {}),
}
for s_ in inner
]
Expand Down Expand Up @@ -6994,9 +6998,10 @@ def load_galaxy_ir(db_path: Path, repo_name: str | None = None) -> GalaxyIR:
parm_col = "parm" if _has_column(cur, "job_flow_data", "parm") else "NULL" # #3624
instream_col = "instream" if _has_column(cur, "job_flow_data", "instream") else "NULL" # #4268
dcb_cols = "lrecl, recfm" if _has_column(cur, "job_flow_data", "lrecl") else "NULL, NULL" # #4268
chain_col = "if_chain" if _has_column(cur, "job_flow_data", "if_chain") else "NULL" # #8886
for row in cur.execute(
"SELECT file_id, kind, job_name, step_ordinal, step_name, program, proc_name, cond, if_cond, in_proc, " # noqa: S608 -- normal_col / runner_cols are literals
f"dd_name, dsn, disp, generation, line_number, {normal_col}, {runner_cols}, {parm_col}, {instream_col}, {dcb_cols} FROM job_flow_data "
f"dd_name, dsn, disp, generation, line_number, {normal_col}, {runner_cols}, {parm_col}, {instream_col}, {dcb_cols}, {chain_col} FROM job_flow_data "
"WHERE repo_name = ? AND commit_hash = ? ORDER BY file_id, line_number, id",
(repo_name, commit_hash),
):
Expand Down Expand Up @@ -7025,6 +7030,7 @@ def load_galaxy_ir(db_path: Path, repo_name: str | None = None) -> GalaxyIR:
instream=row[20],
lrecl=int(row[21]) if row[21] else None,
recfm=row[22],
if_chain=json.loads(row[23]) if row[23] else None,
)
)
# #3455: file definitions. A pre-#3455 database has neither table.
Expand Down
85 changes: 76 additions & 9 deletions gitgalaxy/tools/cobol_to_java/cobol_to_java_batch_forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class Step:
sort_service: str = "" # #4268: the class of its det translation (a service the step runs), "" until ported
sort_java: str = "" # that service's source
concat: int = 0 # a SORT whose SORTIN is a concatenation: its datasets (the k-th, k > 1, is the DD `SORTIN<k>`)
if_chain: list[list] = field(
default_factory=list
) # #8886: [IF line key, condition, in its ELSE clause], outermost first
not_ported: str = "" # why the lowered program is not run (the det translation failed or holds holes)
lowered_note: str = "" # where its record length came from
# #8886: the lowered SORT builds fewer bytes (OUTREC) than its SORTOUT's fixed LRECL: IBM ends it, RC=16
Expand Down Expand Up @@ -205,6 +208,7 @@ def _plan(self, j: dict, dds: dict) -> Job:
dds.get((j["file"], s["ordinal"], ps["step"] if inner is not None else None), []),
self.programs.get(prog or "")) # fmt: skip
st.parm = ps.get("parm")
st.if_chain = self._if_chain(s, ps, inner is not None)
if prog in COPY:
st.refused = self._iebgener_refusal(j["file"], s["ordinal"], st)
elif prog in IDCAMS:
Expand Down Expand Up @@ -619,6 +623,11 @@ def _job_source(self, j: Job) -> str:
bean = j.cls[0].lower() + j.cls[1 : -len("Config")] # unique, as the class is
java += [" @Bean", f" public Job {bean}({', '.join(params)}) {{",
f" return new JobBuilder({_jstr(j.spring)}, jobRepository)", " .listener(steps.abends())"] # fmt: skip
for st in j.steps:
if st.if_chain: # #8886: the IF constructs of the step, by job and step (JclConditions.bypassed)
rows = ", ".join("{" + ", ".join(_jstr(c if isinstance(c, str) else str(c).lower()) for c in r) + "}"
for r in st.if_chain) # fmt: skip
java.append(f" steps.ifChain({_jstr(j.spring)}, {_jstr(st.jcl)}, new String[][] {{{rows}}});")
for i, st in enumerate(j.steps):
verb = ".start" if i == 0 else ".next"
java.append(f" {verb}(new StepBuilder({_jstr(st.name)}, jobRepository)")
Expand Down Expand Up @@ -697,6 +706,18 @@ def _step_todo(self, st: Step) -> str | None:
return f"TODO: {st.jcl} runs the utility {p} through {st.runner} ({st.via}) -- a utility step to port"
return f"TODO: {st.jcl} runs the utility {p} (its control statements are in SYSIN) -- a utility step to port"

@staticmethod
def _if_chain(call: dict, ps: dict, in_proc: bool) -> list[list]:
"""#8886: the IF constructs a step sits in, outermost first. IBM fixes a construct's result when it is first
evaluated (Example 9), so each carries its IF statement's line as the key; a procedure's own IF is keyed by the
call (each call evaluates its own)."""
chain = [[str(line), expr, bool(in_else)] for line, expr, in_else in call.get("if_chain") or []]
if in_proc:
chain += [
[f"{call['step']}.{line}", expr, bool(in_else)] for line, expr, in_else in ps.get("if_chain") or []
]
return chain

def _tasklet(self, j: Job, st: Step) -> str:
consts = f"DDS_{self._const(st.name)}"
head = f"{_jstr(st.name)}, {_jstr(st.jcl)}, {_jstr(j.cond)}, {_jstr(st.cond)}, {_jstr(st.if_cond)}"
Expand Down Expand Up @@ -1313,17 +1334,58 @@ def audit_line(self) -> str:
*/
public static boolean startsAfterAbend(String jobCond, String cond, String ifCond, Map<String, Integer> rcs,
Map<String, String> abends) {
String upper = cond == null ? "" : cond.toUpperCase(Locale.ROOT);
boolean inIf = ifCond != null && !ifCond.isBlank();
if (inIf && (!NAMES_ABEND.matcher(ifCond.toUpperCase(Locale.ROOT)).find() || !holds(ifCond, rcs, abends))) {
return false;
}
return liftsAbendDefault(jobCond, cond, inIf, rcs);
}

/**
* Whether a step the abend default would bypass starts: EVEN / ONLY or an IF lifts it, and the step's JOB COND
* and COND tests still decide.
*/
private static boolean liftsAbendDefault(String jobCond, String cond, boolean inIf, Map<String, Integer> rcs) {
String upper = cond == null ? "" : cond.toUpperCase(Locale.ROOT);
if (!(EVEN.matcher(upper).find() || ONLY.matcher(upper).find()) && !inIf) {
return false;
}
return !(jobCond != null && testsHold(jobCond.toUpperCase(Locale.ROOT), rcs)) && !testsHold(upper, rcs);
}

/**
* Whether a step is bypassed. `chain` (null: the flat `ifCond`) holds the IF constructs the step sits in, outermost
* first, {line of the IF, its condition, "true" in its ELSE clause}: IBM fixes a construct's result when it is first
* evaluated and does not re-evaluate it for its later steps (JCL Reference, IF/THEN/ELSE Example 9), so `frozen`
* (IF line -> result, kept per job) holds the results. jcl_flow's `_starts` is the engine's twin.
*/
public static boolean bypassed(String jobCond, String cond, String ifCond, String[][] chain,
Map<String, Integer> rcs, Map<String, String> abends, Map<String, Boolean> frozen) {
if (chain == null || chain.length == 0) {
return !abends.isEmpty() ? !startsAfterAbend(jobCond, cond, ifCond, rcs, abends)
: bypass(jobCond, rcs) || bypass(cond, rcs) || !holds(ifCond, rcs);
}
StringBuilder names = new StringBuilder();
for (String[] c : chain) {
names.append(c[1]).append(' ');
}
for (String[] c : chain) {
Boolean done = frozen.get(c[0]);
if (done == null) {
if (!abends.isEmpty() && !NAMES_ABEND.matcher(names.toString().toUpperCase(Locale.ROOT)).find()) {
return true;
}
done = holds(c[1], rcs, abends);
frozen.put(c[0], done);
}
if (done == Boolean.parseBoolean(c[2])) {
return true;
}
}
return abends.isEmpty() ? bypass(jobCond, rcs) || bypass(cond, rcs)
: !liftsAbendDefault(jobCond, cond, true, rcs);
}

static boolean compare(int left, String op, int right) {
return switch (op) {
case "GT", ">" -> left > right;
Expand Down Expand Up @@ -1469,10 +1531,10 @@ def audit_line(self) -> str:
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
//{IDCAMS_IMPORT}
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.ToIntFunction;
import __BASE__.cobolrt.job.Idcams;
//{/IDCAMS_IMPORT}
Expand Down Expand Up @@ -1500,6 +1562,7 @@ def audit_line(self) -> str:
private static final Logger LOG = LoggerFactory.getLogger(JclSteps.class);
private final DatasetResolver datasets;
private final boolean skipUnimplemented;
private final Map<String, String[][]> ifChains = new ConcurrentHashMap<>();
//{IDCAMS_IMPORT}
private final Map<Long, Map<String, Idcams.Entry>> catalogs = new ConcurrentHashMap<>();
//{/IDCAMS_IMPORT}
Expand All @@ -1510,6 +1573,11 @@ def audit_line(self) -> str:
this.skipUnimplemented = skipUnimplemented;
}

/** The IF constructs a step sits in, outermost first: {line of the IF, its condition, "true" in its ELSE clause}. */
public void ifChain(String job, String jcl, String[][] chain) {
ifChains.put(job + "/" + jcl, chain);
}

/** A step running a program of the estate: its service's runBatch, whose result is RETURN-CODE. */
public Tasklet program(String name, String jcl, String jobCond, String cond, String ifCond, IntSupplier run) {
return guarded(jcl, jobCond, cond, ifCond, run);
Expand Down Expand Up @@ -1727,13 +1795,12 @@ def audit_line(self) -> str:
Map<String, Integer> rcs = new LinkedHashMap<>((Map<String, Integer>) ctx.get("jcl.rc", Map.class, Map.of()));
Map<String, String> abends = new LinkedHashMap<>(
(Map<String, String>) ctx.get("jcl.abend", Map.class, Map.of()));
if (!abends.isEmpty()) { // an earlier step abended: IBM bypasses this one unless EVEN / ONLY / IF ABEND says so
if (!JclConditions.startsAfterAbend(jobCond, cond, ifCond, rcs, abends)) {
contribution.setExitStatus(new ExitStatus("BYPASSED"));
return RepeatStatus.FINISHED;
}
} else if (JclConditions.bypass(jobCond, rcs) || JclConditions.bypass(cond, rcs)
|| !JclConditions.holds(ifCond, rcs)) {
Map<String, Boolean> frozen = new LinkedHashMap<>(
(Map<String, Boolean>) ctx.get("jcl.if", Map.class, Map.of()));
String[][] chain = ifChains.get(chunk.getStepContext().getJobName() + "/" + jcl);
boolean bypassed = JclConditions.bypassed(jobCond, cond, ifCond, chain, rcs, abends, frozen);
ctx.put("jcl.if", frozen); // an IF construct's result stays fixed for the rest of the job (IBM Example 9)
if (bypassed) { // COND / IF; after an abend IBM bypasses unless EVEN / ONLY / IF ABEND says so
contribution.setExitStatus(new ExitStatus("BYPASSED"));
return RepeatStatus.FINISHED;
}
Expand Down
Loading
Loading