public static Module transformModule(Module mod) { ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(mod); LabelInfo labelInfo = new LabelInfoFromModule(mod); return ModuleTransformer.fromSentenceTransformer( new AddImplicitComputationCell(configInfo, labelInfo), "concretizing configuration").apply(mod); }
private K apply(K term) { if (labelInfo.isFunction(term)) return term; List<K> items = IncompleteCellUtils.flattenCells(term); if (items.size() != 1) { return term; } K item = items.get(0); if (isCell(item)) { return term; } else if (item instanceof KRewrite) { final KRewrite rew = (KRewrite) item; if (Stream.concat( IncompleteCellUtils.flattenCells(rew.left()).stream(), IncompleteCellUtils.flattenCells(rew.right()).stream()) .anyMatch(this::isCell)) { return term; } } KLabel computation = cfg.getCellLabel(cfg.getComputationCell()); return IncompleteCellUtils.make(computation, false, item, true); }
public Sentence apply(Sentence s) { if (s.att().contains(Attribute.MACRO_KEY) || s.att().contains(Attribute.ALIAS_KEY) || s.att().contains(Attribute.ANYWHERE_KEY)) { return s; } if (s instanceof Rule) { Rule rule = (Rule) s; return new Rule(apply(rule.body()), rule.requires(), rule.ensures(), rule.att()); } else if (s instanceof Context) { Context context = (Context) s; return new Context(apply(context.body()), context.requires(), context.att()); } else { return s; } }
public static Definition transformDefinition(Definition input) { ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(input.mainModule()); LabelInfo labelInfo = new LabelInfoFromModule(input.mainModule()); return DefinitionTransformer.fromSentenceTransformer( new AddImplicitComputationCell(configInfo, labelInfo), "concretizing configuration").apply(input); }
@Override public Function<Module, Module> specificationSteps(Definition def) { Module mod = def.mainModule(); ConfigurationInfoFromModule configInfo = new ConfigurationInfoFromModule(mod); LabelInfo labelInfo = new LabelInfoFromModule(mod); SortInfo sortInfo = SortInfo.fromModule(mod); ModuleTransformer resolveAnonVars = ModuleTransformer.fromSentenceTransformer( new ResolveAnonVar()::resolve, "resolving \"_\" vars"); ModuleTransformer resolveSemanticCasts = ModuleTransformer.fromSentenceTransformer( new ResolveSemanticCasts(true)::resolve, "resolving semantic casts"); ModuleTransformer subsortKItem = ModuleTransformer.from(Kompile::subsortKItem, "subsort all sorts to KItem"); ModuleTransformer addImplicitComputationCell = ModuleTransformer.fromSentenceTransformer( new AddImplicitComputationCell(configInfo, labelInfo), "concretizing configuration"); Function1<Module, Module> resolveFreshConstants = d -> ModuleTransformer.from(new ResolveFreshConstants(def, true)::resolve, "resolving !Var variables").apply(d); ModuleTransformer concretizeCells = ModuleTransformer.fromSentenceTransformer( new ConcretizeCells(configInfo, labelInfo, sortInfo, mod)::concretize, "concretizing configuration"); return m -> resolveAnonVars .andThen(resolveSemanticCasts) .andThen(addImplicitComputationCell) .andThen(resolveFreshConstants) .andThen(concretizeCells) .andThen(subsortKItem) .apply(m); }