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.addDeclaration(td.getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
48 cr.outputline(vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") calloc(1,"+size.getSafeSymbol()+");");
49 cr.outputline("alloc((void *) "+vd.getSafeSymbol()+","+size.getSafeSymbol()+");");
50 if (Compiler.ALLOCATECPLUSPLUS) {
51 if (td instanceof StructureTypeDescriptor) {
52 if (((StructureTypeDescriptor)td).size()>0) {
53 FieldDescriptor fd=((StructureTypeDescriptor)td).get(0);
54 if (fd.getSymbol().startsWith("_vptr_")) {
56 vtable+=td.getSymbol().length();
57 vtable+=td.getSymbol();
58 cr.outputline("((int**) "+vd.getSafeSymbol()+")[0] = (int *) & "+vtable+"+2;");
65 public boolean relsetSource(RelationDescriptor rd, boolean domain) {
67 return setSource(rd.getDomain());
68 else return setSource(rd.getRange());
70 public boolean relallocSource(RelationDescriptor rd, boolean domain) {
72 return allocSource(rd.getDomain());
73 else return allocSource(rd.getRange());
76 public SetDescriptor relgetSourceSet(RelationDescriptor rd, boolean domain) {
78 return getSourceSet(rd.getDomain());
79 else return getSourceSet(rd.getRange());
81 public void relgenerateSourceAlloc(CodeWriter cr,VarDescriptor vd, RelationDescriptor rd, boolean domain) {
82 SetDescriptor sd=null;
88 generateSourceAlloc(cr, vd, sd);