New C Runtime.
authorbdemsky <bdemsky>
Thu, 28 Oct 2004 19:26:25 +0000 (19:26 +0000)
committerbdemsky <bdemsky>
Thu, 28 Oct 2004 19:26:25 +0000 (19:26 +0000)
Repair/RepairCompiler/MCC/Runtime/SimpleHash.c [new file with mode: 0755]
Repair/RepairCompiler/MCC/Runtime/SimpleHash.h
Repair/RepairCompiler/MCC/Runtime/buildruntime
Repair/RepairCompiler/MCC/Runtime/classlist.h
Repair/RepairCompiler/MCC/Runtime/instrument.c [new file with mode: 0755]
Repair/RepairCompiler/MCC/Runtime/instrument.h
Repair/RepairCompiler/MCC/Runtime/memory.h
Repair/RepairCompiler/MCC/Runtime/size.h [new file with mode: 0755]
Repair/RepairCompiler/MCC/Runtime/stack.c
Repair/RepairCompiler/MCC/Runtime/tmap.c [new file with mode: 0755]
Repair/RepairCompiler/MCC/Runtime/tmap.h

diff --git a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.c b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.c
new file mode 100755 (executable)
index 0000000..b238c22
--- /dev/null
@@ -0,0 +1,594 @@
+#include "SimpleHash.h"
+#include <stdio.h>
+
+/* LINKED HASH NODE ****************************************************/
+
+struct LinkedHashNode * allocateLinkedHashNode(int key, int data, struct LinkedHashNode *next) {
+    struct LinkedHashNode *thisvar=(struct LinkedHashNode *)malloc(sizeof(struct LinkedHashNode));
+    thisvar->key = key;
+    thisvar->data = data;
+    thisvar->next = next;
+    thisvar->lnext=0;
+    thisvar->lprev=0;
+    return thisvar;
+}
+
+struct LinkedHashNode * noargallocateLinkedHashNode() {
+    struct LinkedHashNode *thisvar=(struct LinkedHashNode *)malloc(sizeof(struct LinkedHashNode));
+    thisvar->key = -1;
+    thisvar->data = -1;
+    thisvar->next = 0;
+    thisvar->lnext=0;
+    thisvar->lprev=0;
+    return thisvar;
+}
+
+/* SIMPLE LIST ****************************************************/
+
+struct SimpleList * allocateSimpleList() {
+    struct SimpleList *thisvar=(struct SimpleList *)malloc(sizeof(struct SimpleList));
+    thisvar->ptr = 0;
+    thisvar->head.next = 0;
+    return thisvar;
+}
+
+void SimpleListreset(struct SimpleList *thisvar) {
+    thisvar->ptr = &thisvar->head;
+}
+
+int SimpleListhasMoreElements(struct SimpleList *thisvar) {
+    return (thisvar->ptr->next != 0);
+}
+
+int SimpleListnextElement(struct SimpleList *thisvar) {
+  thisvar->ptr = thisvar->ptr->next;
+  return thisvar->ptr->data;
+}
+
+void SimpleListadd(struct SimpleList *thisvar,int data) {
+    struct LinkedHashNode *cur = &thisvar->head;
+    while (cur->next) {
+        cur = cur->next;
+        if (cur->data == data) {
+            return; /* no duplicates */
+        }
+    }
+    cur->next = allocateLinkedHashNode(0, data, 0);
+    return;
+}
+
+int SimpleListcontains(struct SimpleList *thisvar,int data) {
+    struct LinkedHashNode *cur = &thisvar->head;
+    while (cur->next) {
+        cur = cur->next;
+        if (cur->data == data) {
+            return 1; /* found! */
+        }
+    }
+    return 0;
+}
+
+/* WORK LIST ****************************************************/
+
+struct WorkList * allocateWorkList() {
+    struct WorkList *thisvar=(struct WorkList *)malloc(sizeof(struct WorkList));
+    thisvar->head=(struct ListNode *) malloc(sizeof(struct ListNode));
+    thisvar->tail=thisvar->head;
+    thisvar->head->next=0;
+    thisvar->headoffset=0;
+    thisvar->tailoffset=0;
+    return thisvar;
+}
+
+void WorkListreset(struct WorkList *thisvar) {
+    thisvar->head=thisvar->tail;
+    thisvar->headoffset=0;
+    thisvar->tailoffset=0;
+}
+
+int WorkListhasMoreElements(struct WorkList *thisvar) {
+  return ((thisvar->head!=thisvar->tail)||(thisvar->headoffset!=thisvar->tailoffset));
+}
+
+int WorkListgetid(struct WorkList *thisvar) {
+  return thisvar->tail->data[thisvar->tailoffset];
+}
+
+int WorkListgettype(struct WorkList *thisvar) {
+  return thisvar->tail->data[thisvar->tailoffset+1];
+}
+
+int WorkListgetlvalue(struct WorkList *thisvar) {
+  return thisvar->tail->data[thisvar->tailoffset+2];
+}
+
+int WorkListgetrvalue(struct WorkList *thisvar) {
+  return thisvar->tail->data[thisvar->tailoffset+3];
+}
+
+void freeWorkList(struct WorkList *thisvar) {
+  struct ListNode *ptr=thisvar->tail;
+  while(ptr) {
+    struct ListNode *oldptr=ptr;
+    ptr=ptr->next;
+    free(oldptr);
+  }
+  free(thisvar);
+}
+
+void WorkListpop(struct WorkList *thisvar) {
+  int newoffset=thisvar->tailoffset+4;
+  struct ListNode *ptr=thisvar->tail;
+  if (newoffset>=WLISTSIZE) {
+    if (newoffset!=WLISTSIZE||thisvar->head!=thisvar->tail) {
+      struct ListNode *oldptr=ptr;
+      newoffset-=WLISTSIZE;
+      ptr=ptr->next;
+      free(oldptr);
+    }
+  }
+  thisvar->tail=ptr;
+  thisvar->tailoffset=newoffset;
+}
+
+void WorkListadd(struct WorkList *thisvar, int id,int type, int lvalue, int rvalue) {
+  if (thisvar->headoffset==WLISTSIZE) {
+    if (thisvar->head->next==0) {
+      thisvar->head->next=(struct ListNode *)malloc(sizeof(struct ListNode));
+      thisvar->head->next->next=0;
+    }
+    thisvar->headoffset=0;
+    thisvar->head=thisvar->head->next;
+    if (thisvar->tailoffset==WLISTSIZE) { /* roll the tail over also */
+        thisvar->tailoffset=0;
+        thisvar->tail=thisvar->tail->next;
+    }
+  }
+  thisvar->head->data[thisvar->headoffset++]=id;
+  thisvar->head->data[thisvar->headoffset++]=type;
+  thisvar->head->data[thisvar->headoffset++]=lvalue;
+  thisvar->head->data[thisvar->headoffset++]=rvalue;
+}
+
+/* SIMPLE HASH ********************************************************/
+struct SimpleIterator* createiterator(struct SimpleHash * thisvar) {
+    return allocateSimpleIterator(thisvar->listhead,thisvar->listtail,thisvar->tailindex/*,thisvar*/);
+}
+
+void iterator(struct SimpleHash *thisvar, struct SimpleIterator * it) {
+  it->cur=thisvar->listhead;
+  it->index=0;
+  it->tailindex=thisvar->tailindex;
+  it->tail=thisvar->listtail;
+}
+
+struct SimpleHash * noargallocateSimpleHash() {
+    return allocateSimpleHash(100);
+}
+
+struct SimpleHash * allocateSimpleHash(int size) {
+    struct SimpleHash *thisvar=(struct SimpleHash *)malloc(sizeof(struct SimpleHash));
+    if (size <= 0) {
+        printf("Negative Hashtable size Exception\n");
+        exit(-1);
+    }
+    thisvar->size = size;
+    thisvar->bucket = (struct SimpleNode **) calloc(sizeof(struct SimpleNode *)*size,1);
+    /* Set allocation blocks*/
+    thisvar->listhead=(struct ArraySimple *) calloc(sizeof(struct ArraySimple),1);
+    thisvar->listtail=thisvar->listhead;
+    thisvar->tailindex=0;
+    /*Set data counts*/
+    thisvar->numparents = 0;
+    thisvar->numchildren = 0;
+    thisvar->numelements = 0;
+    return thisvar;
+}
+
+void freeSimpleHash(struct SimpleHash *thisvar) {
+    struct ArraySimple *ptr=thisvar->listhead;
+    free(thisvar->bucket);
+    while(ptr) {
+        struct ArraySimple *next=ptr->nextarray;
+        free(ptr);
+        ptr=next;
+    }
+    free(thisvar);
+}
+
+int SimpleHashfirstkey(struct SimpleHash *thisvar) {
+  struct ArraySimple *ptr=thisvar->listhead;
+  int index=0;
+  while((index==ARRAYSIZE)||!ptr->nodes[index].inuse) {
+    if (index==ARRAYSIZE) {
+      index=0;
+      ptr=ptr->nextarray;
+    } else
+      index++;
+  }
+  return ptr->nodes[index].key;
+}
+
+void SimpleHashaddParent(struct SimpleHash *thisvar,struct SimpleHash* parent) {
+    thisvar->parents[thisvar->numparents++] = parent;
+    SimpleHashaddChild(parent,thisvar);
+}
+
+void SimpleHashaddChild(struct SimpleHash *thisvar, struct SimpleHash *child) {
+    thisvar->children[thisvar->numchildren++]=child;
+}
+
+int SimpleHashremove(struct SimpleHash *thisvar, int key, int data) {
+    unsigned int hashkey = (unsigned int)key % thisvar->size;
+
+    struct SimpleNode **ptr = &thisvar->bucket[hashkey];
+    int i;
+    for (i = 0; i < thisvar->numchildren; i++) {
+        SimpleHashremove(thisvar->children[i], key, data);
+    }
+
+    while (*ptr) {
+        if ((*ptr)->key == key && (*ptr)->data == data) {
+         struct SimpleNode *toremove=*ptr;
+         *ptr=(*ptr)->next;
+
+         toremove->inuse=0; /* Marked as unused */
+
+         thisvar->numelements--;
+         return 1;
+        }
+        ptr = &((*ptr)->next);
+    }
+
+    return 0;
+}
+
+void SimpleHashaddAll(struct SimpleHash *thisvar, struct SimpleHash * set) {
+    struct SimpleIterator it;
+    SimpleHashiterator(set, &it);
+    while(hasNext(&it)) {
+        int keyv=key(&it);
+        int data=next(&it);
+        SimpleHashadd(thisvar,keyv,data);
+    }
+}
+
+int SimpleHashadd(struct SimpleHash * thisvar,int key, int data) {
+  /* Rehash code */
+  unsigned int hashkey;
+  struct SimpleNode **ptr;
+
+  if (thisvar->numelements>=thisvar->size) {
+    int newsize=2*thisvar->size+1;
+    struct SimpleNode ** newbucket = (struct SimpleNode **) calloc(sizeof(struct SimpleNode *)*newsize,1);
+    int i;
+    for(i=thisvar->size-1;i>=0;i--) {
+        struct SimpleNode *ptr;
+        for(ptr=thisvar->bucket[i];ptr!=NULL;) {
+            struct SimpleNode * nextptr=ptr->next;
+            unsigned int newhashkey=(unsigned int)ptr->key % newsize;
+            ptr->next=newbucket[newhashkey];
+            newbucket[newhashkey]=ptr;
+            ptr=nextptr;
+        }
+    }
+    thisvar->size=newsize;
+    free(thisvar->bucket);
+    thisvar->bucket=newbucket;
+  }
+
+  hashkey = (unsigned int)key % thisvar->size;
+  ptr = &thisvar->bucket[hashkey];
+
+  /* check that thisvar key/object pair isn't already here */
+  /* TBD can be optimized for set v. relation */
+
+  while (*ptr) {
+    if ((*ptr)->key == key && (*ptr)->data == data) {
+      return 0;
+    }
+    ptr = &((*ptr)->next);
+  }
+  if (thisvar->tailindex==ARRAYSIZE) {
+    thisvar->listtail->nextarray=(struct ArraySimple *) calloc(sizeof(struct ArraySimple),1);
+    thisvar->tailindex=0;
+    thisvar->listtail=thisvar->listtail->nextarray;
+  }
+
+  *ptr = &thisvar->listtail->nodes[thisvar->tailindex++];
+  (*ptr)->key=key;
+  (*ptr)->data=data;
+  (*ptr)->inuse=1;
+
+  thisvar->numelements++;
+  {
+      int i;
+      for (i = 0; i < thisvar->numparents; i++) {
+          SimpleHashadd(thisvar->parents[i], key, data);
+      }
+  }
+  return 1;
+}
+
+bool SimpleHashcontainskey(struct SimpleHash *thisvar,int key) {
+    unsigned int hashkey = (unsigned int)key % thisvar->size;
+
+    struct SimpleNode *ptr = thisvar->bucket[hashkey];
+    while (ptr) {
+        if (ptr->key == key) {
+            /* we already have thisvar object
+               stored in the hash so just return */
+            return true;
+        }
+        ptr = ptr->next;
+    }
+    return false;
+}
+
+bool SimpleHashcontainskeydata(struct SimpleHash *thisvar, int key, int data) {
+    unsigned int hashkey = (unsigned int)key % thisvar->size;
+
+    struct SimpleNode *ptr = thisvar->bucket[hashkey];
+    while (ptr) {
+        if (ptr->key == key && ptr->data == data) {
+            /* we already have thisvar object
+               stored in the hash so just return*/
+            return true;
+        }
+        ptr = ptr->next;
+    }
+    return false;
+}
+
+int SimpleHashcount(struct SimpleHash *thisvar,int key) {
+    unsigned int hashkey = (unsigned int)key % thisvar->size;
+    int count = 0;
+
+    struct SimpleNode *ptr = thisvar->bucket[hashkey];
+    while (ptr) {
+        if (ptr->key == key) {
+            count++;
+        }
+        ptr = ptr->next;
+    }
+    return count;
+}
+
+struct SimpleHash * SimpleHashimageSet(struct SimpleHash *thisvar, int key) {
+  struct SimpleHash * newset=allocateSimpleHash(2*SimpleHashcount(thisvar,key)+4);
+  unsigned int hashkey = (unsigned int)key % thisvar->size;
+
+  struct SimpleNode *ptr = thisvar->bucket[hashkey];
+  while (ptr) {
+    if (ptr->key == key) {
+        SimpleHashadd(newset,ptr->data,ptr->data);
+    }
+    ptr = ptr->next;
+  }
+  return newset;
+}
+
+int SimpleHashget(struct SimpleHash *thisvar, int key, int *data) {
+    unsigned int hashkey = (unsigned int)key % thisvar->size;
+
+    struct SimpleNode *ptr = thisvar->bucket[hashkey];
+    while (ptr) {
+        if (ptr->key == key) {
+            *data = ptr->data;
+            return 1; /* success */
+        }
+        ptr = ptr->next;
+    }
+
+    return 0; /* failure */
+}
+
+int SimpleHashcountdata(struct SimpleHash *thisvar,int data) {
+    int count = 0;
+    struct ArraySimple *ptr = thisvar->listhead;
+    while(ptr) {
+      if (ptr->nextarray) {
+          int i;
+          for(i=0;i<ARRAYSIZE;i++)
+              if (ptr->nodes[i].data == data
+                  &&ptr->nodes[i].inuse) {
+                  count++;
+              }
+      } else {
+          int i;
+          for(i=0;i<thisvar->tailindex;i++)
+              if (ptr->nodes[i].data == data
+                  &&ptr->nodes[i].inuse) {
+                  count++;
+              }
+      }
+      ptr = ptr->nextarray;
+    }
+    return count;
+}
+
+struct RepairHashNode * allocateRepairHashNode(int setrelation, int rule, int lvalue, int rvalue, int data, int data2, int ismodify){
+    struct RepairHashNode * thisvar=(struct RepairHashNode *)malloc(sizeof(struct RepairHashNode));
+    thisvar->setrelation = setrelation;
+    thisvar->lvalue=lvalue;
+    thisvar->rvalue=rvalue;
+    thisvar->data = data;
+    thisvar->data2 = data2;
+    thisvar->next = 0;
+    thisvar->lnext=0;
+    thisvar->rule=rule;
+    thisvar->ismodify=ismodify;
+    return thisvar;
+}
+
+struct RepairHash * allocateRepairHash(int size) {
+    struct RepairHash *thisvar=(struct RepairHash*)malloc(sizeof(struct RepairHash));
+    if (size <= 0) {
+        printf("Negative size for RepairHash\n");
+        exit(-1);
+    }
+
+    thisvar->size = size;
+    thisvar->bucket = (struct RepairHashNode **) calloc(1,sizeof(struct RepairHashNode*)*size);
+    thisvar->nodelist=0;
+    thisvar->numelements = 0;
+    return thisvar;
+}
+
+#define REPAIRSIZE 100
+struct RepairHash * noargallocateRepairHash() {
+    return allocateRepairHash(REPAIRSIZE);
+}
+
+void freeRepairHash(struct RepairHash *thisvar) {
+  struct RepairHashNode *ptr=thisvar->nodelist;
+  free(thisvar->bucket);
+  while(ptr) {
+      struct RepairHashNode *next=ptr->lnext;
+      free(ptr);
+      ptr=next;
+  }
+  free(thisvar);
+}
+
+#define SETFLAG (1<<31)
+
+int addset(struct RepairHash *thisvar, int setv, int rule, int value, int data) {
+  return addrelation(thisvar, setv||SETFLAG, rule, value,0,data);
+}
+
+int addrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue, int data) {
+    unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
+
+    struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
+
+    /* check that thisvar key/object pair isn't already here */
+    /* TBD can be optimized for set v. relation */
+    while (*ptr) {
+        if ((*ptr)->setrelation == relation &&
+           (*ptr)->rule==rule &&
+           (*ptr)->lvalue==lvalue &&
+           (*ptr)->rvalue==rvalue &&
+           (*ptr)->data == data&&
+           (*ptr)->data2 == 0) {
+            return 0;
+        }
+        ptr = &((*ptr)->next);
+    }
+
+    *ptr = allocateRepairHashNode(relation,rule,lvalue,rvalue, data,0,0);
+    (*ptr)->lnext=thisvar->nodelist;
+    thisvar->nodelist=*ptr;
+    thisvar->numelements++;
+    return 1;
+}
+
+int addrelation2(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue, int data, int data2) {
+    unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
+
+    struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
+
+    /* check that thisvar key/object pair isn't already here */
+    /* TBD can be optimized for set v. relation */
+    while (*ptr) {
+        if ((*ptr)->setrelation == relation &&
+           (*ptr)->rule==rule &&
+           (*ptr)->lvalue==lvalue &&
+           (*ptr)->rvalue==rvalue &&
+           (*ptr)->data == data &&
+           (*ptr)->data2 == data2) {
+            return 0;
+        }
+        ptr = &((*ptr)->next);
+    }
+
+    *ptr = allocateRepairHashNode(relation,rule,lvalue,rvalue, data,data2,1);
+    (*ptr)->lnext=thisvar->nodelist;
+    thisvar->nodelist=*ptr;
+    thisvar->numelements++;
+    return 1;
+}
+
+bool containsset(struct RepairHash *thisvar, int setv, int rule, int value) {
+  return containsrelation(thisvar, setv||SETFLAG, rule, value,0);
+}
+
+bool containsrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue) {
+    unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
+
+    struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
+
+    /* check that thisvar key/object pair isn't already here */
+    /*  TBD can be optimized for set v. relation */
+    while (*ptr) {
+        if ((*ptr)->setrelation == relation &&
+           (*ptr)->rule==rule &&
+           (*ptr)->lvalue==lvalue &&
+           (*ptr)->rvalue==rvalue) {
+            return true;
+        }
+        ptr = &((*ptr)->next);
+    }
+    return false;
+}
+
+int getset(struct RepairHash *thisvar, int setv, int rule, int value) {
+  return getrelation(thisvar, setv||SETFLAG, rule, value,0);
+}
+
+int ismodify(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
+    unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
+
+    struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
+
+    /* check that thisvar key/object pair isn't already here */
+    /* TBD can be optimized for set v. relation */
+    while (*ptr) {
+        if ((*ptr)->setrelation == relation &&
+           (*ptr)->rule==rule &&
+           (*ptr)->lvalue==lvalue &&
+           (*ptr)->rvalue==rvalue) {
+         return (*ptr)->ismodify;
+        }
+        ptr = &((*ptr)->next);
+    }
+    return 0;
+}
+
+int getrelation2(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
+    unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
+
+    struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
+
+    /* check that thisvar key/object pair isn't already here */
+    /* TBD can be optimized for set v. relation */
+    while (*ptr) {
+        if ((*ptr)->setrelation == relation &&
+           (*ptr)->rule==rule &&
+           (*ptr)->lvalue==lvalue &&
+           (*ptr)->rvalue==rvalue) {
+         return (*ptr)->data2;
+        }
+        ptr = &((*ptr)->next);
+    }
+    return 0;
+}
+
+int getrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
+    unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
+
+    struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
+
+    /* check that this key/object pair isn't already here */
+    /* TBD can be optimized for set v. relation */
+    while (*ptr) {
+        if ((*ptr)->setrelation == relation &&
+           (*ptr)->rule==rule &&
+           (*ptr)->lvalue==lvalue &&
+           (*ptr)->rvalue==rvalue) {
+         return (*ptr)->data;
+        }
+        ptr = &((*ptr)->next);
+    }
+    return 0;
+}
index 094c963d2c246e05c9e81706b0df6cf50a9d7cab..e87ed7b655ef024acde9beccda0f7b4507a4ab03 100755 (executable)
 #ifndef SIMPLEHASH_H
 #define SIMPLEHASH_H
 
 #ifndef SIMPLEHASH_H
 #define SIMPLEHASH_H
 
-/* LinkedHashNode *****************************************************/
+#ifndef bool
+#define bool int
+#endif
 
 
-class LinkedHashNode {
-    
-public:
-    LinkedHashNode *next;
-    LinkedHashNode *lnext,*lprev;
-    int data;
-    int key;  
+#ifndef true
+#define true 1
+#endif
+
+#ifndef false
+#define false 0
+#endif
+
+
+#include <stdarg.h>
+#include <stdlib.h>
 
 
+/* LinkedHashNode *****************************************************/
 
 
-    LinkedHashNode(int key, int data, LinkedHashNode *next);
-    LinkedHashNode();
+struct LinkedHashNode * allocateLinkedHashNode(int key, int data, struct LinkedHashNode *next);
+struct LinkedHashNode * noargallocateLinkedHashNode();
 
 
+struct LinkedHashNode {
+    struct LinkedHashNode *next;
+    struct LinkedHashNode *lnext,*lprev;
+    int data;
+    int key;
 };
 
 /* SimpleList *********************************************************/
 
 };
 
 /* SimpleList *********************************************************/
 
-class SimpleList {
-private:
-    LinkedHashNode head;
-    LinkedHashNode *ptr;
-public:
-    SimpleList();
-    void add(int data);
-    int contains(int data);
-    void reset();
-    int hasMoreElements();
-    int nextElement();
+struct SimpleList * allocateSimpleList();
+void SimpleListadd(struct SimpleList *, int data);
+int SimpleListcontains(struct SimpleList *,int data);
+void SimpleListreset(struct SimpleList *);
+int SimpleListhasMoreElements(struct SimpleList *);
+int SimpleListnextElement(struct SimpleList *);
+
+struct SimpleList {
+    struct LinkedHashNode head;
+    struct LinkedHashNode *ptr;
 };
 
 
 /* WorkList *********************************************************/
 #define WLISTSIZE 4*100
 
 };
 
 
 /* WorkList *********************************************************/
 #define WLISTSIZE 4*100
 
