From 56c897bb9e5c367efb20d88cfdd14f7b6d47a098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Thu, 28 Dec 2023 18:19:44 +0300 Subject: [PATCH] d --- .../platform/2/generation/pipeBusSource.py | 26 +++++++++++++++++++ Utilities/platform/2/generation/pipeSource.py | 7 +---- .../2/generation/sectionGeneratedPipes.py | 8 +++++- 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 Utilities/platform/2/generation/pipeBusSource.py diff --git a/Utilities/platform/2/generation/pipeBusSource.py b/Utilities/platform/2/generation/pipeBusSource.py new file mode 100644 index 0000000..fb6dab8 --- /dev/null +++ b/Utilities/platform/2/generation/pipeBusSource.py @@ -0,0 +1,26 @@ +from generation.isNotKeyword import * + +def pipeSource(name, entity, structure, fmtBusPipe, fmtBusPipeToggle): + props = entity.pipes[name] + if "vm" in props: + return "core.vm." + name + elif "$vm" in props: + return "core.vm.$" + name + else: + # Если это что-то неизвестное заранее, то ищем строку, + # отличную от известных ключевых слов для инструкции pipe. + default = "world" + src = next(filter(isNotKeyword, props), default) + # Прямое обращение к VM. + if src.startswith("vm."): + src = "core." + src + # Обращение к константе шины. + elif src.startswith("K."): + src = pipeSourceBus( + busKey = src + busValueType = structure.model.fields[name][0] + src = "Bus.events.compactMap { Bus.convertKeyValue(" + busKey + ", $0) }.map { (k: String, v: " + busValueType + ") in v }" + # Значение по умолчанию. + elif src == default: + return default + "." + name + return src diff --git a/Utilities/platform/2/generation/pipeSource.py b/Utilities/platform/2/generation/pipeSource.py index 251eb89..33374a1 100644 --- a/Utilities/platform/2/generation/pipeSource.py +++ b/Utilities/platform/2/generation/pipeSource.py @@ -1,6 +1,6 @@ from generation.isNotKeyword import * -def pipeSource(name, entity, structure): +def pipeSource(name, entity): props = entity.pipes[name] if "vm" in props: return "core.vm." + name @@ -14,11 +14,6 @@ def pipeSource(name, entity, structure): # Прямое обращение к VM. if src.startswith("vm."): src = "core." + src - # Обращение к константе шины. - elif src.startswith("K."): - busKey = src - busValueType = structure.model.fields[name][0] - src = "Bus.events.compactMap { Bus.convertKeyValue(" + busKey + ", $0) }.map { (k: String, v: " + busValueType + ") in v }" # Значение по умолчанию. elif src == default: return default + "." + name diff --git a/Utilities/platform/2/generation/sectionGeneratedPipes.py b/Utilities/platform/2/generation/sectionGeneratedPipes.py index 2cec0ba..7b82b4a 100644 --- a/Utilities/platform/2/generation/sectionGeneratedPipes.py +++ b/Utilities/platform/2/generation/sectionGeneratedPipes.py @@ -1,8 +1,11 @@ from generation.shortenName import * +from generation.pipeBusSource import * from generation.pipeFormat import * from generation.pipeSource import * def sectionGeneratedPipes(entity, sub, c): + fmtBusPipe = c.readFile(f"{c.dir}/templates/section-generated-bus-pipe") + fmtBusPipeToggle = c.readFile(f"{c.dir}/templates/section-generated-bus-pipe-toggle") fmtExRecent = c.readFile(f"{c.dir}/templates/section-generated-pipe-ex-recent") fmtRecent = c.readFile(f"{c.dir}/templates/section-generated-pipe-recent") fmtSet = c.readFile(f"{c.dir}/templates/section-generated-pipe-set") @@ -26,7 +29,10 @@ def sectionGeneratedPipes(entity, sub, c): shortSrc = shortenName(key) # SRC. - src = pipeSource(key, entity, c.structure) + src = pipeSource(key, entity) + # Bus. + if src.startswith("K."): + src = pipeBusSource(key, c.structure, fmtBusPipe, fmtBusPipeToggle) fmtPipe = pipeFormat(fmtExRecent, fmtRecent, fmtSet, fmtToggle, fmtToggleNil, key, entity) for fmt in fmtPipe: