public K resolveK(K k) { resetVars();; gatherVars(k); return transform(k); }
@Override public K apply(KVariable k) { if (ANON_VAR.equals(k)) { return newDotVariable(); } return super.apply(k); } }.apply(term);
public Rule compileRule(Definition compiledDef, Rule parsedRule) { return (Rule) UnaryOperator.<Sentence>identity() .andThen(new ResolveAnonVar()::resolve) .andThen(new ResolveSemanticCasts(kompileOptions.backend.equals(Backends.JAVA))::resolve) .andThen(s -> concretizeSentence(s, compiledDef)) .apply(parsedRule); }
private Rule funRule(KLabel fun, K k, Att att) { K resolved = transform(k); K withAnonVars = new ResolveAnonVar().resolveK(resolved); List<K> klist = new ArrayList<>(); klist.add(RewriteToTop.toLeft(withAnonVars)); klist.addAll(closure(k)); return Rule(KRewrite(KApply(fun, KList(klist)), RewriteToTop.toRight(withAnonVars)), BooleanUtils.TRUE, BooleanUtils.TRUE, att); }
public static Function<Definition, Definition> defaultSteps(KompileOptions kompileOptions, KExceptionManager kem, FileUtil files) { DefinitionTransformer resolveStrict = DefinitionTransformer.from(new ResolveStrict(kompileOptions)::resolve, "resolving strict and seqstrict attributes"); DefinitionTransformer resolveHeatCoolAttribute = DefinitionTransformer.fromSentenceTransformer(new ResolveHeatCoolAttribute(new HashSet<>(kompileOptions.transition), EnumSet.of(HEAT_RESULT, COOL_RESULT_CONDITION, COOL_RESULT_INJECTION))::resolve, "resolving heat and cool attributes"); DefinitionTransformer resolveAnonVars = DefinitionTransformer.fromSentenceTransformer(new ResolveAnonVar()::resolve, "resolving \"_\" vars"); DefinitionTransformer resolveSemanticCasts = DefinitionTransformer.fromSentenceTransformer(new ResolveSemanticCasts(kompileOptions.backend.equals(Backends.JAVA))::resolve, "resolving semantic casts");
private Rule resolve(Rule rule) { resetVars(); gatherVars(rule.body()); gatherVars(rule.requires()); gatherVars(rule.ensures()); return new Rule( transform(rule.body()), transform(rule.requires()), transform(rule.ensures()), rule.att()); }
@Override public Function<Module, Module> specificationSteps(Definition def) { BiFunction<Module, K, K> convertCellCollections = (Module m, K k) -> new ConvertDataStructureToLookup(m, false).convert(k); return m -> ModuleTransformer.fromSentenceTransformer(new ResolveAnonVar()::resolve, "resolve anonymous varaibles") .andThen(ModuleTransformer.fromSentenceTransformer(s -> new ResolveSemanticCasts(kompileOptions.backend.equals(Backends.JAVA)).resolve(s), "resolve semantic casts")) .andThen(AddImplicitComputationCell::transformModule) .andThen(ConcretizeCells::transformModule) .andThen(ModuleTransformer.fromRuleBodyTransformer(RewriteToTop::bubbleRewriteToTopInsideCells, "bubble out rewrites below cells")) .andThen(AddBottomSortForListsWithIdenticalLabels.singleton()) .andThen(ModuleTransformer.fromSentenceTransformer((mod, s) -> new ExpandMacros(mod, files, kompileOptions, false).expand(s), "expand macros")) .andThen(ModuleTransformer.fromKTransformerWithModuleInfo(convertCellCollections::apply, "convert cell to the underlying collections")) .andThen(ModuleTransformer.fromRuleBodyTransformer(JavaBackend::ADTKVariableToSortedVariable, "ADT.KVariable to SortedVariable")) .andThen(ModuleTransformer.fromRuleBodyTransformer(JavaBackend::convertKSeqToKApply, "kseq to kapply")) .andThen(ModuleTransformer.fromRuleBodyTransformer(NormalizeKSeq.self(), "normalize kseq")) .andThen(mod -> JavaBackend.markRegularRules(def, mod)) .andThen(ModuleTransformer.fromSentenceTransformer(new AddConfigurationRecoveryFlags()::apply, "add refers_THIS_CONFIGURATION_marker")) .apply(m); }
private Context resolve(Context context) { resetVars(); gatherVars(context.body()); gatherVars(context.requires()); return new Context( transform(context.body()), transform(context.requires()), context.att()); }
@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); }
DefinitionTransformer resolveStrict = DefinitionTransformer.from(new ResolveStrict(kompileOptions)::resolve, "resolving strict and seqstrict attributes"); DefinitionTransformer resolveHeatCoolAttribute = DefinitionTransformer.fromSentenceTransformer(new ResolveHeatCoolAttribute(new HashSet<>(kompileOptions.transition), heatCoolConditions)::resolve, "resolving heat and cool attributes"); DefinitionTransformer resolveAnonVars = DefinitionTransformer.fromSentenceTransformer(new ResolveAnonVar()::resolve, "resolving \"_\" vars"); DefinitionTransformer resolveSemanticCasts = DefinitionTransformer.fromSentenceTransformer(new ResolveSemanticCasts(true)::resolve, "resolving semantic casts");