@Override
 public ASTNode transform(org.kframework.kil.Variable node) throws TransformerException {
   if (node.getSort().equals("Bag"))
     return new Variable(node.getName(), Kind.CELL_COLLECTION.toString());
   DataStructureSort dataStructureSort = context.dataStructureSortOf(node.getSort());
   if (dataStructureSort != null) {
     if (dataStructureSort.type().equals(org.kframework.kil.KSorts.LIST))
       return new Variable(node.getName(), KSorts.LIST);
     if (dataStructureSort.type().equals(org.kframework.kil.KSorts.MAP))
       return new Variable(node.getName(), KSorts.MAP);
     if (dataStructureSort.type().equals(org.kframework.kil.KSorts.SET))
       return new Variable(node.getName(), KSorts.SET);
   }
   return new Variable(node.getName(), node.getSort());
 }
Exemplo n.º 2
0
 @Override
 public Void visit(Bag b, Void _) {
     boolean allCells = true;
     for (Term t : b.getContents()) {
         if (t instanceof Cell
             || t instanceof TermComment) {
             continue;
         } else if (t instanceof Variable) {
             Variable v = (Variable)t;
             if (v.getSort().equals("Bag")) {
                 continue;
             }
         } else if (t instanceof Bracket) {
             Bracket r = (Bracket)t;
             if (r.getContent() instanceof Rewrite
                 && r.getContent().getSort().equals("Bag")) {
                 continue;
             }
         }
         allCells = false;
         break;
     }
     if (allCells) {
         for (Term t : b.getContents()) {
             this.visitNode(t);
         }
     } else {
         assert false;
     }
     return null;
 }
Exemplo n.º 3
0
 @Override
 public Void visit(Variable v, Void _) {
     builder.append(v.getName());
     if (v.isUserTyped()) {
         builder.append(':');
         builder.append(v.getSort());
     }
     return null;
 }
Exemplo n.º 4
0
 @Override
 public Void visit(KApp app, Void _) {
     if (app.getLabel() instanceof Token) {
         assert ((KList)app.getChild()).isEmpty();
         this.visitNode(app.getLabel());
     } else {
         printLabel(app.getLabel());
         Term child = app.getChild();
         builder.append('(');
         if (child instanceof KList) {
             visitNestedKLists((KList)child);
         } else if (child instanceof Variable) {
             Variable klistVar = (Variable)child;
             assert (klistVar.getSort().equals("KList"));
             builder.append(klistVar.getName());
             builder.append(":KList");
         } else {
             assert false;
         }
         builder.append(')');
     }
     return null;
 }
  @Override
  public ASTNode visit(org.kframework.kil.Variable node, Void _void) {
    String name = node.fullName();

    if (node.getSort().equals(org.kframework.kil.Sort.BAG)
        || node.getSort().equals(org.kframework.kil.Sort.BAG_ITEM)) {
      return new Variable(name, Kind.CELL_COLLECTION.asSort());
    }

    if (node.getSort().equals(org.kframework.kil.Sort.K)) {
      return new Variable(name, Sort.KSEQUENCE);
    }
    if (node.getSort().equals(org.kframework.kil.Sort.KLIST)) {
      return new Variable(name, Sort.KLIST);
    }

    DataStructureSort dataStructureSort = context.dataStructureSortOf(node.getSort());
    if (dataStructureSort != null) {
      Sort sort = null;
      if (dataStructureSort.type().equals(org.kframework.kil.Sort.LIST)) {
        sort = Sort.LIST;
      } else if (dataStructureSort.type().equals(org.kframework.kil.Sort.MAP)) {
        sort = Sort.MAP;
      } else if (dataStructureSort.type().equals(org.kframework.kil.Sort.SET)) {
        sort = Sort.SET;
      } else {
        assert false : "unexpected data structure " + dataStructureSort.type();
      }

      if (concreteCollectionSize.containsKey(node)) {
        return new ConcreteCollectionVariable(name, sort, concreteCollectionSize.get(node));
      } else {
        return new Variable(name, sort);
      }
    }

    return new Variable(name, Sort.of(node.getSort()));
  }