Evaluator: add support for str.code (#2696)
authorAndres Noetzli <andres.noetzli@gmail.com>
Thu, 8 Nov 2018 01:04:52 +0000 (17:04 -0800)
committerAndrew Reynolds <andrew.j.reynolds@gmail.com>
Thu, 8 Nov 2018 01:04:52 +0000 (19:04 -0600)
src/theory/evaluator.cpp
test/unit/theory/evaluator_white.h

index 25e20451ae7d1042722d41b234759beda2afff2a..0a0176f25b5a28a1b8281b709206d02766783a07 100644 (file)
@@ -441,6 +441,21 @@ EvalResult Evaluator::evalInternal(TNode n,
           break;
         }
 
+        case kind::STRING_CODE:
+        {
+          const String& s = results[currNode[0]].d_str;
+          if (s.size() == 1)
+          {
+            results[currNode] = EvalResult(
+                Rational(String::convertUnsignedIntToCode(s.getVec()[0])));
+          }
+          else
+          {
+            results[currNode] = EvalResult(Rational(-1));
+          }
+          break;
+        }
+
         case kind::CONST_BITVECTOR:
           results[currNode] = EvalResult(currNodeVal.getConst<BitVector>());
           break;
index 73556c388fd2d2f2ab17c3994fef1dfc173fb8ba..9dc6f9520e0ce8b231dcebc69b4aa461b764c622 100644 (file)
@@ -156,4 +156,28 @@ class TheoryEvaluatorWhite : public CxxTest::TestSuite
       TS_ASSERT_EQUALS(r, Rewriter::rewrite(n));
     }
   }
+
+  void testCode()
+  {
+    Node a = d_nm->mkConst(String("A"));
+    Node empty = d_nm->mkConst(String(""));
+
+    std::vector<Node> args;
+    std::vector<Node> vals;
+    Evaluator eval;
+
+    // (str.code "A") ---> 65
+    {
+      Node n = d_nm->mkNode(kind::STRING_CODE, a);
+      Node r = eval.eval(n, args, vals);
+      TS_ASSERT_EQUALS(r, d_nm->mkConst(Rational(65)));
+    }
+
+    // (str.code "") ---> -1
+    {
+      Node n = d_nm->mkNode(kind::STRING_CODE, empty);
+      Node r = eval.eval(n, args, vals);
+      TS_ASSERT_EQUALS(r, d_nm->mkConst(Rational(-1)));
+    }
+  }
 };