コード例 #1
0
ファイル: TestNeq.java プロジェクト: rssh/termware2
 public boolean runTest(IEnv env) {
   try {
     TermSystem general = TermWare.getInstance().getRoot().resolveSystem("general");
     Term t = TermWare.getInstance().getTermFactory().createParsedTerm("neq(p(x),p(x))");
     Term r = general.reduce(t);
     if (!(r.isBoolean() && r.getBoolean() == false)) {
       System.out.println("r1=" + TermHelper.termToString(r));
       return false;
     }
     t = TermWare.getInstance().getTermFactory().createParsedTerm("neq(p(\"x\"),p(\"x\"))");
     r = general.reduce(t);
     if (r.isBoolean()) {
       if (r.getBoolean() == false) {
         return true;
       } else {
         return false;
       }
     } else {
       System.out.println("r2=" + TermHelper.termToString(r));
       return false;
     }
   } catch (TermWareException ex) {
     ex.printStackTrace();
     return false;
   }
 }
コード例 #2
0
 public static Term static_transform(Term t, TermSystem sys, TransformationContext ctx)
     throws TermWareException {
   if (!t.getName().equals("javaStrategy")) return t;
   if (t.getArity() != 2) {
     return t;
   }
   sys.getInstance().addJavaStrategy(t.getSubtermAt(0).getName(), t.getSubtermAt(1).getName());
   ctx.setChanged(true);
   return TermFactory.createBoolean(true);
 }
コード例 #3
0
 public void generateNextTestSet(TransformationContext ctx, Term t) throws TermWareException {
   if (!t.isX()) {
     throw new AssertException("argument of generateNextTestSet must be a propositional variable");
   }
   Term retval = generateStateTermFromNextFieldModel();
   ctx.getCurrentSubstitution().put(t, retval);
   ++nGenerations_;
   if (nGenerations_ >= maxNGenerations_) {
     ctx.setStop(true);
   }
 }
コード例 #4
0
 public Term transform(JavaTypeModel typeModel, JPEFacts facts, Configuration configuration)
     throws TermWareException, EntityNotFoundException {
   if (configuration.isUnreachableCodeEliminationEnabled()) {
     // check only if current class is reachable.
     Term reachable = typeModel.getAttribute(MarkReachable.REACHABLE_CLASS_ATTRIBUTE);
     if (!reachable.isNil()) {
       if (typeModel instanceof JavaTermTypeAbstractModel) {
         MarkNumberOfChildsInSuper.process((JavaTermTypeAbstractModel) typeModel);
       }
     } else {
       if (configuration.getDebugLevel() >= DebugLevels.SHOW_WALK) {
         System.out.println(
             "devirtualization skip " + typeModel.getFullName() + " as unreachable");
       }
     }
   } else {
     MarkNumberOfChildsInSuper.process((JavaTermTypeAbstractModel) typeModel);
   }
   return null;
 }
コード例 #5
0
 public JavaWildcardBoundsTypeModel(
     Term t, JavaTypeModel where, List<JavaTypeVariableAbstractModel> typeParameters)
     throws TermWareException {
   super(where.getPackageModel());
   if (t.getName().equals("WildcardBounds")) {
     String stype = t.getSubtermAt(0).getName();
     if (stype.equals("extends")) {
       kind_ = JavaWildcardBoundsKind.EXTENDS;
     } else if (stype.equals("super")) {
       kind_ = JavaWildcardBoundsKind.SUPER;
     } else {
       throw new AssertException(
           "'extends' or 'super' is expected as the 0 subterm of " + TermHelper.termToString(t));
     }
     try {
       boundTypeModel_ = JavaResolver.resolveTypeToModel(t.getSubtermAt(1), where, typeParameters);
     } catch (EntityNotFoundException ex) {
       boundTypeModel_ = JavaUnknownTypeModel.INSTANCE;
     }
   } else {
     throw new AssertException(
         "WildcardBounds term is expected, instead " + TermHelper.termToString(t));
   }
 }
コード例 #6
0
 public static Term static_transform(Term t, TermSystem system, TransformationContext ctx)
     throws TermWareException {
   if (t.getArity() != 2) {
     throw new AssertException("logical_and must have arity 2");
   }
   LogHelper.log(system, LogicalAndTransformer.class, "LogicalAnd, t=", t);
   Term frs = t.getSubtermAt(0);
   Term snd = t.getSubtermAt(1);
   Term retval = t;
   if (frs.isBoolean() && snd.isBoolean()) {
     ctx.setChanged(true);
     retval =
         system.getInstance().getTermFactory().createBoolean(frs.getBoolean() && snd.getBoolean());
   } else if (frs.isBoolean()) {
     if (frs.getBoolean()) {
       // true && y -> y
       ctx.setChanged(true);
       retval = snd;
     } else {
       // false &&  y -> false
       ctx.setChanged(true);
       retval = frs;
     }
   } else if (snd.isBoolean()) {
     if (snd.getBoolean()) {
       // x && true -> x
       ctx.setChanged(true);
       retval = frs;
     } else {
       // x && false -> x
       ctx.setChanged(true);
       retval = snd;
     }
   }
   LogHelper.log(system, LogicalAndTransformer.class, "return ", retval);
   return retval;
 }
コード例 #7
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;
 }