MCPcopy Create free account
hub / github.com/Z3Prover/z3 / forestExample

Method forestExample

examples/java/JavaGenericExample.java:1525–1638  ·  view source on GitHub ↗
(Context ctx)

Source from the content-addressed store, hash-verified

1523 // / tree ::= nil | cons(forest, forest)
1524 // / </remarks>
1525 @SuppressWarnings({"unchecked", "unused", "UnusedAssignment"})
1526 public <Tree, Forest> void forestExample(Context ctx) throws TestFailedException
1527 {
1528 System.out.println("ForestExample");
1529 Log.append("ForestExample");
1530
1531 DatatypeSort<Forest> forest;
1532 DatatypeSort<Tree> tree;
1533 FuncDecl<DatatypeSort<Forest>> nil1_decl, cons1_decl, cdr1_decl, car2_decl, cdr2_decl;
1534 FuncDecl<DatatypeSort<Tree>> car1_decl, nil2_decl, cons2_decl;
1535 FuncDecl<BoolSort> is_nil1_decl, is_nil2_decl, is_cons1_decl, is_cons2_decl;
1536
1537 //
1538 // Declare the names of the accessors for cons.
1539 // Then declare the sorts of the accessors.
1540 // For this example, all sorts refer to the new types 'forest' and
1541 // 'tree'
1542 // being declared, so we pass in null for both sorts1 and sorts2.
1543 // On the other hand, the sort_refs arrays contain the indices of the
1544 // two new sorts being declared. The first element in sort1_refs
1545 // points to 'tree', which has index 1, the second element in sort1_refs
1546 // array points to 'forest', which has index 0.
1547 //
1548 Symbol[] head_tail1 = new Symbol[] { ctx.mkSymbol("head"),
1549 ctx.mkSymbol("tail") };
1550 Sort[] sorts1 = new Sort[] { null, null };
1551 int[] sort1_refs = new int[] { 1, 0 }; // the first item points to a
1552 // tree, the second to a forest
1553
1554 Symbol[] head_tail2 = new Symbol[] { ctx.mkSymbol("car"),
1555 ctx.mkSymbol("cdr") };
1556 Sort[] sorts2 = new Sort[] { null, null };
1557 int[] sort2_refs = new int[] { 0, 0 }; // both items point to the forest
1558 // datatype.
1559 Constructor<Forest> nil1_con, cons1_con;
1560 Constructor<Tree> nil2_con, cons2_con;
1561 Constructor<Forest>[] constructors1 = new Constructor[2];
1562 Constructor<Tree>[] constructors2 = new Constructor[2];
1563 Symbol[] sort_names = { ctx.mkSymbol("forest"), ctx.mkSymbol("tree") };
1564
1565 /* build a forest */
1566 nil1_con = ctx.mkConstructor(ctx.mkSymbol("nil1"),
1567 ctx.mkSymbol("is_nil1"), null, null, null);
1568 cons1_con = ctx.mkConstructor(ctx.mkSymbol("cons1"),
1569 ctx.mkSymbol("is_cons1"), head_tail1, sorts1, sort1_refs);
1570 constructors1[0] = nil1_con;
1571 constructors1[1] = cons1_con;
1572
1573 /* build a tree */
1574 nil2_con = ctx.mkConstructor(ctx.mkSymbol("nil2"),
1575 ctx.mkSymbol("is_nil2"), null, null, null);
1576 cons2_con = ctx.mkConstructor(ctx.mkSymbol("cons2"),
1577 ctx.mkSymbol("is_cons2"), head_tail2, sorts2, sort2_refs);
1578 constructors2[0] = nil2_con;
1579 constructors2[1] = cons2_con;
1580
1581 Constructor<Object>[][] clists = new Constructor[][] { constructors1,
1582 constructors2 };

Callers 1

mainMethod · 0.95

Calls 14

appendMethod · 0.95
proveMethod · 0.95
mkSymbolMethod · 0.80
mkConstructorMethod · 0.80
mkDatatypeSortsMethod · 0.80
ConstructorDeclMethod · 0.80
getAccessorDeclsMethod · 0.80
mkConstMethod · 0.80
mkAppMethod · 0.80
mkNotMethod · 0.80
mkEqMethod · 0.80
mkImpliesMethod · 0.80

Tested by

no test coverage detected