Example #1
0
 def consequences(self, filter=None, table_theories=None):
     """Return all the true instances of any table in this theory."""
     # find all table, theory pairs defined in this theory
     if table_theories is None:
         table_theories = set()
         for key in self.rules.keys():
             table_theories |= set([(rule.head.table.table,
                                     rule.head.table.service)
                                    for rule in self.rules.get_rules(key)])
     results = set()
     # create queries: need table names and arities
     # TODO(thinrichs): arity computation will need to ignore
     #   modals once we start using insert[p(x)] instead of p+(x)
     for (table, theory) in table_theories:
         if filter is None or filter(table):
             tablename = compile.Tablename(table, theory)
             arity = self.arity(tablename)
             vs = []
             for i in range(0, arity):
                 vs.append("x" + str(i))
             vs = [compile.Variable(var) for var in vs]
             tablename = table
             if theory:
                 tablename = theory + ":" + tablename
             query = compile.Literal(tablename, vs)
             results |= set(self.select(query))
     return results
Example #2
0
def retrieve(theory, tablename):
    # type: (topdown.TopDownTheory, str) -> List[ast.Literal]
    """Retrieves all the values of an external table.

    Performs a select on the theory with a query computed from the schema
    of the table.
    """
    arity = theory.schema.arity(tablename)
    table = ast.Tablename(tablename, theory.name)
    args = [ast.Variable('X' + str(i)) for i in range(arity)]
    query = ast.Literal(table, args)
    return theory.select(query)
Example #3
0
 def test_select(self):
     context = z3theory.Z3Context.get_context()
     context.select = mock.MagicMock()
     lit = ast.Literal(ast.Tablename('t'), [])
     self.theory.select(lit)
     context.select.assert_called_once_with(self.theory, lit, True)
Example #4
0
 def test_arity(self):
     lit = ast.Literal(
         ast.Tablename('t'),
         [ast.Variable('x'), ast.Variable('x')])
     self.theory.insert(lit)
     self.assertEqual(2, self.theory.arity('t'))