MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / AbstractHeap

Class AbstractHeap

src/main/java/wycc/util/AbstractHeap.java:27–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25import wycc.lang.Syntactic.Item;
26
27public abstract class AbstractHeap implements Syntactic.Heap {
28 /**
29 * The list of syntactic items contained in this heap.
30 */
31 protected final ArrayList<Item> syntacticItems = new ArrayList<>();
32
33 /**
34 * The root item for this heap.
35 */
36 protected int root;
37
38 public AbstractHeap() {
39
40 }
41
42 public AbstractHeap(Syntactic.Heap heap) {
43 // Copy over the root
44 this.root = heap.getRootItem().getIndex();
45 // Now, clone items from heap in here
46 Allocator allocator = new Allocator(this);
47 //
48 for (int i = 0; i != heap.size(); ++i) {
49 Item oitem = heap.getSyntacticItem(i);
50 Item item = clone(oitem, allocator.map);
51 allocator.allocate(item);
52 }
53 }
54
55 @Override
56 public int size() {
57 return syntacticItems.size();
58 }
59
60 @Override
61 public Item getRootItem() {
62 return getSyntacticItem(root);
63 }
64
65 @Override
66 public void setRootItem(Item item) {
67 this.root = allocate(item).getIndex();
68 }
69
70 @Override
71 public Item getSyntacticItem(int index) {
72 return syntacticItems.get(index);
73 }
74
75 @Override
76 public int getIndexOf(Item item) {
77 for (int i = 0; i != syntacticItems.size(); ++i) {
78 if (syntacticItems.get(i) == item) {
79 return i;
80 }
81 }
82 throw new IllegalArgumentException("invalid syntactic item");
83 }
84

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected