private boolean hasCells(KApply k) { for (int i = 0; i < k.klist().size(); i++) { K item = k.klist().items().get(i); if (item instanceof KApply && ((KApply) item).klabel().name().equals("#cells")) { return true; } } return false; }
private void checkVarLabelPatterns(Term subject, BitSet ruleMask, scala.collection.immutable.List<Pair<Integer, Integer>> path, RuleAutomatonDisjunction automatonDisjunction, BitSet returnSet) { List<Pair<KItem, BitSet>> varLabelPatterns = automatonDisjunction.getKItemPatternByArity(((KItem) subject).klist().size()); if (!(varLabelPatterns == null)) { for (Pair<KItem, BitSet> p : varLabelPatterns) { matchInside(subject, ruleMask, path, returnSet, p); } } }
private boolean isCellFragmentTest(KApply app) { if (app.klist().size() != 1) return false; K argument = app.klist().items().get(0); if (!(argument instanceof KVariable)) return false; VarInfo info = variables.get((KVariable)argument); if (info == null) return false; KLabel expectedPredicate = KLabel("is"+cfg.getCellSort(info.parentCell).toString()+"Fragment"); return app.klabel().equals(expectedPredicate); }
private void choose(KApply k, String choiceString, String afterElse) { if (k.klist().items().size() != 2) { throw KEMException.internalError("Unexpected arity of choice: " + k.klist().size(), k);
KItem item = ((KItem) p.getLeft()); if (item.kLabel() instanceof Variable) { Integer arity = new Integer(item.klist().size()); if (!varKItemDisjunctionsMap.containsKey(arity)) { varKItemDisjunctionsMap.put(arity, new ArrayList<>());
@Override public void apply(KApply k) { if (k.klabel().name().equals("#cells")) { for (int i = 0; i < k.klist().size(); i++) { K item = k.klist().items().get(i); if (item instanceof KVariable) { KVariable var = (KVariable) item; if (var.att().contains(Sort.class)) { Sort sort = var.att().get(Sort.class); if (!cfg.cfg.isCell(sort)) { if (!cellFragmentVars.containsKey(var)) { cellFragmentVars.put(var, new HashSet<>()); } cellFragmentVars.get(var).add(k); } } else { if (!cellFragmentVars.containsKey(var)) { cellFragmentVars.put(var, new HashSet<>()); } cellFragmentVars.get(var).add(k); } } } } else { super.apply(k); } } }.apply(term);
private boolean isHOLE(K k) { if (k instanceof KApply) { KApply kapp = (KApply) k; return kapp.klabel().name().startsWith("#SemanticCastTo") && kapp.klist().size() == 1 && isHOLEVar(kapp.klist().items().get(0)); } else { return isHOLEVar(k); } }
private void chooseStep(KApply k, String choiceString, String afterElse) { if (k.klist().items().size() != 2) { throw KEMException.internalError("Unexpected arity of choice: " + k.klist().size(), k);
private String wellformedAndGetSortNameOfCast(KList klist) { try { if (klist.size() == 3) { KApply k1 = (KApply) klist.items().get(0); KApply k3 = (KApply) klist.items().get(2); if (KLabels.NO_DOTS.equals(k1.klabel()) && k1.klist().size() == 0 && KLabels.DOTS.equals(k3.klabel()) && k3.klist().size() == 0) { KRewrite k2 = (KRewrite) klist.items().get(1); KApply k2l = (KApply) k2.left(); KApply k2r = (KApply) k2.right(); if (k2l.klabel().name().equals("ListItem") && k2l.klist().size() == 1 && k2r.klabel().name().equals(".List") && k2r.klist().size() == 0) { KApply k2li = (KApply) k2l.klist().items().get(0); if (k2li.klabel().name().startsWith("#SemanticCastTo") && k2li.klist().size() == 1 && k2li.klist().items().get(0) instanceof KVariable) { return ResolveSemanticCasts.getSortNameOfCast(k2li); // k2li.klabel().name().substring("#SemanticCastTo".length()); } } } } } catch (ClassCastException ignored) { } return ""; } }.apply(rule.body());
.reduce(BooleanUtils.TRUE, BooleanUtils::and); } else if(k.klabel().name().equals("isBag") && k.klist().size() == 1 && k.klist().items().get(0) instanceof KVariable) { KVariable var = (KVariable)k.klist().items().get(0);
@Override public K apply(KApply k0) { if (hasCells(k0)) { ArrayList<K> klist0 = new ArrayList<K>(Collections.nCopies(k0.klist().size(), null)); for (int idx = 0; idx < k0.klist().size(); idx++) { K item0 = k0.klist().items().get(idx); klist0.set(idx, item0); if (item0 instanceof KApply) { KApply k = (KApply) item0; if (k.klabel().name().equals("#cells")) { if (cellFragmentVarsCell.contains(k)) { Sort cellFragmentSort = nthArgSort(k0.klabel(), idx); if (cellFragmentSort == null) { throw new IllegalArgumentException("Not found " + idx + "th argument sort of " + k0.klabel()); } if (cellFragmentSort.name().endsWith("Fragment")) { Sort cellSort = Sort(cellFragmentSort.name().substring(0,cellFragmentSort.name().indexOf("Fragment"))); KLabel cellLabel = cfg.cfg.getCellLabel(cellSort); klist0.set(idx, KApply(cellLabel, KList(item0), Att().add("dummy_cell"))); } } } } } return KApply(k0.klabel(), KList(klist0), k0.att()); } return super.apply(k0); } @Override
topAnywherePre = false; if (k.klabel() instanceof KVariable) { sb.append("KApply").append(k.klist().size()).append("("); apply(k.klabel()); sb.append(","); sb.append(")"); } else { if (k.klist().size() == 0 && rhs) { sb.append("KApply").append(k.klist().size()).append("("); apply(k.klabel()); if (k.klist().size() > 0) { sb.append(","); applyTuple(k.klist().items());
knode.add("arity", app.klist().size()); knode.add("args", args.build());
@Override public K apply(KApply k) { if (isLookupKLabel(k.klabel())) { assert k.klist().size() == 2; K r = apply(k.klist().items().get(1)); lhs = true; K l = apply(k.klist().items().get(0)); lhs = false; if (l != k.klist().items().get(0) || r != k.klist().items().get(1)) { return KApply(k.klabel(), l, r); } else { return k; } } return super.apply(k); }
private static Att getCellPropertiesAsAtt(K k) { if (k instanceof KApply) { KApply kapp = (KApply) k; if (kapp.klabel().name().equals("#cellPropertyListTerminator")) { return Att(); } else if (kapp.klabel().name().equals("#cellPropertyList")) { if (kapp.klist().size() == 2) { Tuple2<String, String> attribute = getCellProperty(kapp.klist().items().get(0)); return Att().add(attribute._1(), attribute._2()).addAll(getCellPropertiesAsAtt(kapp.klist().items().get(1))); } } } throw KEMException.compilerError("Malformed cell properties", k); }
if (kapp.klabel().equals(KLabel(m.attributesFor().apply(collectionLabel).get("element"))) || (needsWrapper = kapp.klabel().equals(getWrapElement(collectionLabel)))) { if (kapp.klist().size() != 2 && !needsWrapper) { throw KEMException.internalError("Unexpected arity of map element: " + kapp.klist().size(), kapp);
private static Tuple2<String, String> getCellProperty(K k) { if (k instanceof KApply) { KApply kapp = (KApply) k; if (kapp.klabel().name().equals("#cellProperty")) { if (kapp.klist().size() == 2) { if (kapp.klist().items().get(0) instanceof KToken) { KToken keyToken = (KToken) kapp.klist().items().get(0); if (keyToken.sort().equals(Sort("#CellName"))) { String key = keyToken.s(); if (kapp.klist().items().get(0) instanceof KToken) { KToken valueToken = (KToken) kapp.klist().items().get(1); if (valueToken.sort().equals(Sorts.KString())) { String value = StringUtil.unquoteKString(valueToken.s()); return Tuple2.apply(key, value); } } } } } } } throw KEMException.compilerError("Malformed cell property", k); }
@Override public K apply(KApply k) { if (k.klabel().name().equals("#SemanticCastToString") && k.klist().size() == 1) { K i = k.klist().items().get(0); if (i instanceof KVariable) { KVariable x = (KVariable) i; switch (x.name()) { case "?Sort": return KToken("\"" + sort + "\"", Sorts.String()); case "?Delimiters": // TODO(Daejun): support `delimiter` attribute in stream cell return KToken("\" \\n\\t\\r\"", Sorts.String()); default: // fall through } } } k = (KApply) super.apply(k); return KApply(apply(k.klabel()), k.klist(), k.att()); }
if (k.klist().size() == 1 && k.klist().items().get(0) instanceof InjectedKLabel) { InjectedKLabel injection = (InjectedKLabel) k.klist().items().get(0); if (injection.klabel() instanceof KVariable) {