From 9c59442d6952a288da481b506db27ce19f6c1098 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 17 May 2004 22:01:36 +0000 Subject: [PATCH] getrelation2 can return 0 in cases of a relation that maps objects to ints. This causes the modify update method to get called in the wrong way...Fixed the bug... --- .../MCC/IR/RepairGenerator.java | 9 +++- .../RepairCompiler/MCC/Runtime/SimpleHash.cc | 49 +++++++++++++++++-- .../RepairCompiler/MCC/Runtime/SimpleHash.h | 4 +- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java index a3b8efd..7921577 100755 --- a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java @@ -1367,7 +1367,11 @@ public class RepairGenerator { cr.startblock(); { /* Have update to call into */ VarDescriptor mdfyptr=VarDescriptor.makeNew("modifyptr"); - cr.outputline("int "+mdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->getrelation2("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); + VarDescriptor ismdfyptr=VarDescriptor.makeNew("ismodifyptr"); + cr.outputline("int "+ismdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->ismodify("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); + + + String parttype=""; for(int i=0;igetrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); - cr.outputline("if ("+mdfyptr.getSafeSymbol()+")"); + cr.outputline("if ("+ismdfyptr.getSafeSymbol()+")"); { cr.startblock(); + cr.outputline("int "+mdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->getrelation2("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+",int,int,int)="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+",int,int,int)) "+tmpptr.getSafeSymbol()+";"); cr.outputline(methodcall+","+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");"); cr.endblock(); diff --git a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc index 25cf6dd..bed5c1f 100755 --- a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc +++ b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.cc @@ -341,7 +341,7 @@ SimpleHashException::SimpleHashException() {} // ************************************************************ -RepairHashNode::RepairHashNode(int setrelation, int rule, int lvalue, int rvalue, int data, int data2){ +RepairHashNode::RepairHashNode(int setrelation, int rule, int lvalue, int rvalue, int data, int data2, int ismodify){ this->setrelation = setrelation; this->lvalue=lvalue; this->rvalue=rvalue; @@ -350,6 +350,7 @@ RepairHashNode::RepairHashNode(int setrelation, int rule, int lvalue, int rvalue this->next = 0; this->lnext=0; this->rule=rule; + this->ismodify=ismodify; } // ************************************************************ @@ -393,7 +394,29 @@ int RepairHash::addset(int setv, int rule, int value, int data) { } int RepairHash::addrelation(int relation, int rule, int lvalue, int rvalue, int data) { - return addrelation(relation,rule,lvalue,rvalue,data, 0); + unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % size; + + RepairHashNode **ptr = &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 && + (*ptr)->data == data&& + (*ptr)->data2 == 0) { + return 0; + } + ptr = &((*ptr)->next); + } + + *ptr = new RepairHashNode(relation,rule,lvalue,rvalue, data,0,0); + (*ptr)->lnext=nodelist; + nodelist=*ptr; + numelements++; + return 1; } int RepairHash::addrelation(int relation, int rule, int lvalue, int rvalue, int data, int data2) { @@ -415,7 +438,7 @@ int RepairHash::addrelation(int relation, int rule, int lvalue, int rvalue, int ptr = &((*ptr)->next); } - *ptr = new RepairHashNode(relation,rule,lvalue,rvalue, data,data2); + *ptr = new RepairHashNode(relation,rule,lvalue,rvalue, data,data2,1); (*ptr)->lnext=nodelist; nodelist=*ptr; numelements++; @@ -449,6 +472,25 @@ int RepairHash::getset(int setv, int rule, int value) { return getrelation(setv||SETFLAG, rule, value,0); } +int RepairHash::ismodify(int relation, int rule, int lvalue,int rvalue) { + unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % size; + + RepairHashNode **ptr = &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)->ismodify; + } + ptr = &((*ptr)->next); + } + return 0; +} + int RepairHash::getrelation2(int relation, int rule, int lvalue,int rvalue) { unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % size; @@ -467,6 +509,7 @@ int RepairHash::getrelation2(int relation, int rule, int lvalue,int rvalue) { } return 0; } + int RepairHash::getrelation(int relation, int rule, int lvalue,int rvalue) { unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % size; diff --git a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.h b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.h index da21f2f..0823fd4 100755 --- a/Repair/RepairCompiler/MCC/Runtime/SimpleHash.h +++ b/Repair/RepairCompiler/MCC/Runtime/SimpleHash.h @@ -175,7 +175,8 @@ class RepairHashNode { int lvalue; int rvalue; int rule; - RepairHashNode(int setrelation, int rule, int lvalue, int rvalue, int data, int data2); + int ismodify; + RepairHashNode(int setrelation, int rule, int lvalue, int rvalue, int data, int data2,int ismodify); }; class RepairHash { @@ -198,6 +199,7 @@ public: 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); }; #endif -- 2.34.1