new class names. build output code for optional tasks.
authorwmontaz <wmontaz>
Tue, 7 Aug 2007 18:35:53 +0000 (18:35 +0000)
committerwmontaz <wmontaz>
Tue, 7 Aug 2007 18:35:53 +0000 (18:35 +0000)
Robust/src/Analysis/TaskStateAnalysis/FlagState.java
Robust/src/Analysis/TaskStateAnalysis/MyOptional.java [deleted file]
Robust/src/Analysis/TaskStateAnalysis/OptionalTaskDescriptor.java [new file with mode: 0644]
Robust/src/Analysis/TaskStateAnalysis/Predicate.java
Robust/src/Analysis/TaskStateAnalysis/SafetyAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/State.java
Robust/src/IR/VarDescriptor.java
Robust/src/Main/Main.java
Robust/src/Runtime/task.c

index c18f9d9079f82000bd0a7db7e66569b4bf7410b5..4f7078efa70bd17cf1dd2adc153320762dd82361 100644 (file)
@@ -114,6 +114,10 @@ public class FlagState extends GraphNode {
     public Iterator getFlags() {
        return flagstate.iterator();
     }
+
+    public int numFlags(){
+       return flagstate.size();
+    }
     
     public FlagState[] setTag(TagDescriptor tag){
        HashSet newset1=(HashSet)flagstate.clone();
diff --git a/Robust/src/Analysis/TaskStateAnalysis/MyOptional.java b/Robust/src/Analysis/TaskStateAnalysis/MyOptional.java
deleted file mode 100644 (file)
index 1e7d5cb..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-package Analysis.TaskStateAnalysis;
-import java.util.*;
-import IR.*;
-import IR.Tree.*;
-import IR.Flat.*;
-import java.io.*;
-import Util.Edge;
-
-public class  MyOptional{
-    public TaskDescriptor td;
-    public HashSet flagstates;
-    public int depth;
-    public HashSet<Hashtable> exitfses;
-    public Predicate predicate;
-    
-    protected MyOptional(TaskDescriptor td, HashSet flagstates, int depth, Predicate predicate){
-       this.td = td;
-       this.flagstates = flagstates;
-       this.depth = depth;
-       this.exitfses = new HashSet();
-       this.predicate = predicate;
-       
-    }
-    
-    public boolean equals(Object o){
-       if (o instanceof MyOptional) {
-           MyOptional myo = (MyOptional) o;
-           if (this.td.getSymbol().compareTo(myo.td.getSymbol())==0)
-               if(this.flagstates.equals(myo.flagstates))
-                   return true;
-           return false;
-       }
-       else return false;
-       
-    }
-    
-    public int hashCode() {
-       return td.hashCode()+flagstates.hashCode()+exitfses.hashCode();
-    }
-    
-    public String tostring() {
-       return "Optional task "+td.getSymbol();
-    }
-    
-}
diff --git a/Robust/src/Analysis/TaskStateAnalysis/OptionalTaskDescriptor.java b/Robust/src/Analysis/TaskStateAnalysis/OptionalTaskDescriptor.java
new file mode 100644 (file)
index 0000000..b4f3981
--- /dev/null
@@ -0,0 +1,54 @@
+package Analysis.TaskStateAnalysis;
+import java.util.*;
+import IR.*;
+import IR.Tree.*;
+import IR.Flat.*;
+import java.io.*;
+import Util.Edge;
+
+public class  OptionalTaskDescriptor{
+    public TaskDescriptor td;
+    public HashSet flagstates;
+    public int depth;
+    public HashSet<HashSet> exitfses;
+    public Predicate predicate;
+    private static int nodeid=0;
+    private int uid;
+    
+    protected OptionalTaskDescriptor(TaskDescriptor td, HashSet flagstates, int depth, Predicate predicate){
+       this.td = td;
+       this.flagstates = flagstates;
+       this.depth = depth;
+       this.exitfses = new HashSet();
+       this.predicate = predicate;
+       this.uid = OptionalTaskDescriptor.nodeid++;
+       
+    }
+    
+    public boolean equals(Object o){
+       if (o instanceof OptionalTaskDescriptor) {
+           OptionalTaskDescriptor otd = (OptionalTaskDescriptor) o;
+           if (this.td.getSymbol().compareTo(otd.td.getSymbol())==0)
+               if(this.flagstates.equals(otd.flagstates))
+                   if(this.predicate.equals(otd.predicate))
+                       return true;
+           return false;
+       }
+       else return false;
+       
+    }
+    
+    public int hashCode() {
+       return td.getSymbol().hashCode()+flagstates.hashCode()+predicate.hashCode();
+    }
+    
+    public String tostring() {
+       return "Optional task "+td.getSymbol();
+    }
+
+    public int getuid() {
+       return uid;
+    }
+
+       
+}
index ea39a95262db74ff630745ea30d553550638ae91..b00b8984672d033b9992926408f49931df9ebee2 100644 (file)
@@ -6,13 +6,29 @@ import IR.Flat.*;
 import Util.Edge;
 
 public class Predicate{
-    public HashSet vardescriptors;
-    public Hashtable<VarDescriptor, HashSet<FlagExpressionNode>> flags;
-    public Hashtable<VarDescriptor, TagExpressionList> tags; //if there is a tag change, we stop the analysis
+    public Hashtable<String, VarDescriptor> vardescriptors;
+    public Hashtable<String, HashSet<FlagExpressionNode>> flags;
+    public Hashtable<String, TagExpressionList> tags; //if there is a tag change, we stop the analysis
     
     public Predicate(){
-       this.vardescriptors = new HashSet();
-           this.flags = new Hashtable();
-           this.tags = new Hashtable();
+       this.vardescriptors = new Hashtable();
+       this.flags = new Hashtable();
+       this.tags = new Hashtable();
     } 
+
+    public boolean equals(Object o){
+       if(o instanceof Predicate){
+           Predicate p = (Predicate) o;
+           if(this.vardescriptors.equals(p.vardescriptors))
+               return true;
+           return false;
+       }
+       else return false;
+    }
+
+    public int hashCode(){
+       return vardescriptors.hashCode();
+    }
+
+
 }
index 5bfb7e04e0a9400d2759eb32172758edb2bb4c4e..8ecab55facce414550c4a4b272082568d91cc984 100644 (file)
@@ -19,7 +19,7 @@ public class SafetyAnalysis {
     private String classname;
     private State state;
     private TaskAnalysis taskanalysis;
-    private Hashtable<ClassDescriptor, HashSet> myoptionals;
+    private Hashtable<ClassDescriptor, Hashtable> optionaltaskdescriptors;
 
     private ClassDescriptor processedclass;
    
@@ -28,8 +28,8 @@ public class SafetyAnalysis {
        return safeexecution;
     }
 
-    public Hashtable<ClassDescriptor, HashSet> getMyOptionals(){
-       return myoptionals;
+    public Hashtable<ClassDescriptor, Hashtable> getOptionalTaskDescriptors(){
+       return optionaltaskdescriptors;
     }
 
     /*Structure that stores a possible optional
@@ -45,7 +45,7 @@ public class SafetyAnalysis {
        this.reducedgraph = new Hashtable();
        this.state = state;
        this.taskanalysis = taskanalysis;
-        this.myoptionals = new Hashtable();
+        this.optionaltaskdescriptors = new Hashtable();
     }
     
     /*finds the the source node in the execution graph*/
@@ -103,8 +103,8 @@ public class SafetyAnalysis {
            System.out.println("\nAnalysing class :");
            processedclass=(ClassDescriptor)e.nextElement();
            classname = processedclass.getSymbol();
-           HashSet newhashset = new HashSet();
-           myoptionals.put(processedclass, newhashset);
+           Hashtable newhashtable = new Hashtable();
+           optionaltaskdescriptors.put(processedclass, newhashtable);
            Hashtable cdhashtable = new Hashtable();
 
            System.out.println("\t"+classname+ "\n");
@@ -151,8 +151,8 @@ public class SafetyAnalysis {
                //removeDoubles(availabletasks);
                                
                for(Iterator it = availabletasks.iterator(); it.hasNext();){
-                   MyOptional mo = (MyOptional)it.next();
-                   resultingFS(mo, classname);
+                   OptionalTaskDescriptor otd = (OptionalTaskDescriptor)it.next();
+                   resultingFS(otd, classname);
                }
                
                cdhashtable.put(fs, availabletasks);
@@ -161,7 +161,7 @@ public class SafetyAnalysis {
            safeexecution.put(processedclass, cdhashtable);
                               
        }
-
+       cleanPredicates();
        printTEST();
 
        
@@ -179,25 +179,26 @@ public class SafetyAnalysis {
                FlagState fs = (FlagState)fses.nextElement();
                System.out.println("\t"+fs.getTextLabel()+"\n\tSafe tasks to execute :\n");
                HashSet availabletasks = (HashSet)hashtbtemp.get(fs);
-               for(Iterator mos = availabletasks.iterator(); mos.hasNext();){
-                   MyOptional mm = (MyOptional)mos.next();
-                   System.out.println("\t\tTASK "+mm.td.getSymbol()+"\n");
-                   System.out.println("\t\tDepth : "+mm.depth);
+               for(Iterator otd_it = availabletasks.iterator(); otd_it.hasNext();){
+                   OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
+                   System.out.println("\t\tTASK "+otd.td.getSymbol()+" UID : "+otd.getuid()+"\n");
+                   System.out.println("\t\tDepth : "+otd.depth);
                    System.out.println("\t\twith flags :");
-                   for(Iterator myfses = mm.flagstates.iterator(); myfses.hasNext();){
+                   for(Iterator myfses = otd.flagstates.iterator(); myfses.hasNext();){
                        System.out.println("\t\t\t"+((FlagState)myfses.next()).getTextLabel());
                    }
                    System.out.println("\t\tand exitflags :");
-                   for(Iterator fseshash = mm.exitfses.iterator(); fseshash.hasNext();){
+                   for(Iterator fseshash = otd.exitfses.iterator(); fseshash.hasNext();){
                        HashSet temphs = (HashSet)fseshash.next();
                        System.out.println("");
                        for(Iterator exfses = temphs.iterator(); exfses.hasNext();){
                            System.out.println("\t\t\t"+((FlagState)exfses.next()).getTextLabel());
                        }
                    }
-                   Predicate predicate = mm.predicate;
+                   Predicate predicate = otd.predicate;
                    System.out.println("\t\tPredicate constains :");
-                   for(Iterator varit = predicate.vardescriptors.iterator(); varit.hasNext();){
+                   Collection c = predicate.vardescriptors.values();
+                   for(Iterator varit = c.iterator(); varit.hasNext();){
                        VarDescriptor vard = (VarDescriptor)varit.next();
                        System.out.println("\t\t\tClass "+vard.getType().getClassDesc().getSymbol());
                    }
@@ -205,28 +206,34 @@ public class SafetyAnalysis {
                }
            }
        
-           System.out.println("\n\n\n\tMyoptionals contains : ");
-           for(Iterator myoit = myoptionals.get(cdtemp).iterator(); myoit.hasNext();){
-               MyOptional mm = (MyOptional)myoit.next();
-               System.out.println("\t\tTASK "+mm.td.getSymbol()+"\n");
-               System.out.println("\t\tDepth : "+mm.depth);
+           System.out.println("\n\n\n\tOptionaltaskdescriptors contains : ");
+           Collection c_otd = optionaltaskdescriptors.get(cdtemp).values();
+           for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();){
+               OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
+               System.out.println("\t\tTASK "+otd.td.getSymbol()+" UID : "+otd.getuid()+"\n");
+               System.out.println("\t\tDepth : "+otd.depth);
                System.out.println("\t\twith flags :");
-               for(Iterator myfses = mm.flagstates.iterator(); myfses.hasNext();){
+               for(Iterator myfses = otd.flagstates.iterator(); myfses.hasNext();){
                    System.out.println("\t\t\t"+((FlagState)myfses.next()).getTextLabel());
                }
                System.out.println("\t\tand exitflags :");
-                   for(Iterator fseshash = mm.exitfses.iterator(); fseshash.hasNext();){
+                   for(Iterator fseshash = otd.exitfses.iterator(); fseshash.hasNext();){
                        HashSet temphs = (HashSet)fseshash.next();
                        System.out.println("");
                        for(Iterator exfses = temphs.iterator(); exfses.hasNext();){
                            System.out.println("\t\t\t"+((FlagState)exfses.next()).getTextLabel());
                        }
                    }
-                   Predicate predicate = mm.predicate;
-                   System.out.println("\t\tPredicate constains :");
-                   for(Iterator varit = predicate.vardescriptors.iterator(); varit.hasNext();){
+                   Predicate predicate = otd.predicate;
+                   System.out.println("\t\tPredicate contains :");
+                   Collection c = predicate.vardescriptors.values();
+                   for(Iterator varit = c.iterator(); varit.hasNext();){
                        VarDescriptor vard = (VarDescriptor)varit.next();
                        System.out.println("\t\t\tClass "+vard.getType().getClassDesc().getSymbol());
+                       HashSet temphash = predicate.flags.get(vard.getName());
+                       if(temphash == null) System.out.println("null hashset");
+                       else System.out.println("\t\t\t"+temphash.size()+" flag(s)");
+                       
                    }
                    System.out.println("\t\t------------");
            }
@@ -336,7 +343,7 @@ public class SafetyAnalysis {
     }
     
 
-    /*recursive method that returns a set of MyOptionals
+    /*recursive method that returns a set of OptionalTaskDescriptors
       The computation basically consist in returning the
       intersection or union of sets depending on the nature
       of the node : OR -> UNION
@@ -358,29 +365,37 @@ public class SafetyAnalysis {
                }
                else temppredicate = combinePredicates(temppredicate, predicate);
                //if the tn is optional and there is no more nodes/presence of a loop
-               //create the MyOptional and return it as a singleton. 
+               //create the OptionalTaskDescriptor and return it as a singleton. 
                if( !((Iterator)tn.edges()).hasNext() || tn.isSelfLoop()){
                    HashSet fstemp = new HashSet();
                    fstemp.add(tn.getFS());
-                   MyOptional mo = new MyOptional(tn.getTD(), fstemp, depth, temppredicate);
-                   myoptionals.get(processedclass).add(mo);
-                   temp.add(mo);
+                   OptionalTaskDescriptor otd = new OptionalTaskDescriptor(tn.getTD(), fstemp, depth, temppredicate);
+                   //System.out.println("Create Optionaltaskdescriptor number "+otd.getuid()+" hascode "+otd.hashCode());
+                   if(optionaltaskdescriptors.get(processedclass).get(otd)!=null){
+                       otd = (OptionalTaskDescriptor)((Hashtable)optionaltaskdescriptors.get(processedclass)).get(otd);
+                   }
+                   else optionaltaskdescriptors.get(processedclass).put(otd, otd);
+                   temp.add(otd);
                    return temp;
                }
                else if(visited.contains(tn)){
                    return temp;
                }                       
-               //else compute the edges, create the MyOptional and add it to the set.
+               //else compute the edges, create the OptionalTaskDescriptor and add it to the set.
                else{
                    int newdepth = depth + 1;
                    visited.add(tn);
                    HashSet newhashset = new HashSet(visited);
                    HashSet fstemp = new HashSet();
                    fstemp.add(tn.getFS());
-                   MyOptional mo = new MyOptional(tn.getTD(), fstemp, depth, temppredicate); 
-                   myoptionals.get(processedclass).add(mo);
+                   OptionalTaskDescriptor otd = new OptionalTaskDescriptor(tn.getTD(), fstemp, depth, temppredicate);
+                   //System.out.println("Create Optionaltaskdescriptor number "+otd.getuid()+" hascode "+otd.hashCode());
+                   if(optionaltaskdescriptors.get(processedclass).get(otd)!=null){
+                       otd = (OptionalTaskDescriptor)((Hashtable)optionaltaskdescriptors.get(processedclass)).get(otd);
+                   }
+                   else optionaltaskdescriptors.get(processedclass).put(otd, otd);
                    temp = computeEdges(tn, newdepth, newhashset, temppredicate);
-                   temp.add(mo);
+                   temp.add(otd);
                    return temp;
                }
            }
@@ -446,7 +461,7 @@ public class SafetyAnalysis {
                            TempFlagPair tfp=(TempFlagPair)it_tfp.next();
                            TempDescriptor tempd = tfp.getTemp();
                            if (classes.contains((ClassDescriptor)((TypeDescriptor)tempd.getType()).getClassDesc()))
-                               return false;
+                               return false;//return false if a taskexit modifies one of the other parameters
                        }
                        continue; // avoid queueing the return node if reachable
                    }
@@ -471,12 +486,12 @@ public class SafetyAnalysis {
            TypeDescriptor typed = td.getParamType(i);
            if(((ClassDescriptor)typed.getClassDesc()).getSymbol().compareTo(classname)!=0){
                VarDescriptor vd = td.getParameter(i);
-               result.vardescriptors.add(vd);
+               result.vardescriptors.put(vd.getName(), vd);
                HashSet flaglist = new HashSet();
                flaglist.add((FlagExpressionNode)td.getFlag(vd));
-               result.flags.put( vd, flaglist);
+               result.flags.put( vd.getName(), flaglist);
                if((TagExpressionList)td.getTag(vd) != null)
-                   result.tags.put( vd, (TagExpressionList)td.getTag(vd));
+                   result.tags.put( vd.getName(), (TagExpressionList)td.getTag(vd));
            }
        }
        return result;
@@ -672,76 +687,79 @@ public class SafetyAnalysis {
        return A;
     }
 
-    /*private void removeDoubles( HashSet A ){
-       //remove duplicated MyOptionals (might happend in few cases)
-       Vector toremove = new Vector();
-       int i = 0;
-       for(Iterator itA = A.iterator(); itA.hasNext();){
-           MyOptional myA = (MyOptional)itA.next();
-           i++;
-           Iterator itA2 = A.iterator();
-           for(int j = 0; j<i; j++){
-               itA2.next();
-           }
-           for(Iterator itA3 = itA2; itA3.hasNext();){
-               MyOptional myA2 = (MyOptional)itA3.next();
-               if(myA2.equal(myA)){
-                   //myA.depth = (myA.depth < myA2.depth) ? myA.depth : myA2.depth;
-                   toremove.add(myA2);
-                   System.out.println("removed!");
-               }
-           }
-       }
-       for( Iterator it = toremove.iterator(); it.hasNext();)
-       A.remove(it.next());
-       }*/
     
     private HashSet createIntersection( HashSet A, HashSet B){
        HashSet result = new HashSet();
-       for(Iterator itB = B.iterator(); itB.hasNext();){
-           MyOptional myB = (MyOptional)itB.next();
-           for(Iterator itA = A.iterator(); itA.hasNext();){
-               MyOptional myA = (MyOptional)itA.next();
-               if(((String)myA.td.getSymbol()).compareTo((String)myB.td.getSymbol())==0){
-                       HashSet newfs = new HashSet();
-                       newfs.addAll(myA.flagstates);
-                       newfs.addAll(myB.flagstates);
-                       int newdepth = (myA.depth < myB.depth) ? myA.depth : myB.depth;
-                       MyOptional newmy = new MyOptional(myB.td, newfs, newdepth, combinePredicates(myA.predicate, myB.predicate));
-                       result.add(newmy);
+       HashSet processed = new HashSet();
+       for(Iterator b_it = B.iterator(); b_it.hasNext();){
+           OptionalTaskDescriptor otd_b = (OptionalTaskDescriptor)b_it.next();
+           for(Iterator a_it = A.iterator(); a_it.hasNext();){
+               OptionalTaskDescriptor otd_a = (OptionalTaskDescriptor)a_it.next();
+               if(((String)otd_a.td.getSymbol()).compareTo((String)otd_b.td.getSymbol())==0){
+                   processed.add(otd_a);
+                   processed.add(otd_b);
+                   
+                   HashSet newfs = new HashSet();
+                   newfs.addAll(otd_a.flagstates);
+                   newfs.addAll(otd_b.flagstates);
+                   int newdepth = (otd_a.depth < otd_b.depth) ? otd_a.depth : otd_b.depth;
+                   OptionalTaskDescriptor newotd = new OptionalTaskDescriptor(otd_b.td, newfs, newdepth, combinePredicates(otd_a.predicate, otd_b.predicate));
+                   if(optionaltaskdescriptors.get(processedclass).get(newotd)!=null){
+                       //System.out.println("OTD found");
+                       //System.out.println("before "+newotd.getuid());
+                       newotd = (OptionalTaskDescriptor)((Hashtable)optionaltaskdescriptors.get(processedclass)).get(newotd);
+                       //System.out.println("after "+newotd.getuid());
+                   }
+                   else optionaltaskdescriptors.get(processedclass).put(newotd, newotd);
+                   result.add(newotd);
                }
            }
        }
+       
+       for(Iterator a_it = A.iterator(); a_it.hasNext();){
+           OptionalTaskDescriptor otd = (OptionalTaskDescriptor)a_it.next();
+           if(!processed.contains(otd))
+               optionaltaskdescriptors.get(processedclass).remove(otd);
+       }
+       for(Iterator b_it = B.iterator(); b_it.hasNext();){
+           OptionalTaskDescriptor otd = (OptionalTaskDescriptor)b_it.next();
+           if(!processed.contains(otd))
+               optionaltaskdescriptors.get(processedclass).remove(otd);
+       }    
        return result;
     }
 
     private Predicate combinePredicates(Predicate A, Predicate B){
        Predicate result = new Predicate();
-       result.vardescriptors.addAll(A.vardescriptors);
-       for(Iterator  varit = B.vardescriptors.iterator(); varit.hasNext();){
+       result.vardescriptors.putAll(A.vardescriptors);
+       result.flags.putAll(A.flags);
+       result.tags.putAll(A.tags);
+       Collection c = B.vardescriptors.values();
+       for(Iterator  varit = c.iterator(); varit.hasNext();){//maybe change that
            VarDescriptor vd = (VarDescriptor)varit.next();
-           if(result.vardescriptors.contains(vd))System.out.println("Already in ");
+           if(result.vardescriptors.containsKey(vd.getName())) System.out.println("Already in ");
            else {
-               System.out.println("Not already in...");
-               result.vardescriptors.add(vd);
+               //System.out.println("Not already in...");
+               result.vardescriptors.put(vd.getName(), vd);
            }
        }
-       for(Iterator varit = result.vardescriptors.iterator(); varit.hasNext();){
+       Collection vardesc = result.vardescriptors.values();
+       for(Iterator varit = vardesc.iterator(); varit.hasNext();){
            VarDescriptor vd = (VarDescriptor)varit.next();
-           HashSet bflags = B.flags.get(vd);
+           HashSet bflags = B.flags.get(vd.getName());
            if( bflags == null ){
-               System.out.println("not in B");
+               //System.out.println("not in B");
                continue;
            }
            else{
-               if (result.flags.containsKey(vd)) ((HashSet)result.flags.get(vd)).addAll(bflags);
-               else result.flags.put(vd, bflags);
+               if (result.flags.containsKey(vd.getName())) ((HashSet)result.flags.get(vd.getName())).addAll(bflags);
+               else result.flags.put(vd.getName(), bflags);
            }
-           TagExpressionList btags = B.tags.get(vd);
+           TagExpressionList btags = B.tags.get(vd.getName());
            if( btags != null ){
-               if (result.tags.containsKey(vd)) System.out.println("There should be nothing to do because same tag");
-               else result.tags.put(vd, btags);
-           }   
+               if (result.tags.containsKey(vd.getName())) System.out.println("Tag found but there should be nothing to do because same tag");
+               else result.tags.put(vd.getName(), btags);
+           }
        }
        return result;
     }
@@ -789,10 +807,10 @@ public class SafetyAnalysis {
        To do it with have to look for TaskExit FlatNodes
        in the IR.
     */
-    private void resultingFS(MyOptional mo, String classname){
+    private void resultingFS(OptionalTaskDescriptor otd, String classname){
        Stack stack = new Stack();
        HashSet result = new HashSet();
-       FlatMethod fm = state.getMethodFlat((TaskDescriptor)mo.td);
+       FlatMethod fm = state.getMethodFlat((TaskDescriptor)otd.td);
        FlatNode fn = (FlatNode)fm;
        
        Stack nodestack=new Stack();
@@ -810,7 +828,7 @@ public class SafetyAnalysis {
                    //System.out.println("TASKEXIT");
                    //***
                    HashSet tempset = new HashSet();
-                   for(Iterator it_fs = mo.flagstates.iterator(); it_fs.hasNext();){
+                   for(Iterator it_fs = otd.flagstates.iterator(); it_fs.hasNext();){
                        FlagState fstemp = (FlagState)it_fs.next();
                        for(Iterator it_tfp=ffan.getTempFlagPairs();it_tfp.hasNext();) {
                            TempFlagPair tfp=(TempFlagPair)it_tfp.next();
@@ -829,7 +847,7 @@ public class SafetyAnalysis {
                //***
                //System.out.println("RETURN NODE REACHABLE WITHOUT TASKEXITS");
                //***
-               result.add(mo.flagstates);
+               result.add(otd.flagstates);
            }
            
            /* Queue other nodes past this one */
@@ -841,8 +859,13 @@ public class SafetyAnalysis {
                }
            }
        }
-       mo.exitfses=result;
+       otd.exitfses=result;
     }
+
+    private void cleanPredicates(){
+       
+    }
+       
         
 }
 
index 96f6d96e1a220fc75395dd9f70cd1df6c1c6f188..29e2f1322a8568ed756abb05672fa030f8927610 100644 (file)
@@ -8,7 +8,8 @@ import java.util.*;
 import java.io.*;
 import Util.Relation;
 import Analysis.TaskStateAnalysis.FlagState;
-import Analysis.TaskStateAnalysis.MyOptional;
+import Analysis.TaskStateAnalysis.OptionalTaskDescriptor;
+import Analysis.TaskStateAnalysis.Predicate;
 
 public class BuildCode {
     State state;
@@ -55,6 +56,7 @@ public class BuildCode {
        PrintWriter outtask=null;
        PrintWriter outtaskdefs=null;
        PrintWriter outoptionalarrays=null;
+       PrintWriter optionalheaders=null;
 
        try {
            OutputStream str=new FileOutputStream(PREFIX+"structdefs.h");
@@ -73,8 +75,10 @@ public class BuildCode {
                str=new FileOutputStream(PREFIX+"taskdefs.c");
                outtaskdefs=new java.io.PrintWriter(str, true);
                if (state.OPTIONAL){
-                   str=new FileOutputStream(PREFIX+"optionnalarrays.c");
+                   str=new FileOutputStream(PREFIX+"optionalarrays.c");
                    outoptionalarrays=new java.io.PrintWriter(str, true);
+                   str=new FileOutputStream(PREFIX+"optionalstruct.h");
+                   optionalheaders=new java.io.PrintWriter(str, true);
                } 
            }
            if (state.structfile!=null) {
@@ -156,8 +160,7 @@ public class BuildCode {
            if (state.TASK) {
                outclassdefs.println("  int flag;");
                outclassdefs.println("  void * flagptr;");
-               outclassdefs.println("  int failedstatus;");
-               outclassdefs.println("  int * flagset;");
+               if(state.OPTIONAL) outclassdefs.println("  int failedstatus;");
            }
            printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs);
            outclassdefs.println("  int ___length___;");
@@ -165,6 +168,8 @@ public class BuildCode {
 
            if (state.TASK) {
            //Print out definitions for task types
+               outtask.println("#ifndef _TASK_H");
+               outtask.println("#define _TASK_H");
                outtask.println("struct parameterdescriptor {");
                outtask.println("int type;");
                outtask.println("int numberterms;");
@@ -183,6 +188,8 @@ public class BuildCode {
                outtask.println("};");
                outtask.println("extern struct taskdescriptor * taskarray[];");
                outtask.println("extern numtasks;");
+
+               outtask.println("#endif");
            }
        }
 
@@ -327,7 +334,7 @@ public class BuildCode {
            outstructs.println("#define MAXTASKPARAMS "+maxtaskparams);
 
        if (state.TASK&&state.OPTIONAL){
-           generateOptionalArrays(outoptionalarrays, state.getAnalysisResult(), state.getMyOptionals());
+           generateOptionalArrays(outoptionalarrays, optionalheaders, state.getAnalysisResult(), state.getOptionalTaskDescriptors());
            outoptionalarrays.close();
        } 
 
@@ -805,8 +812,7 @@ public class BuildCode {
        if (state.TASK) {
            classdefout.println("  int flag;");
            classdefout.println("  void * flagptr;");
-           classdefout.println("  int failedstatus;");
-           classdefout.println("  int * flagset;");
+           if (state.OPTIONAL) classdefout.println("  int failedstatus;");
        }
        printClassStruct(cn, classdefout);
        classdefout.println("};\n");
@@ -1613,92 +1619,333 @@ public class BuildCode {
        }
     }
 
-     void generateOptionalArrays(PrintWriter output, Hashtable<ClassDescriptor, Hashtable<FlagState, HashSet>> safeexecution, Hashtable myoptionals) {
-
-        /* SymbolTable classes = state.getClassSymbolTable();
-        for( Iterator it = classes.getAllDescriptorsIterator(); it.hasNext();){
-            ClassDescriptor cd = (ClassDescriptor)it.next();
-            output.println("Class "+cd.getSymbol());
-            Hashtable flags=(Hashtable)flagorder.get(cd);
-            for (Iterator fit = cd.getFlags(); fit.hasNext();){
-                FlagDescriptor fd = (FlagDescriptor)fit.next();
-                int flagid=1<<((Integer)flags.get(fd)).intValue();
-                output.println("\tFlag associated with "+fd.getSymbol()+" : 0x"+Integer.toHexString(flagid)+" bx"+Integer.toBinaryString(flagid));
-            }
-            }*/
+     void generateOptionalArrays(PrintWriter output, PrintWriter headers, Hashtable<ClassDescriptor, Hashtable<FlagState, HashSet>> safeexecution, Hashtable optionaltaskdescriptors) {
+        
+        //GENERATE HEADERS
+        headers.println("#include \"task.h\"\n\n");
         
 
+        
+        //STRUCT PREDICATEMEMBER
+        headers.println("struct predicatemember{");
+        headers.println("int type;");
+        headers.println("int numdnfterms;");
+        headers.println("int * flags;");
+        headers.println("int numtags;");
+        headers.println("int * tags;\n};\n\n");
+
+        //STRUCT EXITFLAGSTATE
+        headers.println("struct exitflagstate{");
+        headers.println("int numflags;");
+        headers.println("int * flags;");
+        /*
+          headers.println("int numtags;");
+          headers.println("int * tags;");
+        */
+        headers.println("\n};\n\n");
+        
+        //STRUCT EXITSTATES
+        headers.println("struct exitstates{");
+        headers.println("int numexitflagstates;");
+        headers.println("struct exitflagstate * exitflagstatearray;\n};\n\n");
+
+        //STRUCT OPTIONALTASKDESCRIPTOR
+        headers.println("struct optionaltaskdescriptor{");
+        headers.println("struct taskdescriptor * task;");
+        headers.println("int numpredicatemembers;");
+        headers.println("struct predicatemember * predicatememberarray;");
+        headers.println("int numexitstates;");
+        headers.println("struct existates * exitstatesarray;\n};\n\n");
+                
+        //STRUCT FSANALYSISWRAPPER
+        headers.println("struct fsanalysiswrapper{");
+        headers.println("int numflags;");
+        headers.println("int * flags;");
+        headers.println("int numtags;");
+        headers.println("int * tags;");
+        headers.println("int numoptionaltaskdescriptors;");
+        headers.println("struct optionaltaskdescriptor * optionaltaskdescriptorarray;\n};\n\n");
+
+        //STRUCT CLASSANALYSISWRAPPER
+        headers.println("struct classanalyiswrapper{");
+        headers.println("int type;");
+        headers.println("int numfsanalysiswrappers;");
+        headers.println("struct fsanalysiswrapper * fsanalysiswrapperarray;\n};\n\n");
+
+        Iterator taskit=state.getTaskSymbolTable().getDescriptorsIterator();
+        while(taskit.hasNext()) {
+            TaskDescriptor td=(TaskDescriptor)taskit.next();
+            headers.println("extern struct taskdescriptor task_"+td.getSafeSymbol()+";");
+        }
+        
+                                                  
+        
+        //GENERATE STRUCTS
+        output.println("#include \"optionalstruct.h\"\n\n");    
+        HashSet processedcd = new HashSet();
        
-        int fscounter = 0;
-        int myocounter = 0;
-        int classescounter = 0;
+
         Enumeration e = safeexecution.keys();
         while (e.hasMoreElements()) {
+            
             //get the class
             ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement();
-            for(Iterator myoit = ((HashSet)myoptionals.get(cdtemp)).iterator(); myoit.hasNext();){
-                MyOptional myo = (MyOptional)myoit.next();
-                output.println("struct myoptional myoptional_"+"/*ID to determine*/"+"_"+"cdtemp.getsafeSymbol()"+"={");
-                //insert code to generate the myoptional
-                output.println("};");
-            }   
-            classescounter++;
+            Hashtable flaginfo=(Hashtable)flagorder.get(cdtemp);//will be used several times
+            
+            //Generate the struct of optionals
+            if((Hashtable)optionaltaskdescriptors.get(cdtemp)==null) System.out.println("Was in cd :"+cdtemp.getSymbol());
+            Collection c_otd = ((Hashtable)optionaltaskdescriptors.get(cdtemp)).values();
+            if( !c_otd.isEmpty() ){
+                for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();){
+                    OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
+                    
+                    //generate the int arrays for the predicate
+                    Predicate predicate = otd.predicate;
+                    int predicateindex = 0;
+                    //iterate through the classes concerned by the predicate
+                    Collection c_vard = predicate.vardescriptors.values();
+                    for(Iterator vard_it = c_vard.iterator(); vard_it.hasNext();){
+                        VarDescriptor vard = (VarDescriptor)vard_it.next();
+                        TypeDescriptor typed = vard.getType();
+                        
+                        //generate for flags
+                        HashSet fen_hashset = predicate.flags.get(vard.getSymbol());
+                        output.println("int predicateflags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
+                        int numberterms=0;
+                        if (fen_hashset!=null){
+                            for (Iterator fen_it = fen_hashset.iterator(); fen_it.hasNext();){
+                                FlagExpressionNode fen = (FlagExpressionNode)fen_it.next();
+                                if (fen==null) {
+                                    //output.println("0x0, 0x0 };");
+                                    //numberterms+=1;
+                                }
+                                else {
+                                    
+                                    DNFFlag dflag=fen.getDNF();
+                                    numberterms+=dflag.size();
+                                    
+                                    Hashtable flags=(Hashtable)flagorder.get(typed.getClassDesc());
+                                    
+                                    for(int j=0;j<dflag.size();j++) {
+                                        if (j!=0)
+                                            output.println(",");
+                                        Vector term=dflag.get(j);
+                                        int andmask=0;
+                                        int checkmask=0;
+                                        for(int k=0;k<term.size();k++) {
+                                            DNFFlagAtom dfa=(DNFFlagAtom)term.get(k);
+                                            FlagDescriptor fd=dfa.getFlag();
+                                            boolean negated=dfa.getNegated();
+                                            int flagid=1<<((Integer)flags.get(fd)).intValue();
+                                            andmask|=flagid;
+                                            if (!negated)
+                                                checkmask|=flagid;
+                                        }
+                                        output.print("/*andmask*/0x"+Integer.toHexString(andmask)+", /*checkmask*/0x"+Integer.toHexString(checkmask));
+                                    }
+                                }
+                            }
+                        }
+                        output.println("};\n");
+                        
+                        //generate for tags
+                        TagExpressionList tagel = predicate.tags.get(vard.getSymbol()); 
+                        output.println("int predicatetags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
+                        //BUG...added next line to fix, test with any task program
+                        int numtags = 0;
+                        if (tagel!=null){
+                            for(int j=0;j<tagel.numTags();j++) {
+                                if (j!=0)
+                                    output.println(",");
+                                /* for each tag we need */
+                                /* which slot it is */
+                                /* what type it is */
+                                //TagVarDescriptor tvd=(TagVarDescriptor)task.getParameterTable().get(tagel.getName(j));
+                                TempDescriptor tmp=tagel.getTemp(j);
+                                //got rid of slot
+                                output.println("/*tagid*/"+state.getTagId(tmp.getTag()));
+                            }
+                            numtags = tagel.numTags();
+                        }
+                        output.println("};");
+                        
+                        //store the result into a predicatemember struct
+                        output.println("struct predicatemember predicatemember_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"={");
+                        output.println("/*type*/"+typed.getClassDesc().getId()+",");
+                        output.println("/* number of dnf terms */"+numberterms+",");
+                        output.println("predicateflags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
+                        output.println("/* number of tag */"+numtags+",");
+                        output.println("predicatetags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
+                        output.println("};\n");
+                        predicateindex++;
+                    }
+                    
+
+                    //generate an array that stores the entire predicate
+                    output.println("struct predicatemember * predicatememberarray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
+                    for( int j = 0; j<predicateindex; j++){
+                        if( j != predicateindex-1)output.println("&predicatemember_"+j+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
+                        else output.println("&predicatemember_"+j+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"};\n");
+                    }
+
+                    //generate the struct for possible exitfses
+                    HashSet<HashSet> exitfses = otd.exitfses;
+                    int exitindex = 0;
+                    int nbexit = exitfses.size();
+                    int fsnumber;
+                    
+                    //iterate through possible exits
+                    for(Iterator exitfseshash = exitfses.iterator(); exitfseshash.hasNext();){
+                        HashSet temp_hashset = (HashSet)exitfseshash.next();
+                        fsnumber = 0 ;
+                        
+                        //iterate through possible FSes corresponding to the exit
+                        for(Iterator exfses = temp_hashset.iterator(); exfses.hasNext();){
+                           FlagState fs = (FlagState)exfses.next();
+                           fsnumber++;
+                           output.println("int flags"+fsnumber+"_EXIT"+exitindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
+                           int counterflag = 0;
+                           for(Iterator flags = fs.getFlags(); flags.hasNext();){
+                               FlagDescriptor flagd = (FlagDescriptor)flags.next();
+                               int flagid=1<<((Integer)flaginfo.get(flagd)).intValue();
+                               if( flags.hasNext() ) output.print("0x"+Integer.toHexString(flagid)+" /*"+Integer.toBinaryString(flagid)+"*/,");
+                               else  output.print("0x"+Integer.toHexString(flagid)+" /*"+Integer.toBinaryString(flagid)+"*/");
+                               counterflag++;
+                           } 
+                           output.println("};\n");
+                           //do the same for tags;
+                           //maybe not needed because no tag changes tolerated.
+
+                           //store the information into a struct
+                           output.println("struct exitflagstate exitflagstate"+fsnumber+"_EXIT"+exitindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"={");
+                           output.println("/*number of flags*/"+counterflag+",");
+                           output.println("flags"+fsnumber+"_EXIT"+exitindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol());
+                           output.println("};\n");
+                        }
+                        
+                        //store fses corresponding to this exit into an array
+                        output.println("struct exitflagstate * exitflagstatearray"+"_EXIT"+exitindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+" [] = {");
+                        for( int j = 0; j<fsnumber; j++){
+                            if( j != fsnumber-1)output.println("&exitflagstate"+(j+1)+"_EXIT"+exitindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"'");
+                            else output.println("&exitflagstate"+(j+1)+"_EXIT"+exitindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"};\n");
+                        }
+                        
+                        //store that information in a struct
+                        output.println("struct exitstates exitstates"+exitindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"={");
+                        output.println("/*number of exitflagstate*/"+fsnumber+",");
+                        output.println("exitflagstatearray"+"_EXIT"+exitindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol());
+                        output.println("};\n");
+
+                        exitindex++;
+                    }
+                    
+                    //store the information concerning all exits into an array
+                    output.println("struct exitstates * exitstatesarray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
+                    for( int j = 0; j<nbexit; j++){
+                        if( j != nbexit-1)output.println("&exitstates"+j+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
+                        else output.println("&exitstates"+j+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"};\n");
+                    }
+                                    
+                                    
+                    //generate optionaltaskdescriptor that actually includes exit fses, predicate and the task concerned
+                    output.println("struct optionaltaskdescriptor optionaltaskdescriptor_"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"={");
+                    output.println("task_"+otd.td.getSafeSymbol()+",");
+                    output.println("/*number of members */"+predicateindex+",");
+                    output.println("predicatememberarray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
+                    output.println("/*number of exit fses */"+nbexit+",");
+                    output.println("exitstatearray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol());
+                    output.println("};\n");
+                }      
+            }
+            else continue; // if there is no optionals, there is no need to build the rest of the struct 
+            
+            //get all the possible falgstates reachable by an object
             Hashtable hashtbtemp = safeexecution.get(cdtemp);
             Enumeration fses = hashtbtemp.keys();
+            int fscounter = 0;
             while(fses.hasMoreElements()){
-                //get all the possible falgstates reachable by an object
                 FlagState fs = (FlagState)fses.nextElement();
                 fscounter++;
-                //get the set of MyOptionnals
+                
+                //get the set of OptionalTaskDescriptors corresponding
                 HashSet availabletasks = (HashSet)hashtbtemp.get(fs);
-                //iterate through the MyOptionals
+                //iterate through the OptionalTaskDescriptors and store the pointers to the optionals struct (see on top) into an array
+                
+                output.println("struct optionaltaskdescriptor * optionaltaskdescriptorarray_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[] = {");
                 for(Iterator mos = availabletasks.iterator(); mos.hasNext();){
-                    MyOptional mm = (MyOptional)mos.next();
-                    myocounter++;
-                }
-                output.println("struct myoptional * myoptionals_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[] = {");
-                for(int i=0; i<myocounter; i++){
-                    if(i==myocounter-1) output.println("&myoptional_"+"/*ID to determine*/"+"_"+cdtemp.getSafeSymbol()+"};");
-                        
-                    else output.println("&myoptional_"+"/*ID to determine*/"+"_"+cdtemp.getSafeSymbol()+",");
+                    OptionalTaskDescriptor mm = (OptionalTaskDescriptor)mos.next();
+                    if(!mos.hasNext()) output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol()+"};\n");
+                    
+                    else output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol()+",");
                 }
-                myocounter = 0;
-                output.println("int flagstatednf_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[]={");
+
+                //process flag information (what the flag after failure is) so we know what optionaltaskdescriptors to choose.
+                
+                output.println("int flags_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[]={");
                 for(Iterator flags = fs.getFlags(); flags.hasNext();){
                     FlagDescriptor flagd = (FlagDescriptor)flags.next();
-                    //process the fs, maybe add int tagstate[]
+                    int flagid=1<<((Integer)flaginfo.get(flagd)).intValue();
+                    if( flags.hasNext() ) output.print("0x"+Integer.toHexString(flagid)+" /*"+Integer.toBinaryString(flagid)+"*/,");
+                    else  output.print("0x"+Integer.toHexString(flagid)+" /*"+Integer.toBinaryString(flagid)+"*/");
+                    
                 }
-                output.println("};");
-                output.println("struct structB structB_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"={");
-                output.println("/* number of dnf terms (to add)*/,");
-                output.println("flagstatednf_"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
-                output.println("/* number of tags (to add)*/,");
-                output.println("tags_"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
-                output.println("/* number of myoptionals */,");
-                output.println("myoptionals_FS"+fscounter+"_"+cdtemp.getSafeSymbol());
-                output.println("};");
+                //process tag information
+                
+                int tagcounter = 0;
+                //TagExpressionList tagel = fs.getTags(); 
+                //output.println("int predicatetags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
+                //BUG...added next line to fix, test with any task program
+                
+                //if (tagel!=null){
+                //    for(int j=0;j<tagel.numTags();j++) {
+                //      if (j!=0)
+                //          output.println(",");
+                //      TempDescriptor tmp=tagel.getTemp(j);
+                //      output.println("/*tagid*/"+state.getTagId(tmp.getTag()));
+                //   }
+                //  numtags = tagel.numTags();
+                //}
+                //output.println("};");
+                
+                
+                //Store the result in fsanalysiswrapper
+                output.println("};\n");
+                output.println("struct fsanalysiswrapper fsanalysiswrapper_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"={");
+                output.println("/* number of flags*/"+fs.numFlags()+",");
+                output.println("flags_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
+                output.println("/* number of tags*/"+tagcounter+",");
+                output.println("tags_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
+                output.println("/* number of optionaltaskdescriptors */"+availabletasks.size()+",");
+                output.println("optionaltaskdescriptorarray_FS"+fscounter+"_"+cdtemp.getSafeSymbol());
+                output.println("};\n");
+                
             }
-            output.println("struct structB * structBs_"+cdtemp.getSafeSymbol()+"[] = {");
+
+            //Build the array of fsanalysiswrappers
+            output.println("struct fsanalysiswrapper * fsanalysiswrapperarray_"+cdtemp.getSafeSymbol()+"[] = {");
             for(int i = 0; i<fscounter; i++){
-                if(i==fscounter-1) output.println("&structB_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"};");
+                if(i==fscounter-1) output.println("&fsanalysiswrapper_FS"+(i+1)+"_"+cdtemp.getSafeSymbol()+"};\n");
                         
-                    else output.println("&structB_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
+                    else output.println("&fsanalysiswrapper_FS"+(i+1)+"_"+cdtemp.getSafeSymbol()+",");
             }
+
+            //Build the classanalysiswrapper referring to the previous array
+            output.println("struct classanalysiswrapper classanalysiswrapper_"+cdtemp.getSafeSymbol()+"={");
+            output.println("/*type*/"+cdtemp.getId()+",");
+            output.println("/* number of fsanalysiswrappers */"+fscounter+",");
+            output.println("fsanalysiswrapperarray_"+cdtemp.getSafeSymbol()+"};\n");
             fscounter = 0;
-            output.println("struct structA structA_"+cdtemp.getSafeSymbol()+"={");
-            output.println("/* class identifier */,");
-            output.println("structBs_"+cdtemp.getSafeSymbol()+"};");
+            processedcd.add(cdtemp);
         }
-        output.println("struct structA * classesarray[]={");
-        e = safeexecution.keys();
-        int j = 0;
-        while (e.hasMoreElements()) {
-            ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement();
-            j++;
-            if(j==classescounter) output.println("&structA_"+cdtemp.getSafeSymbol()+"};");
-            else output.println("&structA_"+cdtemp.getSafeSymbol()+",");
+
+        //build an array containing every classes for which code has been build
+        output.println("struct classanalysiswrapper * classanalysiswrapperarray[]={");
+        for(Iterator classit = processedcd.iterator(); classit.hasNext();){
+            ClassDescriptor cdtemp=(ClassDescriptor)classit.next();
+            if(!classit.hasNext()) output.println("&classanalysiswrapper_"+cdtemp.getSafeSymbol()+"};\n");
+            else output.println("&classanalysiswrapper_"+cdtemp.getSafeSymbol()+",");
         }
-        output.println("int numclasses = "+classescounter+";");
+        output.println("int numclasses = "+processedcd.size()+";");
         
      }
     
index eb02c49c3e3b07c357127a2d7fbc7d6f2d2932b1..9df0cc3235d9d2067de8914edc0b1f491e09839a 100644 (file)
@@ -15,7 +15,7 @@ public class State {
        this.arraytonumber=new Hashtable();
        this.tagmap=new Hashtable();
        this.analysisresult=new Hashtable();
-       this.myoptionals=new Hashtable();
+       this.optionaltaskdescriptors=new Hashtable();
     }
 
     public void addParseNode(ParseNode parsetree) {
@@ -26,16 +26,16 @@ public class State {
        analysisresult = result;
     }
     
-    public void storeMyOptionals(Hashtable myoptionals){
-       this.myoptionals=myoptionals;
+    public void storeOptionalTaskDescriptors(Hashtable optionaltaskdescriptors){
+       this.optionaltaskdescriptors=optionaltaskdescriptors;
     }
 
     public Hashtable getAnalysisResult(){
        return analysisresult;
     }
     
-    public Hashtable getMyOptionals(){
-       return myoptionals;
+    public Hashtable getOptionalTaskDescriptors(){
+       return optionaltaskdescriptors;
     }
 
     /** Boolean flag which indicates whether compiler is compiling a task-based
@@ -64,7 +64,7 @@ public class State {
 
 
     private Hashtable analysisresult;
-    private Hashtable myoptionals;
+    private Hashtable optionaltaskdescriptors;
 
     private Hashtable tagmap;
     private int numtags=0;
index 17e81f00ae7a3130e0de360786cf980b09d37991..2a3ee9a91ae3742c83bfb0dd21fc7dd8169ec15e 100644 (file)
@@ -32,4 +32,5 @@ public class VarDescriptor extends Descriptor {
     public String toString() {
            return td.toString()+" "+identifier;
     }
+
 }
index fa7a78dd8a26def08a6832f851f327787a4392ac..0221524ec3dbd10d44da28285c669963d4221645 100644 (file)
@@ -140,7 +140,7 @@ public class Main {
              SafetyAnalysis sa = new SafetyAnalysis(et.getExecutionGraph(), state, ta);
              sa.buildPath();
              state.storeAnalysisResult(sa.getResult());
-             state.storeMyOptionals(sa.getMyOptionals());
+             state.storeOptionalTaskDescriptors(sa.getOptionalTaskDescriptors());
          }
          
          if (state.WEBINTERFACE) {
index 93fc4aaeb771a162297272caf8286660a9938c06..5e7848c83c61cc379475f20fa93d8f9058ea7f7f 100644 (file)
@@ -6,6 +6,7 @@
 #include "Queue.h"
 #include "SimpleHash.h"
 #include "GenericHashtable.h"
+#include "optionalstruct.h"
 #include <sys/select.h>
 #include <sys/types.h>
 #include <sys/mman.h>