private void installClass(CgenNode nd) { AbstractSymbol name = nd.getName(); if (probe(name) != null) return; nds.addElement(nd); nodeMap.put(nd.getName(), nd); addId(name, nd); }
/* given a class and a method, return the offset to the class's dispatch table */ public int getMethodOffset(AbstractSymbol clazz, AbstractSymbol method) { CgenNode nd = nodeMap.get(clazz); if (Flags.cgen_debug) System.out.printf("getMethodOffset %s %s\n", clazz, method); if (!nd.methOffsets.containsKey(method)) return getMethodOffset(nd.getParent(), method); else return nd.methOffsets.get(method); }
/* get the depth of the class in the inheritance tree */ public int getDepth(AbstractSymbol clazz) { int depth = 0; CgenNode nd = nodeMap.get(clazz); while (nd.name != TreeConstants.Object_) { nd = nd.getParentNode(); depth++; } return depth; }
private void codeClassMethods() { str.println("\n# Class Methods"); for (Object obj : nds) { // code each of the class method CgenNode nd = (CgenNode) obj; nd.codeClassMethod(str); } }
private void codeObjInits() { str.println("\n# Object Initializers"); for (Object obj : nds) { CgenNode nd = (CgenNode) obj; // code object initailzers (constructor method) CgenSupport.emitInitRef(nd.getName(), str); str.print(CgenSupport.LABEL); nd.codeObjInit(str); } }
private void codeDispTables() { str.println("\n# Dispatch Tables"); for (Object obj : nds) { CgenNode nd = (CgenNode) obj; // code class method reference CgenSupport.emitDispTableRef(nd.getName(), str); str.print(CgenSupport.LABEL); nd.codeDispTab(str); } }
private void codeProtObjs() { str.println("\n# Prototype Objects"); for (Object obj : nds) { CgenNode nd = (CgenNode) obj; // code class attributes str.println(CgenSupport.WORD + "-1"); // GC tag CgenSupport.emitProtObjRef(nd.getName(), str); str.print(CgenSupport.LABEL); nd.codeProtObj(str); } }
private void codeClassNameTable() { str.println("\n# Class Name Table"); str.print(CgenSupport.CLASSNAMETAB + CgenSupport.LABEL); // code the name of each class for (Object obj : nds) { str.print(CgenSupport.WORD); ((CgenNode) obj).getNameStrSym().codeRef(str); str.println("\t# " + obj); } }
/* given a class and an attribute, return the offset to the object reference */ public int getAttrOffset(AbstractSymbol clazz, AbstractSymbol a) { CgenNode nd = nodeMap.get(clazz); if (!nd.attrOffsets.containsKey(a)) return getAttrOffset(nd.getParent(), a); else return nd.attrOffsets.get(a); }
private void setRelations(CgenNode nd) { CgenNode parent = (CgenNode) probe(nd.getParent()); nd.setParentNd(parent); parent.addChild(nd); }