build with other copy
[repair.git] / Repair / RepairInterpreter / DefaultGuidance2.cc
1 // for the File System benchmark
2
3 #include <stdlib.h>
4 #include "DefaultGuidance2.h"
5 #include "model.h"
6 #include "dmodel.h"
7 #include "tmodel.h"
8 #include "element.h"
9 #include "common.h"
10   /* This class tells the analysis stuff */
11   /* For each set:
12      1. Source for atoms if the set is too small - can be another set or function call (assumed to be no set)
13      2. Source for atoms if relation requires atom of this set - can be another set or function call (assumed to be no set)
14      3. Removal from set - where to insert objects from this set
15      4. Insertion into set - which subset to put objects in  */
16
17 DefGuidance2::DefGuidance2(model *m) {
18   globalmodel=m;
19 }
20
21 Source DefGuidance2::sourceforsetsize(char *set) {
22   DomainRelation *dr=globalmodel->getdomainrelation();
23   DomainSet *ds=dr->getset(set);
24   while(dr->getsuperset(ds)!=NULL)
25     ds=dr->getsuperset(ds);
26   if(equivalentstrings(ds->getname(),"Block"))
27      return Source(copystr("FreeBlock"));
28   if(equivalentstrings(ds->getname(),"Inode"))
29      return Source(copystr("FreeInode"));
30 }
31
32 Source DefGuidance2::sourceforrelation(char *set) {
33   return Source(set);
34 }
35
36 char * DefGuidance2::removefromset(char * set) {
37   DomainRelation *dr=globalmodel->getdomainrelation();
38   DomainSet *ds=dr->getset(set);
39   if (equivalentstrings(set,"token"))
40     return NULL;
41
42   if (equivalentstrings(dr->getsuperset(ds)->getname(),"UsedBlock"))
43     return "FreeBlock";
44   if (equivalentstrings(dr->getsuperset(ds)->getname(),"UsedInode"))
45     return "FreeInode";
46
47   DomainSet *ss=dr->getsuperset(ds);
48   while(ss!=NULL&&ss->gettype()==DOMAINSET_PARTITION) {
49     for(int i=0;i<ss->getnumsubsets();i++) {
50       char *name=ss->getsubset(i);
51       if (!equivalentstrings(ds->getname(),name)&&
52           !equivalentstrings(ds->getname(),name)) {
53         /* Do search */
54         ss=dr->getset(name);
55         while(ss->gettype()==DOMAINSET_PARTITION) {
56           char *name=ss->getsubset(0);
57           ss=dr->getset(name);
58         }
59         return ss->getname();
60       }
61     }
62     ds=ss;
63     ss=dr->getsuperset(ss);
64   }
65   if (ss!=NULL)
66     return ss->getname();
67   else
68     return NULL;
69 }
70
71 char * DefGuidance2::insertiontoset(char *set) {
72   if (equivalentstrings(set,"token"))
73     return NULL;
74   if (equivalentstrings(set,"UsedBlock"))
75     return "FileBlock";
76   if (equivalentstrings(set,"UsedInode"))
77     return "FileInode";
78   
79   DomainRelation *dr=globalmodel->getdomainrelation();
80   DomainSet *ds=dr->getset(set);
81   while (ds->gettype()==DOMAINSET_PARTITION) {
82     ds=dr->getset(ds->getsubset(0));
83     /* have to look for subset; */
84   }
85   return ds->getname();
86 }
87
88 Element * allocatebytes2(structure * st, model *m) {
89   int size=st->getsize(m->getbitreader(),m,m->gethashtable());
90   Element * e=new Element(new char[size],st);
91   return e;
92 }