-class WorkList {
-private:
+struct WorkList * allocateWorkList();
+void freeWorkList(struct WorkList *);
+void WorkListreset(struct WorkList *);
+void WorkListadd(struct WorkList *,int id, int type, int lvalue, int rvalue);
+int WorkListhasMoreElements(struct WorkList *);
+int WorkListgetid(struct WorkList *);
+int WorkListgettype(struct WorkList *);
+int WorkListgetlvalue(struct WorkList *);
+int WorkListgetrvalue(struct WorkList *);
+void WorkListpop(struct WorkList *);
+
+
+struct WorkList {
   struct ListNode *head;
   struct ListNode *tail;
   int headoffset;
   int tailoffset;
   struct ListNode *head;
   struct ListNode *tail;
   int headoffset;
   int tailoffset;
-
-public:
-    WorkList();
-    ~WorkList();
-    void reset();
-    void add(int id, int type, int lvalue, int rvalue);
-    int hasMoreElements();
-    int getid();
-    int gettype();
-    int getlvalue();
-    int getrvalue();
-    void pop();
 };
 
 struct ListNode {
   int data[WLISTSIZE];
 };
 
 struct ListNode {
   int data[WLISTSIZE];
-  ListNode *next;
+  struct ListNode *next;
 };
 };
+
 /* SimpleHash *********************************************************/
 /* SimpleHash *********************************************************/
