Changes:
[repair.git] / Repair / RepairCompiler / MCC / IR / Sources.java
1 package MCC.IR;
2
3 import MCC.State;
4
5 public class Sources {
6     State state;
7
8     public Sources(State s) {
9         this.state=s;
10     }
11
12     public boolean setSource(SetDescriptor sd) {
13         return false;
14     }
15     public boolean allocSource(SetDescriptor sd) {
16         return true;
17     }
18     public SetDescriptor getSourceSet(SetDescriptor sd) {
19         return null;
20     }
21     public void generateSourceAlloc(CodeWriter cr,VarDescriptor vd, SetDescriptor sd) {
22         TypeDescriptor td=sd.getType();
23         Expr e=td.getSizeExpr();
24         VarDescriptor size=VarDescriptor.makeNew("size");
25         cr.pushSymbolTable(state.stGlobals);
26         e.generate(cr, size);
27         cr.popSymbolTable();
28         cr.outputline(td.getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") malloc("+size.getSafeSymbol()+");");
29     }
30
31     public boolean relsetSource(RelationDescriptor rd, boolean domain) {
32         return false;
33     }
34     public boolean relallocSource(RelationDescriptor rd, boolean domain) {
35         return true;
36     }
37     public SetDescriptor relgetSourceSet(RelationDescriptor rd, boolean domain) {
38         return null;
39     }
40     public void relgenerateSourceAlloc(CodeWriter cr,VarDescriptor vd, RelationDescriptor rd, boolean domain) {
41         SetDescriptor sd=null;
42         if (domain)
43             sd=rd.getDomain();
44         else
45             sd=rd.getRange();
46         TypeDescriptor td=sd.getType();
47         Expr e=td.getSizeExpr();
48         VarDescriptor size=VarDescriptor.makeNew("size");
49         cr.pushSymbolTable(state.stGlobals);
50         e.generate(cr, size);
51         cr.popSymbolTable();
52         cr.outputline(td.getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") malloc("+size.getSafeSymbol()+");");
53     }
54
55 }