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

Class AbstractItem

src/main/java/wycc/util/AbstractItem.java:24–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22import wycc.lang.Syntactic.Item;
23
24public abstract class AbstractItem implements Comparable<Item>, Item, Cloneable {
25 // Constants;
26 private Syntactic.Heap parent;
27 private int index; // index in the parent
28 protected int opcode;
29 protected Item[] operands;
30 protected byte[] data;
31
32 public AbstractItem(int opcode) {
33 super();
34 this.opcode = opcode;
35 this.operands = null;
36 this.data = null;
37 }
38
39 public AbstractItem(int opcode, Item... operands) {
40 this.opcode = opcode;
41 this.operands = operands;
42 this.data = null;
43 }
44
45 protected AbstractItem(int opcode, byte[] data, Item... operands) {
46 this.opcode = opcode;
47 this.operands = operands;
48 this.data = data;
49 }
50
51 @Override
52 public Syntactic.Heap getHeap() {
53 return parent;
54 }
55
56 @Override
57 public void allocate(Syntactic.Heap heap, int index) {
58 if(parent != null && parent != heap) {
59 throw new IllegalArgumentException(
60 "item already allocated to different heap (" + getClass().getName() + ";" + parent + ", " + heap
61 + ")");
62 }
63
64 this.parent = heap;
65 this.index = index;
66 }
67
68 /**
69 * Get the first syntactic item of a given kind which refers to this item.
70 *
71 * @param kind
72 * @return
73 */
74 @Override
75 public <T extends Item> T getParent(Class<T> kind) {
76 return parent.getParent(this, kind);
77 }
78
79 /**
80 * Get all syntactic items of a given kind which refer to this item.
81 *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected