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: