public static String getSortOfVar(KVariable k, VarInfo vars) { if (vars.vars.containsKey(k)) { String varName = vars.vars.get(k).iterator().next(); if (vars.listVars.containsKey(varName)) { return vars.listVars.get(varName).name(); } } if (k.att().contains("cellSort")) { return Sorts.K().toString(); } return k.att().getOptional(Sort.class).orElse(Sorts.K()).toString(); }
static boolean hasPolySort(TermCons tc) { if (!tc.production().att().contains("poly")) return false; List<Set<Integer>> positions = RuleGrammarGenerator.computePositions(tc.production()); return positions.stream().anyMatch(s -> s.contains(0)); }
@Override public K apply(KVariable k) { if (varToTypedVar.containsKey(k)) { return varToTypedVar.get(k); } return super.apply(k); } }.apply(term);
private Rule getExitCodeRule(Definition parsedDefinition) { Module mainMod = parsedDefinition.mainModule(); Set<Production> exitProds = stream(mainMod.productions()).filter(p -> p.att().contains("exit")).collect(Collectors.toSet()); if (exitProds.size() == 0) { return null; } else if (exitProds.size() > 1) { throw KEMException.compilerError("Found more than one or zero productions with 'exit' attribute. Exactly one production, a cell, must have this attribute, designating the exit code of krun. Found:\n" + exitProds); } Production exitProd = exitProds.iterator().next(); return Rule(IncompleteCellUtils.make(exitProd.klabel().get(), false, KApply(KLabel("#SemanticCastToInt"), KVariable("_")), false), BooleanUtils.TRUE, BooleanUtils.TRUE); }
private boolean isFunction(Production prod) { Production realProd = prod.att().get("originalPrd", Production.class); if (!realProd.att().contains(Attribute.FUNCTION_KEY)) { return false; } return true; }
public Module resolve(Module input) { Set<Sentence> contextsToAdd = resolve(stream(input.localSentences()) .filter(s -> s instanceof Production) .map(s -> (Production) s) .filter(p -> p.att().contains("strict") || p.att().contains("seqstrict")).collect(Collectors.toSet())); return Module(input.name(), input.imports(), (scala.collection.Set<Sentence>) input.localSentences().$bar(immutable(contextsToAdd)), input.att()); } }
@Override public void apply(KVariable k) { if (k.att().contains("denormal")) { normalization.put(KVariable(k.att().get("denormal")), k.name()); } } }.apply(normal);
public WrapLabelRule(Production label) { assert label != null; this.label = label; this.isToken = label.att().contains("token"); this.needsLabel = label.klabel().isDefined() || !label.isSyntacticSubsort(); } protected Term apply(KList klist, MetaData metaData) {
private String getVarName(KVariable var) { if (var.att().contains("denormal")) { return var.att().get("denormal"); } return var.name(); }
@Override public Term apply(TermCons tc) { if (tc.production().att().contains("bracket") || tc.production().klabel().get().name().equals("#SyntacticCast") || tc.production().klabel().get().name().equals("#InnerCast") || tc.production().klabel().get().name().equals("#OuterCast")) { return apply(tc.get(0)); } return super.apply(tc); } }
@Override public Optional<KApply> apply(KApply k) { if (k.klabel() instanceof KVariable) { return super.apply(k); } if (m.attributesFor().apply(k.klabel()).contains("thread")) { return Optional.of(k); } return super.apply(k); }
public static K flattenTerm(Module mod, KApply kapp) { List<K> items = new ArrayList<>(); Att att = mod.attributesFor().apply(KLabel(kapp.klabel().name())); if (att.contains("assoc") && att.contains("unit")) { items = Assoc.flatten(kapp.klabel(), kapp.klist().items(), KLabel(att.get("unit"))); } else { items = kapp.klist().items(); } return KApply(kapp.klabel(), KList(items), kapp.att()); }
private Rule resolve(Rule rule) { resetCasts(); gatherCasts(rule.body()); gatherCasts(rule.requires()); gatherCasts(rule.ensures()); return new Rule( transform(rule.body()), addSideCondition(transform(rule.requires()), rule.att().contains("macro") || rule.att().contains("alias")), transform(rule.ensures()), rule.att()); }
private boolean isConstructorLike(KLabel klabel) { String labelName = klabel.name(); if (isInjectionLabel(labelName) || isBuiltinModuloConstructor(klabel)) return true; Set<Production> productionSet = module.productionsFor().apply(klabel); assert productionSet.size() == 1 : "Should not have more than one production"; Production production = productionSet.head(); return !production.att().contains(Att.Function()); }