5 import java.util.Iterator;
10 public Sources(State s) {
14 public boolean setSource(SetDescriptor sd) {
15 SetDescriptor usedblock=(SetDescriptor)state.stSets.get("UsedBlock");
16 SetDescriptor usedinode=(SetDescriptor)state.stSets.get("UsedInode");
18 if (usedblock!=null&&usedblock.isSubset(sd))
20 if (usedinode!=null&&usedinode.isSubset(sd))
25 public boolean allocSource(SetDescriptor sd) {
26 return !setSource(sd);
28 public SetDescriptor getSourceSet(SetDescriptor sd) {
29 SetDescriptor usedblock=(SetDescriptor)state.stSets.get("UsedBlock");
30 SetDescriptor usedinode=(SetDescriptor)state.stSets.get("UsedInode");
32 if (usedblock!=null&&usedblock.isSubset(sd))
33 return (SetDescriptor)state.stSets.get("FreeBlock");
34 if (usedinode!=null&&usedinode.isSubset(sd))
35 return (SetDescriptor)state.stSets.get("FreeInode");
40 public void generateSourceAlloc(CodeWriter cr,VarDescriptor vd, SetDescriptor sd) {
41 TypeDescriptor td=sd.getType();
42 Expr e=td.getSizeExpr();
43 VarDescriptor size=VarDescriptor.makeNew("size");
44 cr.pushSymbolTable(state.stGlobals);
47 cr.outputline(td.getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") calloc(1,"+size.getSafeSymbol()+");");
48 cr.outputline("alloc((void *) "+vd.getSafeSymbol()+","+size.getSafeSymbol()+");");
49 if (Compiler.ALLOCATECPLUSPLUS) {
50 if (td instanceof StructureTypeDescriptor) {
51 if (((StructureTypeDescriptor)td).size()>0) {
52 FieldDescriptor fd=((StructureTypeDescriptor)td).get(0);
53 if (fd.getSymbol().startsWith("_vptr_")) {
55 vtable+=td.getSymbol().length();
56 vtable+=td.getSymbol();
57 cr.outputline("((int**) "+vd.getSafeSymbol()+")[0] = (int *) & "+vtable+"+2;");
64 public boolean relsetSource(RelationDescriptor rd, boolean domain) {
66 return setSource(rd.getDomain());
67 else return setSource(rd.getRange());
69 public boolean relallocSource(RelationDescriptor rd, boolean domain) {
71 return allocSource(rd.getDomain());
72 else return allocSource(rd.getRange());
75 public SetDescriptor relgetSourceSet(RelationDescriptor rd, boolean domain) {
77 return getSourceSet(rd.getDomain());
78 else return getSourceSet(rd.getRange());
80 public void relgenerateSourceAlloc(CodeWriter cr,VarDescriptor vd, RelationDescriptor rd, boolean domain) {
81 SetDescriptor sd=null;
87 generateSourceAlloc(cr, vd, sd);