Esempio n. 1
0
 public static Term static_transform(Term t, TermSystem sys, TransformationContext ctx)
     throws TermWareException {
   if (!t.getName().equals("printTerm")) return t;
   if (sys.isLoggingMode()) {
     sys.getEnv().getLog().print("native:");
     t.print(sys.getEnv().getLog());
     sys.getEnv().getLog().println();
   }
   Term retval = t;
   if (t.getArity() == 1) {
     t.getSubtermAt(0).print(sys.getEnv().getOutput());
     retval = t.getSubtermAt(0);
   } else if (t.getArity() == 2 || t.getArity() == 3) {
     // TODO:
     //    1.  check that name and language is string
     //    2.  outTag can be parameter.
     String printerName = t.getSubtermAt(1).getName();
     IPrinterFactory printerFactory = sys.getInstance().getPrinterFactory(printerName);
     IPrinter printer;
     Term arg = ((t.getArity() == 2) ? TermFactory.createNIL() : t.getSubtermAt(2));
     printer = printerFactory.createPrinter(sys.getEnv().getOutput(), "unknown", sys, arg);
     printer.writeTerm(t.getSubtermAt(0));
     retval = t.getSubtermAt(0);
   } else {
     if (sys.isLoggingMode()) {
       sys.getEnv().getLog().print("native:");
       t.print(sys.getEnv().getLog());
       sys.getEnv().getLog().println("- not changed.");
     }
     return t;
   }
   ctx.setChanged(true);
   if (sys.isLoggingMode()) {
     sys.getEnv().getLog().print("native:");
     t.print(sys.getEnv().getLog());
     sys.getEnv().getLog().println("- printed.");
   }
   return retval;
 }
Esempio n. 2
0
 @Override
 public IResponse execute(ISolver solver) {
   SMT.Configuration smtConfig = solver.smt();
   if (!(solver instanceof Solver_test)) {
     return smtConfig.responseFactory.error(
         "This kind of solver (" + solver.getClass() + ") is not able to execute a what command",
         null);
   }
   IPrinter printer = smtConfig.defaultPrinter;
   SymbolTable symTable = ((Solver_test) solver).symTable;
   Iterator<IIdentifier> iter = ids().iterator();
   if (!iter.hasNext()) {
     // No arguments - print everything in the symbol table
     SymbolTable.Iterator symiter = symTable.iterator();
     while (symiter.hasNext()) {
       SymbolTable.Entry n = symiter.next();
       smtConfig.log.logOut(printer.toString(n.name) + " : " + printer.toString(n.sort));
     }
   } else {
     while (iter.hasNext()) {
       IIdentifier s = iter.next();
       ISort.IDefinition sortDef = symTable.lookupSort(s);
       if (sortDef != null)
         smtConfig.log.logOut(printer.toString(s) + " : " + printer.toString(sortDef));
       else {
         Map<Integer, List<SymbolTable.Entry>> map = symTable.lookup(s);
         if (map != null && map.size() != 0) {
           for (List<SymbolTable.Entry> entrylist : map.values()) {
             for (SymbolTable.Entry entry : entrylist) {
               smtConfig.log.logOut(printer.toString(s) + " : " + printer.toString(entry.sort));
             }
           }
         } else {
           smtConfig.log.logOut(printer.toString(s) + " : -no entry- ");
         }
       }
     }
   }
   return smtConfig.responseFactory.success();
 }