Improve precision of interference analysis. Allow sizeof(v.r1.r2) expressions.
[repair.git] / Repair / RepairInterpreter / DefaultGuidance3.cc
1 #include <stdlib.h>
2 #include "DefaultGuidance3.h"
3 #include "model.h"
4 #include "dmodel.h"
5 #include "tmodel.h"
6 #include "element.h"
7 #include "common.h"
8   /* This class tells the analysis stuff */
9   /* For each set:
10      1. Source for atoms if the set is too small - can be another set or function call (assumed to be no set)
11      2. Source for atoms if relation requires atom of this set - can be another set or function call (assumed to be no set)
12      3. Removal from set - where to insert objects from this set
13      4. Insertion into set - which subset to put objects in  */
14
15 DefGuidance3::DefGuidance3(model *m) {
16   globalmodel=m;
17 }
18
19 Source DefGuidance3::sourceforsetsize(char *set) {
20   DomainRelation *dr=globalmodel->getdomainrelation();
21   DomainSet *ds=dr->getset(set);
22   while(dr->getsuperset(ds)!=NULL)
23     ds=dr->getsuperset(ds);
24   if(equivalentstrings(ds->getname(),"blocks"))
25      return Source(copystr("freeblocks"));
26 }
27
28 Source DefGuidance3::sourceforrelation(char *set) {
29   DomainRelation *dr=globalmodel->getdomainrelation();
30   DomainSet *ds=dr->getset(set);
31   while(dr->getsuperset(ds)!=NULL)
32     ds=dr->getsuperset(ds);
33   if(equivalentstrings(ds->getname(),"blocks"))
34      return Source(copystr("freeblocks"));
35   return Source(set);
36 }
37
38 char * DefGuidance3::removefromset(char * set) {
39   DomainRelation *dr=globalmodel->getdomainrelation();
40   DomainSet *ds=dr->getset(set);
41   if (equivalentstrings(set,"token"))
42     return NULL;
43
44   if (equivalentstrings(dr->getsuperset(ds)->getname(),"fatblocks"))
45     return "freeblocks";
46   if (equivalentstrings(dr->getsuperset(ds)->getname(),"usedblocks"))
47     return "freeblocks";
48
49   DomainSet *ss=dr->getsuperset(ds);
50   while(ss!=NULL&&ss->gettype()==DOMAINSET_PARTITION) {
51     for(int i=0;i<ss->getnumsubsets();i++) {
52       char *name=ss->getsubset(i);
53       if (!equivalentstrings(ds->getname(),name)&&
54           !equivalentstrings(ds->getname(),name)) {
55         /* Do search */
56         ss=dr->getset(name);
57         while(ss->gettype()==DOMAINSET_PARTITION) {
58           char *name=ss->getsubset(0);
59           ss=dr->getset(name);
60         }
61         return ss->getname();
62       }
63     }
64     ds=ss;
65     ss=dr->getsuperset(ss);
66   }
67   if (ss!=NULL)
68     return ss->getname();
69   else
70     return NULL;
71 }
72
73 char * DefGuidance3::insertiontoset(char *set) {
74   if (equivalentstrings(set,"token"))
75     return NULL;
76   
77   DomainRelation *dr=globalmodel->getdomainrelation();
78   DomainSet *ds=dr->getset(set);
79   while (ds->gettype()==DOMAINSET_PARTITION) {
80     ds=dr->getset(ds->getsubset(0));
81     /* have to look for subset; */
82   }
83   return ds->getname();
84 }