@Override public int hashCode() { return k.hashCode(); }
@Override public String toString() { return k.toString(); }
public Sort getCellSort(K k) { if (k instanceof KApply) { return labels.getCodomain(((KApply) k).klabel()); } else if (k instanceof KVariable) { return k.att().get(Sort.class); } else { throw new AssertionError("expected KApply or KVariable, found " + k.getClass().getSimpleName()); } }
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(); } } }
private void filterRequired(Set<Sort> required, K item) { if (item instanceof KApply) { required.remove(labelInfo.getCodomain(((KApply) item).klabel())); } else if (item instanceof KVariable) { if (item.att().contains(Sort.class)) { Sort sort = item.att().get(Sort.class); if (cfg.cfg.isCell(sort)) { required.remove(sort); } else { required.clear(); } } else { required.clear(); } } } }
private KLabel computePolyKLabel(KApply k) { List<Set<Integer>> poly = polyKLabels.get(k.klabel().name()); List<Sort> params = new ArrayList<>(); for (Set<Integer> positions : poly) { int pos = positions.iterator().next(); Sort sort; if (pos == 0) { sort = k.att().get(Sort.class); } else { sort = k.items().get(pos-1).att().get(Sort.class); } params.add(sort); } return KLabel(k.klabel().name(), immutable(params)); }
@Override public V put(K key, V value) { if (key == null) { throw new NullPointerException("key == null"); } // my edit here if(find(key, false) != null) { throw new IllegalArgumentException("'" + key.toString() + "' is duplicate key for json!"); } Node<K, V> created = find(key, true); V result = created.value; created.value = value; return result; }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + _0.hashCode(); result = 31 * result + _1.hashCode(); result = 31 * result + _2.hashCode(); result = 31 * result + _3.hashCode(); result = 31 * result + _4.hashCode(); result = 31 * result + _5.hashCode(); return result; } }
public synchronized String toString() { int max = size() - 1; if (max == -1) return "{}"; StringBuilder sb = new StringBuilder(); Iterator<Map.Entry<K,V>> it = entrySet().iterator(); sb.append('{'); for (int i = 0; ; i++) { Map.Entry<K,V> e = it.next(); K key = e.getKey(); V value = e.getValue(); sb.append(key == this ? "(this Map)" : key.toString()); sb.append('='); sb.append(value == this ? "(this Map)" : value.toString()); if (i == max) return sb.append('}').toString(); sb.append(", "); } }
@Override public void apply(KSequence k) { for (int i = 0; i < k.items().size(); i++) { K item = k.items().get(i); boolean isList = item.att().get(Sort.class).equals(Sorts.K()); if (i == k.items().size() - 1) { if (isList) { apply(item); } else { sb.append("kseq{}("); apply(item); sb.append(",dotk{}())"); } } else { if (item.att().get(Sort.class).equals(Sorts.K())) { sb.append("append{}("); } else { sb.append("kseq{}("); } apply(item); sb.append(","); } } if (k.items().size() == 0) { sb.append("dotk{}()"); } for (int i = 0; i < k.items().size() - 1; i++) { sb.append(")"); } }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + _0.hashCode(); result = 31 * result + _1.hashCode(); result = 31 * result + _2.hashCode(); result = 31 * result + _3.hashCode(); result = 31 * result + _4.hashCode(); result = 31 * result + _5.hashCode(); result = 31 * result + _6.hashCode(); result = 31 * result + _7.hashCode(); result = 31 * result + _8.hashCode(); return result; } }
K topOfKCell = seq.items().get(0); if (topOfKCell instanceof KVariable) { Optional<Sort> sortAtt = topOfKCell.att().getOptional(Sort.class); if (sortAtt.isPresent()) { Sort sort = sortAtt.get();
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + _0.hashCode(); result = 31 * result + _1.hashCode(); result = 31 * result + _2.hashCode(); result = 31 * result + _3.hashCode(); result = 31 * result + _4.hashCode(); result = 31 * result + _5.hashCode(); result = 31 * result + _6.hashCode(); return result; } }
public Term convert(org.kframework.kore.K k) { if (k instanceof Term) return (Term) k; else if (k instanceof org.kframework.kore.KToken) return KToken(((org.kframework.kore.KToken) k).s(), ((org.kframework.kore.KToken) k).sort(), k.att()); else if (k instanceof org.kframework.kore.KApply) { return KApply1(((KApply) k).klabel(), ((KApply) k).klist(), k.att()); } else if (k instanceof org.kframework.kore.KSequence) return KSequence(((org.kframework.kore.KSequence) k).items(), k.att()); else if (k instanceof org.kframework.kore.KVariable) return KVariable(((org.kframework.kore.KVariable) k).name(), k.att()); else if (k instanceof org.kframework.kore.InjectedKLabel) return InjectedKLabel(((org.kframework.kore.InjectedKLabel) k).klabel(), k.att()); else if (k instanceof org.kframework.kore.KRewrite) { return KItem.of(KLabelConstant.of(KLabels.KREWRITE, definition), KList.concatenate(convert(((KRewrite) k).left()), convert(((KRewrite) k).right())), global); } else throw new AssertionError("BUM!"); }
private Set<Sort> sort(K k, Rule r) { if (k instanceof KVariable) { return Collections.singleton(k.att().get(Sort.class)); } else if (k instanceof KToken) { return Collections.singleton(((KToken)k).sort()); } else if (k instanceof KApply) { KApply kapp = (KApply)k; if (kapp.klabel() instanceof KVariable) { throw KEMException.compilerError("Cannot compute macros with klabel variables.", r); } Set<Production> prods = new HashSet<>(mutable(mod.productionsFor().apply(kapp.klabel()))); prods.removeIf(p -> p.arity() != kapp.items().size()); for (int i = 0; i < kapp.items().size(); i++) { final int idx = i; Set<Sort> sorts = sort(kapp.items().get(idx), r); prods.removeIf(p -> sorts.stream().noneMatch(s -> mod.subsorts().lessThanEq(s, p.nonterminal(idx).sort()))); } Set<Sort> candidates = prods.stream().map(Production::sort).collect(Collectors.toSet()); return candidates; } else { throw KEMException.compilerError("Cannot compute macros with sort check on terms that are not KApply, KToken, or KVariable.", r); } }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + _0.hashCode(); result = 31 * result + _1.hashCode(); result = 31 * result + _2.hashCode(); result = 31 * result + _3.hashCode(); result = 31 * result + _4.hashCode(); result = 31 * result + _5.hashCode(); result = 31 * result + _6.hashCode(); result = 31 * result + _7.hashCode(); return result; } }
Sort sort = k.att().get(Sort.class); return Optional.of(cfg.getParent(sort)); } else {