-class SimpleIterator;
 
 
-class SimpleHash {
-private:
+struct SimpleHash * noargallocateSimpleHash();
+struct SimpleHash * allocateSimpleHash(int size);
+void SimpleHashaddChild(struct SimpleHash *thisvar, struct SimpleHash * child);
+void freeSimpleHash(struct SimpleHash *);
+
+
+int SimpleHashadd(struct SimpleHash *, int key, int data);
+int SimpleHashremove(struct SimpleHash *,int key, int data);
+bool SimpleHashcontainskey(struct SimpleHash *,int key);
+bool SimpleHashcontainskeydata(struct SimpleHash *,int key, int data);
+int SimpleHashget(struct SimpleHash *,int key, int* data);
+int SimpleHashcountdata(struct SimpleHash *,int data);
+void SimpleHashaddParent(struct SimpleHash *,struct SimpleHash* parent);
+int SimpleHashfirstkey(struct SimpleHash *);
+struct SimpleIterator* SimpleHashcreateiterator(struct SimpleHash *, struct SimpleHash *);
+void SimpleHashiterator(struct SimpleHash *, struct SimpleIterator * it);
+int SimpleHashcount(struct SimpleHash *, int key);
+void SimpleHashaddAll(struct SimpleHash *, struct SimpleHash * set);
+struct SimpleHash * SimpleHashimageSet(struct SimpleHash *, int key);
+
+struct SimpleHash {
     int numelements;
     int size;
     struct SimpleNode **bucket;
     struct ArraySimple *listhead;
     struct ArraySimple *listtail;
     int numelements;
     int size;
     struct SimpleNode **bucket;
     struct ArraySimple *listhead;
     struct ArraySimple *listtail;
-
-
     int numparents;
     int numchildren;
     int numparents;
     int numchildren;
-    SimpleHash* parents[10];
-    SimpleHash* children[10];
-    void addChild(SimpleHash* child);
-public:
+    struct SimpleHash* parents[10];
+    struct SimpleHash* children[10];
     int tailindex;
     int tailindex;
-    SimpleHash(int size=100);
-    ~SimpleHash();
-    int add(int key, int data);
-    int remove(int key, int data);
-    bool contains(int key);
-    bool contains(int key, int data);
-    int get(int key, int& data);
-    int countdata(int data);
-    void addParent(SimpleHash* parent);
-    int firstkey();
-    SimpleIterator* iterator();
-    void iterator(SimpleIterator & it);
-    inline int count() {
-        return numelements;
-    }
-    int count(int key);
-    void addAll(SimpleHash * set);
-    SimpleHash * imageSet(int key);
 };
 
 };
 
+inline int count(struct SimpleHash * thisvar) {
+    return thisvar->numelements;
+}
+
+
 /* SimpleHashExcepion  *************************************************/
 
 
 /* SimpleHashExcepion  *************************************************/
 
 
@@ -108,7 +120,7 @@ public:
 struct SimpleNode {
   struct SimpleNode *next;
   int data;
 struct SimpleNode {
   struct SimpleNode *next;
   int data;
-  int key;  
+  int key;
   int inuse;
 };
 
   int inuse;
 };
 
@@ -118,91 +130,83 @@ struct ArraySimple {
 };
 
 
 };
 
 
-class SimpleIterator {
- public:
-
+struct SimpleIterator {
   struct ArraySimple *cur, *tail;
   int index,tailindex;
   struct ArraySimple *cur, *tail;
   int index,tailindex;
-  //  SimpleHash * table;
-  inline SimpleIterator() {}
-
-  inline SimpleIterator(struct ArraySimple *start, struct ArraySimple *tl, int tlindex/*, SimpleHash *t*/) {
-    cur = start;
-    //    table=t;
-    index=0;
-    tailindex=tlindex;
-    tail=tl;
-  }
-
-  inline int hasNext() {
-    if (cur==tail &&
-       index==tailindex)
-      return 0;
-    while((index==ARRAYSIZE)||!cur->nodes[index].inuse) {
-      if (index==ARRAYSIZE) {
-       index=0;
-       cur=cur->nextarray;
-      } else
-       index++;
+};
+
+inline struct SimpleIterator * noargallocateSimpleIterator() {
+    return (struct SimpleIterator*)malloc(sizeof(struct SimpleIterator));
+}
+
+inline struct SimpleIterator * allocateSimpleIterator(struct ArraySimple *start, struct ArraySimple *tl, int tlindex) {
+    struct SimpleIterator *thisvar=(struct SimpleIterator*)malloc(sizeof(struct SimpleIterator));
+    thisvar->cur = start;
+    thisvar->index=0;
+    thisvar->tailindex=tlindex;
+    thisvar->tail=tl;
+    return thisvar;
+}
+
+inline int hasNext(struct SimpleIterator *thisvar) {
+    if (thisvar->cur==thisvar->tail &&
+       thisvar->index==thisvar->tailindex)
+        return 0;
+    while((thisvar->index==ARRAYSIZE)||!thisvar->cur->nodes[thisvar->index].inuse) {
+        if (thisvar->index==ARRAYSIZE) {
+            thisvar->index=0;
+            thisvar->cur=thisvar->cur->nextarray;
+        } else
+            thisvar->index++;
     }
     }
-    if (cur->nodes[index].inuse)
-      return 1;
+    if (thisvar->cur->nodes[thisvar->index].inuse)
+        return 1;
     else
     else
-      return 0;
-  }
-
-  inline int next() {
-    return cur->nodes[index++].data;
-  }
-  
-  inline int key() {
-    return cur->nodes[index].key;
-  }
-};
+        return 0;
+}
 
 
-/* SimpleHashExcepion  *************************************************/
+inline int next(struct SimpleIterator *thisvar) {
+    return thisvar->cur->nodes[thisvar->index++].data;
+}
 
 
-class SimpleHashException {
-public:
-    SimpleHashException();
-};
+inline int key(struct SimpleIterator *thisvar) {
+    return thisvar->cur->nodes[thisvar->index].key;
+}
+
+
+struct RepairHashNode * allocateRepairHashNode(int setrelation, int rule, int lvalue, int rvalue, int data, int data2,int ismodify);
 
 
-class RepairHashNode {
- public:
-    RepairHashNode *next;
-    RepairHashNode *lnext;
+struct RepairHashNode {
+    struct RepairHashNode *next;
+    struct RepairHashNode *lnext;
     int data;
     int data2;
     int data;
     int data2;
-    int setrelation;  
-    int lvalue;  
-    int rvalue;  
+    int setrelation;
+    int lvalue;
+    int rvalue;
     int rule;
     int ismodify;
     int rule;
     int ismodify;
-    RepairHashNode(int setrelation, int rule, int lvalue, int rvalue, int data, int data2,int ismodify);
 };
 
 };
 
