private static void flattenKSequence( List<org.kframework.kil.Term> flatList, List<org.kframework.kil.Term> nestedList) { for (org.kframework.kil.Term term : nestedList) { if (term instanceof org.kframework.kil.KSequence) { org.kframework.kil.KSequence kSequence = (org.kframework.kil.KSequence) term; KILtoBackendJavaKILTransformer.flattenKSequence(flatList, kSequence.getContents()); } else { flatList.add(term); } } }
@Override public ASTNode transform(org.kframework.kil.KSequence node) throws TransformerException { List<org.kframework.kil.Term> list = new ArrayList<org.kframework.kil.Term>(); KILtoBackendJavaKILTransformer.flattenKSequence(list, node.getContents()); Variable variable = null; if (!list.isEmpty() && list.get(list.size() - 1) instanceof org.kframework.kil.Variable && list.get(list.size() - 1).getSort().equals(org.kframework.kil.KSorts.K)) { variable = (Variable) list.remove(list.size() - 1).accept(this); } ImmutableList.Builder<Term> builder = new ImmutableList.Builder<Term>(); for (org.kframework.kil.Term term : list) { builder.add((Term) term.accept(this)); } return new KSequence(builder.build(), variable); }
@Override public ASTNode visit(org.kframework.kil.KSequence node, Void _void) { List<org.kframework.kil.Term> list = new ArrayList<>(); KILtoBackendJavaKILTransformer.flattenKSequence(list, node.getContents()); Variable variable = null; if (!list.isEmpty() && list.get(list.size() - 1) instanceof org.kframework.kil.Variable && list.get(list.size() - 1).getSort().equals(org.kframework.kil.Sort.K)) { variable = (Variable) this.visitNode(list.remove(list.size() - 1)); } KSequence.Builder builder = KSequence.builder(); for (org.kframework.kil.Term term : list) { builder.concatenate((Term) this.visitNode(term)); } if (variable != null) { builder.concatenate(variable); } return builder.build(); }