From 95271a46ce6573ff5532fda46561d2936cb25393 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 12 Aug 2004 21:41:40 +0000 Subject: [PATCH] Improved precision of computation of maximum set sizes. Removed generation of redundant rules by implicitschema. --- .../RepairCompiler/MCC/IR/ComputeMaxSize.java | 271 ++++++++++++++++-- Repair/RepairCompiler/MCC/IR/Expr.java | 7 + .../RepairCompiler/MCC/IR/ImplicitSchema.java | 101 ++++++- 3 files changed, 359 insertions(+), 20 deletions(-) diff --git a/Repair/RepairCompiler/MCC/IR/ComputeMaxSize.java b/Repair/RepairCompiler/MCC/IR/ComputeMaxSize.java index 51221c3..a5a9d57 100755 --- a/Repair/RepairCompiler/MCC/IR/ComputeMaxSize.java +++ b/Repair/RepairCompiler/MCC/IR/ComputeMaxSize.java @@ -7,12 +7,14 @@ import java.util.*; public class ComputeMaxSize { State state; Hashtable sizemap; /* -1 means infinity */ - + static int KBOUND=100; public ComputeMaxSize(State state) { this.state=state; sizemap=new Hashtable(); computesizes(); + postprocess(); + printsizes(); } /** This method compute relation and set maximum sizes */ @@ -28,29 +30,42 @@ public class ComputeMaxSize { Descriptor d=(Descriptor)dit.next(); if (d instanceof ReservedSetDescriptor) continue; - int totalsize=0; + int totalstarts=0; + int totalchains=0; + Rule chainrule=null; for(int i=0;i=KBOUND) + totalstarts=-1; + if (totalchains>=KBOUND) + totalchains=-1; + + if (!sizemap.containsKey(d)||getstarts(d)!=totalstarts||getchains(d)!=totalchains) { change=true; - sizemap.put(d,new Integer(totalsize)); + MaxSizeObject so=new MaxSizeObject(totalstarts,totalchains,chainrule); + sizemap.put(d,so); } } } } + + void printsizes() { + Set descriptorset=new HashSet(); + descriptorset.addAll(state.stSets.getAllDescriptors()); + descriptorset.addAll(state.stRelations.getAllDescriptors()); + for(Iterator dit=descriptorset.iterator();dit.hasNext();) { + Descriptor d=(Descriptor)dit.next(); + if (d instanceof ReservedSetDescriptor) + continue; + System.out.println("size("+d+")="+getsize(d)); + } + } + + private void postprocess() { + Vector rules=state.vRules; + boolean change=true; + Set descriptorset=new HashSet(); + descriptorset.addAll(state.stSets.getAllDescriptors()); + descriptorset.addAll(state.stRelations.getAllDescriptors()); + while(change) { + change=false; + for(Iterator dit=descriptorset.iterator();dit.hasNext();) { + Descriptor d=(Descriptor)dit.next(); + if (d instanceof ReservedSetDescriptor) + continue; + int totalstarts=0; + int totalchains=0; + Rule chainrule=null; + for(int i=0;i=KBOUND) + totalstarts=-1; + if (totalchains>=KBOUND) + totalchains=-1; + + if (!sizemap.containsKey(d)||getstarts(d)!=totalstarts||getchains(d)!=totalchains) { + change=true; + MaxSizeObject so=new MaxSizeObject(totalstarts,totalchains,chainrule); + sizemap.put(d,so); + } + } + } + + } + + int getstarts(Descriptor d) { + MaxSizeObject so=(MaxSizeObject)sizemap.get(d); + return so.maxstarts; + } + int getchains(Descriptor d) { + MaxSizeObject so=(MaxSizeObject)sizemap.get(d); + return so.numberchains; + } int getsize(Descriptor d) { - return ((Integer)sizemap.get(d)).intValue(); + MaxSizeObject so=(MaxSizeObject)sizemap.get(d); + if (so.maxstarts==0) + return 0; + if (so.numberchains!=0) + return -1; + return so.maxstarts; } -} + private Rule getchainrule(Descriptor d) { + MaxSizeObject so=(MaxSizeObject)sizemap.get(d); + return so.chainrule; + } + + public static boolean isMutuallyExclusive(Rule r1,Rule r2) { + // Building a map between quantifier variables + if (r1.numQuantifiers()!=r2.numQuantifiers()) + return false; + Set usedDescriptors=new HashSet(); + Hashtable varmap=new Hashtable(); + + outerloop: + for(int i=0;i