bug fixes
authorbdemsky <bdemsky>
Wed, 18 Jul 2007 19:21:19 +0000 (19:21 +0000)
committerbdemsky <bdemsky>
Wed, 18 Jul 2007 19:21:19 +0000 (19:21 +0000)
Robust/src/Analysis/TaskStateAnalysis/FlagState.java
Robust/src/Analysis/TaskStateAnalysis/TagAnalysis.java
Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java

index 6e122435b5eebe9f685dc31c538c7aacf07a2cd8..78233e15b2b3ef714747dba2fb0a96b70edc74a0 100644 (file)
@@ -115,27 +115,31 @@ public class FlagState extends GraphNode {
        return flagstate.iterator();
     }
     
-    public FlagState setTag(TagDescriptor tag){
-          
-           HashSet newset=(HashSet)flagstate.clone();
-           Hashtable<TagDescriptor,Integer> newtags=(Hashtable<TagDescriptor,Integer>)tags.clone();
+    public FlagState[] setTag(TagDescriptor tag){
+       HashSet newset1=(HashSet)flagstate.clone();
+       Hashtable<TagDescriptor,Integer> newtags1=(Hashtable<TagDescriptor,Integer>)tags.clone();
            
-           if (newtags.containsKey(tag)){
-                  switch (newtags.get(tag).intValue()){
-                          case ONETAG:
-                                       newtags.put(tag,new Integer(MULTITAGS));
-                                       break;
-                          case MULTITAGS:
-                                       newtags.put(tag,new Integer(MULTITAGS));
-                                       break;
-                       }
-               }
-               else{
-                       newtags.put(tag,new Integer(ONETAG));
-               }
-               
-               return new FlagState(newset,cd,newtags);
-                               
+       if (tags.containsKey(tag)){
+           //Code could try to remove flag that doesn't exist
+           
+           HashSet newset2=(HashSet)flagstate.clone();
+           Hashtable<TagDescriptor,Integer> newtags2=(Hashtable<TagDescriptor,Integer>)tags.clone();
+           switch (tags.get(tag).intValue()){
+           case ONETAG:
+               newtags1.put(tag,new Integer(MULTITAGS));
+               break;
+           case MULTITAGS:
+               newtags1.put(tag,new Integer(MULTITAGS));
+               break;
+           default:
+               throw new Error();
+           }
+           return new FlagState[] {new FlagState(newset1,cd,newtags1),
+                                   new FlagState(newset2,cd,newtags2)};
+       } else {
+           newtags1.put(tag,new Integer(ONETAG));
+           return new FlagState[] {new FlagState(newset1,cd,newtags1)};
+       }
     }
 
     public int getTagCount(String tagtype){
@@ -149,37 +153,32 @@ public class FlagState extends GraphNode {
     }
     
     public FlagState[] clearTag(TagDescriptor tag){
-           FlagState[] retstates;
-           
-           if (tags.containsKey(tag)){
+       if (tags.containsKey(tag)){
            switch(tags.get(tag).intValue()){
-                   case ONETAG:
-                       HashSet newset=(HashSet)flagstate.clone();
-                       Hashtable<TagDescriptor,Integer> newtags=(Hashtable<TagDescriptor,Integer>)tags.clone();
-                       newtags.remove(tag);
-                       retstates=new FlagState[]{new FlagState(newset,cd,newtags)};
-                       return retstates;
-                       
-                   case MULTITAGS:
-                       //when tagcount is more than 2, COUNT stays at MULTITAGS
-                       retstates=new FlagState[2];
-                       HashSet newset1=(HashSet)flagstate.clone();
-                       Hashtable<TagDescriptor,Integer> newtags1=(Hashtable<TagDescriptor,Integer>)tags.clone();
-                       retstates[1]=new FlagState(newset1,cd,newtags1);
-                       //when tagcount is 2, COUNT changes to ONETAG
-                       HashSet newset2=(HashSet)flagstate.clone();
-                       Hashtable<TagDescriptor,Integer> newtags2=(Hashtable<TagDescriptor,Integer>)tags.clone();
-                       newtags1.put(tag,new Integer(ONETAG));
-                       retstates[1]=new FlagState(newset2,cd,newtags2);
-                       return retstates;
-               default:
-                       return null;                    
-       }
-               }else{
-                       throw new Error("Invalid Operation: Can not clear a tag that doesn't exist.");
-                       
-               }
+           case ONETAG:
+               HashSet newset=(HashSet)flagstate.clone();
+               Hashtable<TagDescriptor,Integer> newtags=(Hashtable<TagDescriptor,Integer>)tags.clone();
+               newtags.remove(tag);
+               return new FlagState[]{new FlagState(newset,cd,newtags)};
                
+           case MULTITAGS:
+               //two possibilities - count remains 2 or becomes 1
+               //2 case
+               HashSet newset1=(HashSet)flagstate.clone();
+               Hashtable<TagDescriptor,Integer> newtags1=(Hashtable<TagDescriptor,Integer>)tags.clone();
+
+               //1 case
+               HashSet newset2=(HashSet)flagstate.clone();
+               Hashtable<TagDescriptor,Integer> newtags2=(Hashtable<TagDescriptor,Integer>)tags.clone();
+               newtags1.put(tag,new Integer(ONETAG));
+               return new FlagState[] {new FlagState(newset1, cd, newtags2),
+                                       new FlagState(newset2, cd, newtags2)};
+           default:
+               throw new Error();
+           }
+       } else {
+           throw new Error("Invalid Operation: Can not clear a tag that doesn't exist.");
+       }
     }
     
     /** Creates a string description of the flagstate
index 24b7417a9d7dc1ec3f37cddc0a7a09ddc0948815..93840a162d7d3f565fd3f0f8fb5753bc79aff6f7 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Stack;
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Arrays;
 import Util.Edge;
 import Analysis.CallGraph.CallGraph;
 import IR.SymbolTable;
@@ -144,22 +145,36 @@ private void computeCallsFlags(FlatMethod fm, Hashtable parammap, Set tagbinding
                    else
                        fs=fs.setFlag(tfp.getFlag(), false);
                }
+               
+               HashSet fsset=new HashSet();
+               fsset.add(fs);
+
                for(Iterator it=ffan.getTempTagPairs();it.hasNext();) {
+                   HashSet oldfsset=fsset;
+                   fsset=new HashSet();
+                   
                    TempTagPair ttp=(TempTagPair)it.next();
                    if (ffan.getTagChange(ttp)) {
                        TagDescriptor tag=ttp.getTag();
                        if (tag==null&&parammap!=null&&parammap.containsKey(ttp.getTagTemp())) {
                            tag=(TagDescriptor)parammap.get(ttp.getTagTemp());
                        }
-                       fs=fs.setTag(tag);
+                       for(Iterator setit=oldfsset.iterator();setit.hasNext();) {
+                           FlagState fs2=(FlagState)setit.next();
+                           fsset.addAll(Arrays.asList(fs2.setTag(tag)));
+                       }
                    } else
                        throw new Error("Don't clear tag in new object allocation");
                }
-               if (!flagmap.containsKey(fs))
-                   flagmap.put(fs,fs);
-               else
-                   fs=(FlagState) flagmap.get(fs);
-               newflags.add(fs);
+
+               for(Iterator setit=fsset.iterator();setit.hasNext();) {
+                   FlagState fs2=(FlagState)setit.next();
+                   if (!flagmap.containsKey(fs2))
+                       flagmap.put(fs2,fs2);
+                   else
+                       fs2=(FlagState) flagmap.get(fs2);
+                   newflags.add(fs2);
+               }
            }
        }
     }
index 592510246cfcf6dfc04fc73dec230941c43fed89..cb8cf7022d805352360dfdb71f492f5743ad202d 100644 (file)
@@ -252,7 +252,6 @@ private void analyseTasks(FlagState fs) {
                    
                    for(Enumeration en=fsv_taskexit.elements();en.hasMoreElements();){
                        FlagState fs_taskexit=(FlagState)en.nextElement();
-                       if (fs_taskexit == null ) System.out.println("Bug to fix : fs_taskexit == null");//continue;
                        if (!sourcenodes.containsKey(fs_taskexit)) {
                            toprocess.add(fs_taskexit);
                            
@@ -333,83 +332,37 @@ private boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs){
        return ctr;
 } */
 
-/** Evaluates a NewObject Node and returns the newly created 
- *  flagstate to add to the process queue.
- *     @param nn FlatNode
- *  @return FlagState
- *  @see FlatNode
- *  @see FlagState
- */
-    
-private FlagState evalNewObjNode(FlatNode nn){
-           
-    ClassDescriptor cd_new=((FlatNew)nn.getPrev(0)).getType().getClassDesc();
-           
-           
-    //TempDescriptor[] tdArray = ((FlatFlagActionNode)nn).readsTemps();
-    
-    //if (tdArray.length==0)
-    // return null;
-    
-    //Under the safe assumption that all the temps in FFAN.NewObject node are of the same type(class)
-    //ClassDescriptor cd_new=tdArray[0].getType().getClassDesc();
-    
-    FlagState fstemp=new FlagState(cd_new);
-    
-    for(Iterator it_tfp=((FlatFlagActionNode)nn).getTempFlagPairs();it_tfp.hasNext();) {
-       TempFlagPair tfp=(TempFlagPair)it_tfp.next();
-       if (! (tfp.getFlag()==null))// condition checks if the new object was created without any flag setting
-           {                                   
-               fstemp=fstemp.setFlag(tfp.getFlag(),((FlatFlagActionNode)nn).getFlagChange(tfp));
-           }
-       
-       else
-           break;
-    }
-    for(Iterator it_ttp=((FlatFlagActionNode)nn).getTempTagPairs();it_ttp.hasNext();) {
-       TempTagPair ttp=(TempTagPair)it_ttp.next();
-       if (! (ttp.getTag()==null)){
-           fstemp=fstemp.setTag(ttp.getTag());
-       }
-       else
-           break;      
-       
-    }
-    return fstemp;
-}
-       
-    private Vector<FlagState> evalTaskExitNode(FlatNode nn,ClassDescriptor cd,FlagState fs, TempDescriptor temp){
+    private Vector<FlagState> evalTaskExitNode(FlatFlagActionNode ffan,ClassDescriptor cd,FlagState fs, TempDescriptor temp){
        FlagState fstemp=fs;
-       //FlagState[] fstemparray=new FlagState[3];
-       Vector<FlagState> inprocess=new Vector<FlagState>();
        Vector<FlagState> processed=new Vector<FlagState>();
+
+       //Process the flag changes
        
-       for(Iterator it_tfp=((FlatFlagActionNode)nn).getTempFlagPairs();it_tfp.hasNext();) {
+       for(Iterator it_tfp=ffan.getTempFlagPairs();it_tfp.hasNext();) {
            TempFlagPair tfp=(TempFlagPair)it_tfp.next();
            if (temp==tfp.getTemp())
-               fstemp=fstemp.setFlag(tfp.getFlag(),((FlatFlagActionNode)nn).getFlagChange(tfp));
+               fstemp=fstemp.setFlag(tfp.getFlag(),ffan.getFlagChange(tfp));
        }
        
-       inprocess.add(fstemp);
+       //Process the tag changes
+
        processed.add(fstemp);
        
-       for(Iterator it_ttp=((FlatFlagActionNode)nn).getTempTagPairs();it_ttp.hasNext();) {
+       for(Iterator it_ttp=ffan.getTempTagPairs();it_ttp.hasNext();) {
            TempTagPair ttp=(TempTagPair)it_ttp.next();
            
-           if (temp==ttp.getTemp()){   
-               processed=new Vector<FlagState>();                      
-               for (Enumeration en=inprocess.elements();en.hasMoreElements();){
+           if (temp==ttp.getTemp()) {
+               Vector<FlagState> oldprocess=processed;
+               processed=new Vector<FlagState>();
+
+               for (Enumeration en=oldprocess.elements();en.hasMoreElements();){
                    FlagState fsworking=(FlagState)en.nextElement();
-                   if (((FlatFlagActionNode)nn).getTagChange(ttp)){
-                       fsworking=fsworking.setTag(ttp.getTag());
-                       processed.add(fsworking);
+                   if (ffan.getTagChange(ttp)){
+                       processed.addAll(Arrays.asList(fsworking.setTag(ttp.getTag())));
+                   } else {
+                       processed.addAll(Arrays.asList(fsworking.clearTag(ttp.getTag())));
                    }
-                   else
-                       {       
-                           processed.addAll(Arrays.asList(fsworking.clearTag(ttp.getTag())));
-                       }
                }
-               inprocess=processed;
            }
        }
        return processed;