-class RepairHash {
-
-private:
+struct RepairHash * noargallocateRepairHash();
+struct RepairHash * allocateRepairHash(int size);
+void freeRepairHash(struct RepairHash *);
+int addset(struct RepairHash *, int setv, int rule, int value, int data);
+int addrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue, int data);
+int addrelation2(struct RepairHash *, int relation, int rule, int lvalue, int rvalue, int data, int data2);
+bool containsset(struct RepairHash *, int setv, int rule, int value);
+bool containsrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
+int getset(struct RepairHash *, int setv, int rule, int value);
+int getrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
+int getrelation2(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
+int ismodify(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
+
+struct RepairHash {
     int numelements;
     int size;
     int numelements;
     int size;
-    RepairHashNode **bucket;
-    RepairHashNode *nodelist;
-
-public:
-    RepairHash();
-    RepairHash(int size);
-    ~RepairHash();
-    int addset(int setv, int rule, int value, int data);
-    int addrelation(int relation, int rule, int lvalue, int rvalue, int data);
-    int addrelation(int relation, int rule, int lvalue, int rvalue, int data, int data2);
-    bool containsset(int setv, int rule, int value);
-    bool containsrelation(int relation, int rule, int lvalue, int rvalue);
-    int getset(int setv, int rule, int value);
-    int getrelation(int relation, int rule, int lvalue, int rvalue);
-    int getrelation2(int relation, int rule, int lvalue, int rvalue);
-    int ismodify(int relation, int rule, int lvalue, int rvalue);
+    struct RepairHashNode **bucket;
+    struct RepairHashNode *nodelist;
+
 };
 
 #endif
 };
 
 #endif
-
index 1d69d05e08b727c178bf81d89518ad6f5cd0bea2..c056fb6832e06000d224f82e0cd23b01e7980bb2 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/bash
 #!/bin/bash
-FLAG='-O0 -g'
-g++ $FLAG -c SimpleHash.cc
-g++ $FLAG -c tmap.cc
-g++ $FLAG -c instrument.cc
+FLAG='-O0 -g -pedantic'
+gcc $FLAG -c SimpleHash.c
+gcc $FLAG -c tmap.c
+gcc $FLAG -c instrument.c
 gcc $FLAG -c libredblack/redblack.c
 gcc $FLAG -c stack.c
 gcc $FLAG -c libredblack/redblack.c
 gcc $FLAG -c stack.c
-g++ $FLAG -c size.cc
+
index 1fbfcc7f719b4d507dd798e9c6cbc40068982c48..c04c1af64a956af949359dbc51d7cea866033b5d 100755 (executable)
@@ -1,7 +1,4 @@
 #ifndef CLASSLIST_H
 #define CLASSLIST_H
 
 #ifndef CLASSLIST_H
 #define CLASSLIST_H
 
-class typeobject;
-class typemap;
-class structuremap;
 #endif
 #endif
diff --git a/Repair/RepairCompiler/MCC/Runtime/instrument.c b/Repair/RepairCompiler/MCC/Runtime/instrument.c
new file mode 100755 (executable)
index 0000000..66aef0d
--- /dev/null
@@ -0,0 +1,69 @@
+/* Defines interfaces for the applications and exports function calls that
+   the applications should use instead of the standard ones. */
+
+#include <stdlib.h>
+#include <sys/time.h>
+
+#include "instrument.h"
+#include <stdio.h>
+#include "tmap.h"
+#include "size.h"
+
+struct typemap * memmap;
+
+void *ourcalloc(size_t nmemb, size_t size) {
+  void *oc=calloc(nmemb,size);
+  typemapallocate(memmap, oc,size*nmemb);
+  return oc;
+}
+
+void *ourmalloc(size_t size) {
+  void *oc=malloc(size);
+  typemapallocate(memmap, oc,size);
+  return oc;
+}
+
+void ourfree(void *ptr) {
+  typemapdeallocate(memmap, ptr);
+  free(ptr);
+}
+
+void *ourrealloc(void *ptr, size_t size) {
+  void *orr=realloc(ptr,size);
+  if (size==0) {
+    typemapdeallocate(memmap, ptr);
+    return orr;
+  }
+  if (orr==NULL) {
+    return orr;
+  }
+  typemapdeallocate(memmap, ptr);
+  typemapallocate(memmap, ptr,size);
+}
+
+void alloc(void *ptr,int size) {
+  typemapallocate(memmap, ptr,size);
+}
+
+void dealloc(void *ptr) {
+  typemapdeallocate(memmap, ptr);
+}
+
+void initializemmap() {
+  memmap=allocatetypemap();
+}
+
+void resettypemap() {
+  typemapreset(memmap);
+}
+
+bool assertvalidtype(int ptr, int structure) {
+  return typemapasserttype(memmap, (void *)ptr, structure);
+}
+bool assertvalidmemory(int ptr, int structure) {
+  return typemapassertvalidmemory(memmap, (void *)ptr, structure);
+}
+
+void initializestack(void *high) {
+  initializetypemapstack(memmap, high);
+}
index 60376821f86d731947db26702b15f8f87d0685a0..7709e054da092fe22117ad83170a6215104fc753 100755 (executable)
@@ -1,4 +1,4 @@
-/* Defines interfaces for the applications and exports function calls that  
+/* Defines interfaces for the applications and exports function calls that
    the applications should use instead of the standard ones. */
 
 #ifndef INSTRUMENT_H
    the applications should use instead of the standard ones. */
 
 #ifndef INSTRUMENT_H
@@ -6,6 +6,10 @@
 #include "classlist.h"
 #include <stdlib.h>
 
 #include "classlist.h"
 #include <stdlib.h>
 
+#ifndef bool
+#define bool int
+#endif
+
 void alloc(void *ptr,int size);
 void dealloc(void *ptr);
 void *ourcalloc(size_t nmemb, size_t size);
 void alloc(void *ptr,int size);
 void dealloc(void *ptr);
 void *ourcalloc(size_t nmemb, size_t size);
@@ -13,10 +17,9 @@ void *ourmalloc(size_t size);
 void ourfree(void *ptr);
 void *ourrealloc(void *ptr, size_t size);
 void initializemmap();
 void ourfree(void *ptr);
 void *ourrealloc(void *ptr, size_t size);
 void initializemmap();
-typeobject * gettypeobject();
 void resettypemap();
 bool assertvalidtype(int ptr, int structure);
 bool assertvalidmemory(int ptr, int structure);
 void initializestack(void *);
 void resettypemap();
 bool assertvalidtype(int ptr, int structure);
 bool assertvalidmemory(int ptr, int structure);
 void initializestack(void *);
-extern typemap * memmap;
+extern struct typemap * memmap;
 #endif
 #endif
index e2fff80406e8ebe971787df67880f21716c4b66a..3a1c76b81fcb1e4c350c7825458236e945b002f8 100755 (executable)
@@ -1,8 +1,7 @@
 #ifndef MEMORY_H
 #define MEMORY_H
 #ifndef MEMORY_H
 #define MEMORY_H
-extern "C" {
 #include "instrument.h"
 #include "instrument.h"
-}
+
 #define malloc(size) ourmalloc(size)
 #define calloc(memb,size) ourcalloc(memb,size)
 #define realloc(ptr,size) ourrealloc(ptr,size)
 #define malloc(size) ourmalloc(size)
 #define calloc(memb,size) ourcalloc(memb,size)
 #define realloc(ptr,size) ourrealloc(ptr,size)
diff --git a/Repair/RepairCompiler/MCC/Runtime/size.h b/Repair/RepairCompiler/MCC/Runtime/size.h
new file mode 100755 (executable)
index 0000000..5b11610
--- /dev/null
@@ -0,0 +1,10 @@
+struct foo_state {int l;};
+int getfield(int type, int fieldindex);
+int isArray(int type, int fieldindex);
+int isPtr(int type, int fieldindex);
+int numElements(int type, int fieldindex);
+int size(int type);
+int sizeBytes(int type);
+int getnumfields(int type);
+bool issubtype(int subtype, int type);
+void computesizes(struct foo_state *);
index 838293d642c3dfd2baa3a9153a8d9a40dfe4b523..c9586dc54d84b63ed3171e31ad1d510745b76a6f 100755 (executable)
@@ -11,7 +11,7 @@ Permission is hereby granted to use or copy this program
 for any purpose,  provided the above notices are retained on all copies.
 Permission to modify the code and to distribute modified code is granted,
 provided the above notices are retained, and a notice that the code was
 for any purpose,  provided the above notices are retained on all copies.
 Permission to modify the code and to distribute modified code is granted,
 provided the above notices are retained, and a notice that the code was
-modified is included with the above copyright notice.   
+modified is included with the above copyright notice.
  */
 
 
  */
 
 
@@ -19,6 +19,9 @@ modified is included with the above copyright notice.
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <ctype.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <ctype.h>
+#include <stdio.h>
+#include <unistd.h>
+
 #define ptr_t void *
 #pragma weak __libc_stack_end
 extern ptr_t __libc_stack_end;
 #define ptr_t void *
 #pragma weak __libc_stack_end
 extern ptr_t __libc_stack_end;
@@ -31,7 +34,7 @@ extern ptr_t __libc_stack_end;
   {
     /* We read the stack base value from /proc/self/stat.  We do this  */
     /* using direct I/O system calls in order to avoid calling malloc   */
   {
     /* We read the stack base value from /proc/self/stat.  We do this  */
     /* using direct I/O system calls in order to avoid calling malloc   */
-    /* in case REDIRECT_MALLOC is defined.                             */ 
+    /* in case REDIRECT_MALLOC is defined.                             */
 #   define STAT_BUF_SIZE 4096
 #   define STAT_READ read
          /* Should probably call the real read, if read is wrapped.    */
 #   define STAT_BUF_SIZE 4096
 #   define STAT_READ read
          /* Should probably call the real read, if read is wrapped.    */
@@ -50,7 +53,7 @@ extern ptr_t __libc_stack_end;
            return __libc_stack_end + 0x10;
          } /* Otherwise it's not safe to add 16 bytes and we fall      */
            /* back to using /proc.                                     */
            return __libc_stack_end + 0x10;
          } /* Otherwise it's not safe to add 16 bytes and we fall      */
            /* back to using /proc.                                     */
-#      else 
+#      else
          return __libc_stack_end;
 #      endif
       }
          return __libc_stack_end;
 #      endif
       }
diff --git a/Repair/RepairCompiler/MCC/Runtime/tmap.c b/Repair/RepairCompiler/MCC/Runtime/tmap.c
new file mode 100755 (executable)
index 0000000..2e1a818
--- /dev/null
@@ -0,0 +1,241 @@
+#include <stdio.h>
+#include "tmap.h"
+#include "size.h"
+#include "stack.h"
+#include <stdlib.h>
+
+#define CHECKTYPE
+#define CHECKMEMORY
+
+struct typemap * allocatetypemap() {
+  struct typemap *thisvar=(struct typemap *) malloc(sizeof(struct typemap));
+  thisvar->alloctree=rbinit();
+  thisvar->typetree=rbinit();
+  thisvar->low=GC_linux_stack_base();
+}
+
+void freefunction(void *ptr) {
+  if(ptr!=NULL) {
+    free((struct structuremap *)ptr);
+  }
+}
+
+void freetypemap(struct typemap * ptr) {
+  rbdestroy(ptr->typetree,freefunction);
+  rbdestroy(ptr->alloctree,freefunction);
+  free(ptr);
+}
+
+void typemapreset(struct typemap *ptr) {
+  rbdestroy(ptr->typetree,freefunction);
+  ptr->typetree=rbinit();
+  if (ptr->low<ptr->high)
+    rbdelete(ptr->low,ptr->alloctree);
+  else
+    rbdelete(ptr->high,ptr->alloctree);
+}
+
+void initializetypemapstack(struct typemap * ptr, void *high) {
+  ptr->high=high;
+  if (ptr->low<ptr->high)
+    rbinsert(ptr->low,ptr->high,NULL,ptr->alloctree);
+  else
+    rbinsert(ptr->high,ptr->low,NULL,ptr->alloctree);
+}
+
+struct structuremap * allocatestructuremap(int s) {
+  struct structuremap *ptr=(struct structuremap *)malloc(sizeof(struct structuremap));
+  ptr->str=s;
+  ptr->typetree=rbinit();
+  return ptr;
+}
+
+void freestructuremap(struct structuremap *ptr) {
+  rbdestroy(ptr->typetree,freefunction);
+  free(ptr);
+}
+
+bool typemapasserttype(struct typemap *thisvar, void *ptr, int s) {
+  int toadd=sizeBytes(s);
+  return typemapasserttypeB(thisvar, ptr,((char *) ptr)+toadd,s);
+}
+
+bool typemapasserttypeB(struct typemap * thisvar, void *ptr, void *high, int s) {
+#ifdef CHECKTYPE
+  bool b=typemapchecktype(thisvar,true,ptr,s);
+  if (!b) {
+    printf("Assertion failure\n");
+    {
+      bool testb=typemapchecktype(thisvar,true,ptr,s);
+    }
+  }
+  return b;
+#endif
+  return typemapassertvalidmemoryB(thisvar,ptr, high);
+}
+
+bool typemapassertvalidmemory(struct typemap * thisvar, void* low, int s) {
+  int toadd=sizeBytes(s);
+  return typemapassertvalidmemoryB(thisvar, low,((char *)low)+toadd);
+}
+
+bool typemapassertvalidmemoryB(struct typemap * thisvar, void* low, void* high) {
+#ifdef CHECKMEMORY
+  return typemapcheckmemory(thisvar, low, high);
+#endif
+  return true;
+}
+
+bool typemapistype(struct typemap *thisvar, void *ptr, void *high, int s) {
+#ifdef CHECKTYPE
+  bool b=typemapchecktype(thisvar, false,ptr,s);
+  if (!b) {
+    printf("Verify failure\n");
+    {
+      bool testb=typemapchecktype(thisvar, false,ptr,s);
+    }
+  }
+  return b;
+#endif
+  return typemapassertvalidmemoryB(thisvar, ptr, high);
+}
+
+void typemapallocate(struct typemap *thisvar,void *ptr, int size) {
+  void *low=ptr;
+  void *high=((char *)ptr)+size;
+  int val=rbinsert(low,high,NULL,thisvar->alloctree);
+  if (val==0)
+    printf("Error\n");
+}
+
+inline int sizeinbytes(unsigned int bits) {
+  int bytes=bits>>3;
+  if (bits %8)
+    bytes++;
+  return bytes;
+}
+
+int typemapfindoffsetstructure(struct typemap * thisvar, int s, int offset) {
+  int count=0;
+  int i;
+  int increment;
+  for(i=0;i<getnumfields(s);i++) {
+    int mult=1;
+    int ttype=getfield(s,i);
+    if (isArray(s,i)) {
+      mult=numElements(s,i);
+    }
+    increment=size(ttype);
+    if (increment%8) {
+      int delt=offset-count;
+      int byteincrement=increment/8;
+      if (delt<mult*byteincrement) {
+       if (delt%byteincrement==0) {
+         return ttype;
+       } else
+         return -1;
+      }
+    } else {
+      if ((count+sizeinbytes(mult*increment))>offset)
+       return -1;
+    }
+    count+=sizeinbytes(mult*increment);
+  }
+  return -1;
+}
+
+void typemapdeallocate(struct typemap * thisvar,void *ptr) {
+  if (rbdelete(ptr,thisvar->alloctree)==NULL)
+    printf("Freeing unallocated memory\n");
+}
+
+bool typemapcheckmemory(struct typemap *thisvar, void* low, void* high) {
+  struct pair allocp=rbfind(low,high,thisvar->alloctree);
+  if (allocp.low == NULL) {
+    return false;
+  } else if ((allocp.low > low) || (allocp.high < high)) { /* make sure this block is used */
+    return false;
+  } else {
+    return true;
+  }
+}
+
+
+bool typemapchecktype(struct typemap *thisvar, bool doaction,void *ptr, int structure) {
+  int ssize=sizeBytes(structure);
+  void *low=ptr;
+  void *high=((char *)low)+ssize;
+  struct pair allocp=rbfind(low,high,thisvar->alloctree);
+  if (allocp.low==NULL)
+    return false;
+  if (allocp.low>low||allocp.high<high) /* make sure this block is used */
+    return false;
+  {
+    struct pair typep=rbfind(low,high,thisvar->typetree);
+    struct structuremap *smap=(struct structuremap *)rblookup(low,high,thisvar->typetree);
+    if (typep.low==NULL) {
+      if(!doaction)
+        return true;
+      {
+        struct structuremap *sm=allocatestructuremap(structure);
+        int flag=rbinsert(low, high, sm, thisvar->typetree);
+        if (flag==0) {
+          printf("Error in asserttype\n");
+          return false;
+        } else
+          return true;
+      }
+    }
+    return typemapchecktypeB(thisvar, doaction, low,high, structure, thisvar->typetree);
+  }
+}
+
+bool typemapchecktypeB(struct typemap *thisvar, bool doaction, void *low, void *high, int structure, struct rbtree *ttree) {
+  struct pair typep=rbfind(low,high,ttree);
+  struct structuremap *smap=(struct structuremap *)rblookup(low,high,ttree);
+  if (typep.low==low&&typep.high==high) {
+    /* Recast */
+    if (issubtype(structure,smap->str)) {
+      /* narrowing cast */
+      if (!doaction)
+       return true;
+      smap->str=structure;
+      return true;
+    } else if (issubtype(smap->str,structure)) {
+      /* widening cast */
+      return true;
+    } else
+      return false; /* incompatible types */
+  } else if (typep.low<=low&&typep.high>=high) {
+    /* See if it matches up with structure inside typep */
+    if (rbsearch(low,high,smap->typetree)) {
+      /* recurse */
+      return typemapchecktypeB(thisvar,doaction,low,high, structure, smap->typetree);
+    } else {
+      /* check to see if data lines up correctly */
+      int offset=((char *)low)-((char *)typep.low);
+      int st=typemapfindoffsetstructure(thisvar, smap->str,offset);
+      if (st==-1)
+       return false;
+      if (issubtype(structure,st)) {
+       if (!doaction)
+         return true;
+        {
+          struct structuremap *newsm=allocatestructuremap(structure);
+          int flag=rbinsert(low, high, newsm, smap->typetree);
+          return (flag==1);
+        }
+      } else if (issubtype(st,structure)) {
+       if (!doaction)
+         return true;
+        {
+          struct structuremap *newsm=allocatestructuremap(st);
+          int flag=rbinsert(low, high, newsm, smap->typetree);
+          return (flag==1);
+        }
+      } else
+       return false;
+    }
+  } else
+    return false;
+}
index 85f8619f044d5acc251178c42e3133470578f97d..535ecc56ec383f9d984560795c820f0de3d57852 100755 (executable)
@@ -1,36 +1,49 @@
 #ifndef TMAP_H
 #define TMAP_H
 #include "classlist.h"
 #ifndef TMAP_H
 #define TMAP_H
 #include "classlist.h"
