public String getAttr(String attribute) { return productionAttributes.getOptional(attribute).orElse(null); }
private Att addKoreAttributes(Production prod, SetMultimap<KLabel, Rule> functionRules, Set<KLabel> impurities, Set<Production> overloads) { boolean isConstructor = !isFunction(prod); boolean isFunctional = !isFunction(prod); if (prod.att().contains(Attribute.ASSOCIATIVE_KEY) || prod.att().contains(Attribute.COMMUTATIVE_KEY) || prod.att().contains(Attribute.IDEMPOTENT_KEY) || (prod.att().contains(Attribute.FUNCTION_KEY) && prod.att().contains(Attribute.UNIT_KEY))) { isConstructor = false; if (r.att().contains(Attribute.ANYWHERE_KEY)) { isConstructor = false; isAnywhere = true; Att att = prod.att().remove("constructor"); if (att.contains(Attribute.HOOK_KEY) && att.get(Attribute.HOOK_KEY).startsWith("ARRAY.")) { att = att.remove("hook"); att = att.add("constructor"); att = att.add("functional"); att = att.add("anywhere");
public static java.util.List<UserList> getLists(Set<Sentence> sentences) { Map<Boolean, List<Sentence>> separatedProds = sentences.stream().collect(Collectors.groupingBy(p -> p instanceof Production && p.att().contains(Att.userList()))); Map<Sort, java.util.List<Sentence>> listsMap = separatedProds.getOrDefault(true, new LinkedList<>()) .stream().collect(Collectors.groupingBy(s -> ((Production) s).sort())); ul.separator = t.value(); ul.klabel = p.klabel().get(); ul.attrs = p.att().remove("klabel"); ul.nonEmpty = ul.attrs.get(Att.userList()).equals("+"); ul.childSort = ((NonTerminal) p.items().head()).sort(); ul.pList = p;
if (cellProperties.contains("maincell")) { assert isLeaf; assert childSorts.size() == 1; Att att = cellProperties.addAll(configAtt); StringBuilder format = new StringBuilder(); format.append("%1%i"); att = att.add("format", format.toString()); Rule initializerRule; if (hasConfigurationOrRegularVariable || isStream) { initializer = Production(KLabel(initLabel), sort, Seq(Terminal(initLabel), Terminal("("), NonTerminal(Sorts.Map()), Terminal(")")), Att().add("initializer").add("function").add("noThread")); initializerRule = Rule(KRewrite(KApply(KLabel(initLabel), INIT), IncompleteCellUtils.make(KLabel("<" + cellName + ">"), false, childInitializer, false)), BooleanUtils.TRUE, ensures == null ? BooleanUtils.TRUE : ensures, Att().add("initializer")); } else { initializer = Production(KLabel(initLabel), sort, Seq(Terminal(initLabel)), Att().add("initializer").add("function").add("noThread")); initializerRule = Rule(KRewrite(KApply(KLabel(initLabel)), IncompleteCellUtils.make(KLabel("<" + cellName + ">"), false, childInitializer, false)), BooleanUtils.TRUE, ensures == null ? BooleanUtils.TRUE : ensures, Att().add("initializer")); if (!m.definedKLabels().contains(KLabel("no"+childSort.toString()))) { sentences.add(Production(KLabel("no"+childSort.toString()), childOptSort, List(Terminal("no"+childSort.toString())), Att().add(Attribute.CELL_OPT_ABSENT_KEY,Sort.class,childSort))); if (!m.definedKLabels().contains(KLabel("<" + cellName + ">-fragment"))) { sentences.add(Production(KLabel("<" + cellName + ">-fragment"), fragmentSort, immutable(fragmentItems), Att().add(Attribute.CELL_FRAGMENT_KEY, Sort.class, Sort(sortName)))); String type = cellProperties.<String>getOptional("type").orElse("Bag"); Sort bagSort = Sort(sortName + type); Att bagAtt = Att()
private Stream<? extends K> performParse(Map<String, ParsedSentence> cache, ParseInModule parser, Scanner scanner, Bubble b) { int startLine = b.att().get("contentStartLine", Integer.class); int startColumn = b.att().get("contentStartColumn", Integer.class); Source source = b.att().get(Source.class); Tuple2<Either<java.util.Set<ParseFailedException>, K>, java.util.Set<ParseFailedException>> result; if (cache.containsKey(b.contents())) { ParsedSentence parse = cache.get(b.contents()); Optional<Source> cacheSource = parse.getParse().source(); //Cache might contain content from an identical file but another source path. //The content will have wrong Source attribute and must be invalidated. if (cacheSource.isPresent() && cacheSource.get().equals(source)) { cachedBubbles.getAndIncrement(); kem.addAllKException(parse.getWarnings().stream().map(e -> e.getKException()).collect(Collectors.toList())); return Stream.of(parse.getParse()); } } result = parser.parseString(b.contents(), START_SYMBOL, scanner, source, startLine, startColumn, !b.att().contains("macro") && !b.att().contains("alias")); parsedBubbles.getAndIncrement(); kem.addAllKException(result._2().stream().map(e -> e.getKException()).collect(Collectors.toList())); if (result._1().isRight()) { KApply k = (KApply) new TreeNodesToKORE(Outer::parseSort, isStrict).down(result._1().right().get()); k = KApply(k.klabel(), k.klist(), k.att().addAll(b.att().remove("contentStartLine").remove("contentStartColumn").remove(Source.class).remove(Location.class))); cache.put(b.contents(), new ParsedSentence(k, new HashSet<>(result._2()))); return Stream.of(k); } else { errors.addAll(result._1().left().get()); return Stream.empty(); } } }
if (p.att().contains("poly")) { List<Set<Integer>> positions = computePositions(p); if (!p.isSyntacticSubsort()) { prods.add(Production(p.klabel(), returnSort, immutable(pis), p.att().add(Constants.ORIGINAL_PRD, Production.class, p))); addRuleCells = mod.sentences().exists(p -> p instanceof Production && ((Production) p).att().contains("cell")); } else { addRuleCells = false; ConfigurationInfo cfgInfo = new ConfigurationInfoFromModule(mod); parseProds = Stream.concat(prods.stream(), stream(mod.sentences())).flatMap(s -> { if (s instanceof Production && s.att().contains("cellCollection")) { return Stream.empty(); if (s instanceof Production && (s.att().contains("cell"))) { Production p = (Production) s; if (s instanceof Production && (s.att().contains("cellFragment", Sort.class))) { Production p = (Production) s; Production p1 = Production(Sorts.Cell(), Seq(NonTerminal(p.sort()))); parseProds = Stream.concat(prods.stream(), stream(mod.sentences()).filter(s -> !s.att().contains("cell"))).collect(Collectors.toSet()); } else parseProds = Stream.concat(prods.stream(), stream(mod.sentences())).collect(Collectors.toSet()); Att newAtts = ul.attrs.remove("userList"); newAtts.remove("format").add(Constants.ORIGINAL_PRD, Production.class, ul.pTerminator));
public static List<Set<Integer>> computePositions(Production p) { return (List<Set<Integer>>) Arrays.asList(p.att().get("poly").split(";")) .stream().map(l -> Arrays.asList(l.split(",")).stream() .map(s -> Integer.valueOf(s.trim())).collect(Collectors.toSet())).collect(Collectors.toList()); }
@Override public K apply(K k) { if (isRHS() && !isLHS()) { if (cache.containsKey(k)) { return cache.get(k); } } if (isLHS() && !isRHS()) { if (usedOnRhs.contains(k)) { return KAs(super.apply(k), cache.get(k), Att.empty().add(Sort.class, cache.get(k).att().get(Sort.class))); } } return super.apply(k); } }.apply(term);
KVariable newDotVariable(Sort s) { KVariable newLabel; do { if (s == null) { newLabel = KVariable("DotVar" + (counter++), Att().add("anonymous")); } else { newLabel = KVariable("DotVar" + (counter++), Att().add("anonymous").add(Sort.class, s)); } } while (vars.contains(newLabel)); vars.add(newLabel); return newLabel; }
public Constructor(ConstructorType type, int size1, int size2, int size3, Kind kind, org.kframework.kore.Sort cellCollectionSort) { this(type, size1, size2, size3, kind, cellCollectionSort, null, null, null, Att.empty()); }
public void applyUserList(Set<org.kframework.definition.Sentence> res, org.kframework.kore.Sort sort, Production p, UserList userList) { // Transform list declarations of the form Es ::= List{E, ","} into something representable in kore org.kframework.kore.Sort elementSort = userList.getSort(); org.kframework.attributes.Att attrs = convertAttributes(p).add(Att.userList(), userList.getListType()); String kilProductionId = "" + System.identityHashCode(p); Att attrsWithKilProductionId = attrs.add(PRODUCTION_ID, kilProductionId); org.kframework.definition.Production prod1, prod3; // Es ::= E "," Es prod1 = Production(KLabel(p.getKLabel(kore)), sort, Seq(NonTerminal(elementSort), Terminal(userList.getSeparator()), NonTerminal(sort)), attrsWithKilProductionId.add("right")); // Es ::= ".Es" prod3 = Production(KLabel(p.getTerminatorKLabel(kore)), sort, Seq(Terminal("." + sort.toString())), attrsWithKilProductionId.remove("format").remove("strict").add("klabel", p.getTerminatorKLabel(false))); res.add(prod1); res.add(prod3); }
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(); }
public K apply(KVariable var) { if (var.name(). equals("HOLE") && transitions.stream().noneMatch(att::contains)) { return KVariable(var.name(), var.att().add(Sort.class, Outer.parseSort(att.getOptional("result").orElse("KResult")))); } return super.apply(var); } }.apply(body);