+#include "redblack.h"
 
 
-class typemap {
- public:
-  typemap(typeobject *);
-  ~typemap();
-  void allocate(void *, int);
-  void deallocate(void *);
-  bool assertvalidmemory(void* low, void* high);
-  bool asserttype(void *ptr, void *high, int structure);
-  bool assertvalidmemory(void* low, int structure);
-  bool asserttype(void *ptr, int structure);
-  bool istype(void *ptr, void *high, int structure);
-  void reset();
-  typeobject *size;
-  void initializestack(void *high);
- private:
+#ifndef bool
+#define bool int
+#endif
+
+#ifndef true
+#define true 1
+#endif
+
+#ifndef false
+#define false 0
+#endif
+
+struct typemap * allocatetypemap();
+void freetypemap(struct typemap *);
+void typemapreset(struct typemap *);
+void initializetypemapstack(struct typemap *, void *high);
+
+void typemapallocate(struct typemap *, void *, int);
+void typemapdeallocate(struct typemap *, void *);
+bool typemapassertvalidmemoryB(struct typemap *, void* low, void* high);
+bool typemapasserttypeB(struct typemap *, void *ptr, void *high, int structure);
+bool typemapassertvalidmemory(struct typemap *, void* low, int structure);
+bool typemapasserttype(struct typemap *, void *ptr, int structure);
+bool typemapistype(struct typemap *, void *ptr, void *high, int structure);
+bool typemapcheckmemory(struct typemap *, void* low, void* high);
+bool typemapchecktype(struct typemap *, bool doaction,void *ptr, int structure);
+bool typemapchecktypeB(struct typemap *, bool doaction, void *low, void *high,int structure, struct rbtree *ttree);
+int typemapfindoffsetstructure(struct typemap *, int s, int offset);
+
+
+struct typemap {
   void *low;
   void *high;
   void *low;
   void *high;
-  bool checkmemory(void* low, void* high);
-  bool checktype(bool doaction,void *ptr, int structure);
-  bool checktype(bool doaction, void *low, void *high,int structure, struct rbtree *ttree);
-  int findoffsetstructure(int s, int offset);
   struct rbtree *alloctree;
   struct rbtree *typetree;
 };
 
   struct rbtree *alloctree;
   struct rbtree *typetree;
 };
 
-class structuremap {
-  public:
-  structuremap(int s);
-  ~structuremap();
+struct structuremap * allocatestructuremap(int s);
+void freestructuremap(struct structuremap *);
+
+struct structuremap {
   int str;
   struct rbtree *typetree;
 };
   int str;
   struct rbtree *typetree;
 };