new class names. build output code for optional tasks.
[IRC.git] / Robust / src / Analysis / TaskStateAnalysis / TaskAnalysis.java
index 1ce3588110db509494548b39fd0430504668169b..c5b626a943b54fb6fba5f91b1167de91791cc920 100644 (file)
@@ -1,5 +1,4 @@
 package Analysis.TaskStateAnalysis;
-import Analysis.TaskStateAnalysis.*;
 import IR.*;
 import IR.Tree.*;
 import IR.Flat.*;
@@ -8,41 +7,46 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.FileOutputStream;
 
-
 public class TaskAnalysis {
     State state;
     Hashtable flagstates;
     Hashtable flags;
     Hashtable extern_flags;
-    Queue<FlagState> q_main;
-    Hashtable map;
-    TempDescriptor temp;
+    Queue<FlagState> toprocess;
+    TagAnalysis taganalysis;
+    Hashtable cdtorootnodes;
+
     TypeUtil typeutil;
-    
+
     /** 
      * Class Constructor
      *
      * @param state a flattened State object
      * @see State
-     * @param map Hashtable containing the temp to var mapping
      */
-    public TaskAnalysis(State state,Hashtable map)
+    public TaskAnalysis(State state, TagAnalysis taganalysis)
     {
        this.state=state;
-       this.map=map;
        this.typeutil=new TypeUtil(state);
+       this.taganalysis=taganalysis;
+               
     }
     
-    /** This function builds a table of flags for each class **/
+    /** Builds a table of flags for each class in the Bristlecone program.  
+     * It creates two hashtables: one which holds the ClassDescriptors and arrays of
+     *  FlagDescriptors as key-value pairs; the other holds the ClassDescriptor and the 
+     *  number of external flags for that specific class.
+     */
 
     private void getFlagsfromClasses() {
        flags=new Hashtable();
        extern_flags = new Hashtable();
        
+       /** Iterate through the classes used in the program to build the table of flags
+        */
        for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) {
                
            ClassDescriptor cd = (ClassDescriptor)it_classes.next();
-           System.out.println(cd.getSymbol());
            Vector vFlags=new Vector();
            FlagDescriptor flag[];
            int ctr=0;
@@ -54,14 +58,12 @@ public class TaskAnalysis {
                
                for(Iterator it_cflags=superdesc.getFlags();it_cflags.hasNext();) {     
                    FlagDescriptor fd = (FlagDescriptor)it_cflags.next();
-                   System.out.println(fd.toString());
                    vFlags.add(fd);
                }
            }
 
            for(Iterator it_cflags=cd.getFlags();it_cflags.hasNext();) {
                FlagDescriptor fd = (FlagDescriptor)it_cflags.next();
-               System.out.println(fd.toString());
                vFlags.add(fd);
            }
 
@@ -84,472 +86,343 @@ public class TaskAnalysis {
            }
        }
     }
-
+    /** Method which starts up the analysis  
+     *  
+    */
+    
     public void taskAnalysis() throws java.io.IOException {
        flagstates=new Hashtable();
        Hashtable<FlagState,FlagState> sourcenodes;
+       cdtorootnodes=new Hashtable();
        
        getFlagsfromClasses();
        
        int externs;
-       q_main=new LinkedList<FlagState>();
+       toprocess=new LinkedList<FlagState>();
        
        for(Iterator it_classes=(Iterator)flags.keys();it_classes.hasNext();) {
            ClassDescriptor cd=(ClassDescriptor)it_classes.next();
            externs=((Integer)extern_flags.get(cd)).intValue();
            FlagDescriptor[] fd=(FlagDescriptor[])flags.get(cd);
-
-           //Debug block
-           System.out.println("Inside taskAnalysis;\n Class:"+ cd.getSymbol());
-           System.out.println("No of externs " + externs);
-           System.out.println("No of flags: "+fd.length);
-           //Debug block
-           
-          flagstates.put(cd,new Hashtable<FlagState,FlagState>());
+           flagstates.put(cd,new Hashtable<FlagState,FlagState>());
+           cdtorootnodes.put(cd,new Vector());
        }       
        
        
        ClassDescriptor startupobject=typeutil.getClass(TypeUtil.StartupClass);
        
        sourcenodes=(Hashtable<FlagState,FlagState>)flagstates.get(startupobject);
-       
        FlagState fsstartup=new FlagState(startupobject);
+       
+       
        FlagDescriptor[] fd=(FlagDescriptor[])flags.get(startupobject);
-                   
-       fsstartup=fsstartup.setFlag(fd[0],true);
        
-       sourcenodes.put(fsstartup,fsstartup);
-                           
-       Queue<FlagState> q_temp=analyseTasks(fsstartup);
+       fsstartup=fsstartup.setFlag(fd[0],true);
+       fsstartup.setAsSourceNode();
+       ((Vector)cdtorootnodes.get(startupobject)).add(fsstartup);
 
-       if ( q_temp != null) {
-               q_main.addAll(q_temp);
-       }
+       sourcenodes.put(fsstartup,fsstartup);
+       toprocess.add(fsstartup);
        
-       while (q_main.size() > 0) {
-           // ****debug block********
+       /** Looping through the flagstates in the toprocess queue to perform the state analysis */
+       while (!toprocess.isEmpty()) {
+           FlagState trigger=toprocess.poll();
+           createPossibleRuntimeStates(trigger);
            
-           System.out.println("/***********contents of main q before pop**********/");
-           for (Iterator it_qm=q_main.iterator();it_qm.hasNext();)
-               {
-                   
-                   FlagState fs_qm=(FlagState)it_qm.next();
-                   
-                   System.out.println("FS : "+fs_qm.getClassDescriptor().toString()+" : "+fs_qm.toString((FlagDescriptor [])flags.get(fs_qm.getClassDescriptor())));
-               } 
-           System.out.println("/*********************************/");
-           // ****debug block********
-           FlagState trigger=q_main.poll();
-           
-          
-           q_temp=createPossibleRuntimeStates(trigger);
-           
-           if ( q_temp != null){
-                   q_main.addAll(q_temp);
-                   
-               // ****debug block********
-           
-           System.out.println("/***********contents of main q**********/");
-           for (Iterator it_qm=q_main.iterator();it_qm.hasNext();)
-               {
-                   
-                   FlagState fs_qm=(FlagState)it_qm.next();
-                   
-                   System.out.println("FS : "+fs_qm.getClassDescriptor().toString()+" : "+fs_qm.toString((FlagDescriptor [])flags.get(fs_qm.getClassDescriptor())));
-               } 
-           System.out.println("/*********************************/");
-           // ****debug block********
-           
-           q_temp=analyseTasks(trigger);
-           
-           if ( q_temp != null) 
-                       q_main.addAll(q_temp);
-                       
-               // ****debug block********
-           
-           System.out.println("/***********contents of main q after analyse tasks**********/");
-           for (Iterator it_qm=q_main.iterator();it_qm.hasNext();)
-               {
-                   
-                   FlagState fs_qm=(FlagState)it_qm.next();
-                   
-                   System.out.println("FS : "+fs_qm.getClassDescriptor().toString()+" : "+fs_qm.toString((FlagDescriptor [])flags.get(fs_qm.getClassDescriptor())));
-               } 
-           System.out.println("/*********************************/");
-           // ****debug block********
-           
-       }
+           analyseTasks(trigger);
        }
        
-       //Creating DOT files
+       /** Creating DOT files */
        Enumeration e=flagstates.keys();
-
+       
        while (e.hasMoreElements()) {
-           System.out.println("creating dot file");
            ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement();
-           System.out.println((cdtemp.getSymbol()));
            createDOTfile(cdtemp);
        }
-       
+    }
     
-       }
-
+    
+    /** Analyses the set of tasks based on the given flagstate, checking
+     *  to see which tasks are triggered and what new flagstates are created
+     *  from the base flagstate.
+     *  @param fs A FlagState object which is used to analyse the task
+     *  @see FlagState
+     */
 
-    public Queue<FlagState> analyseTasks(FlagState fs) throws java.io.IOException {
+private void analyseTasks(FlagState fs) {
+    ClassDescriptor cd=fs.getClassDescriptor();
+    Hashtable<FlagState,FlagState> sourcenodes=(Hashtable<FlagState,FlagState>)flagstates.get(cd);
+    
+    for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator();it_tasks.hasNext();) {
+       TaskDescriptor td = (TaskDescriptor)it_tasks.next();
+       String taskname=td.getSymbol();
        
+       /** counter to keep track of the number of parameters (of the task being analyzed) that 
+        *  are satisfied by the flagstate.
+        */
+       int trigger_ctr=0;
+       TempDescriptor temp=null;
+       FlatMethod fm = state.getMethodFlat(td);        
        
-       Hashtable<FlagState,FlagState> sourcenodes;
-       Queue<FlagState> q_retval;
+       for(int i=0; i < td.numParameters(); i++) {
+           FlagExpressionNode fen=td.getFlag(td.getParameter(i));
+           TagExpressionList tel=td.getTag(td.getParameter(i));
+           
+           /** Checking to see if the parameter is of the same type/class as the 
+            *  flagstate's and also if the flagstate fs triggers the given task*/
+           if (typeutil.isSuperorType(td.getParamType(i).getClassDesc(),cd)
+               && isTaskTrigger_flag(fen,fs)
+               && isTaskTrigger_tag(tel,fs)) {
+               temp=fm.getParameter(i);
+               trigger_ctr++;
+           }
+       }
        
+       if (trigger_ctr==0) //Look at next task
+           continue;
        
+       if (trigger_ctr>1)
+           throw new Error("Illegal Operation: A single flagstate cannot satisfy more than one parameter of a task.");
        
-       ClassDescriptor cd=fs.getClassDescriptor();
        
-       sourcenodes=(Hashtable<FlagState,FlagState>)flagstates.get(cd);
+       Set newstates=taganalysis.getFlagStates(td);
+       for(Iterator fsit=newstates.iterator();fsit.hasNext();) {
+           FlagState fsnew=(FlagState) fsit.next();
+           fsnew.setAsSourceNode();
+           fsnew.addAllocatingTask(td);
+           ((Vector)cdtorootnodes.get(fsnew.getClassDescriptor())).add(fsnew);
+           
+           if (! ((Hashtable<FlagState,FlagState>)flagstates.get(fsnew.getClassDescriptor())).containsKey(fsnew)) {
+               ((Hashtable<FlagState,FlagState>)flagstates.get(fsnew.getClassDescriptor())).put(fsnew, fsnew);
+               toprocess.add(fsnew);
+           }
+       }
        
-       int externs=((Integer)extern_flags.get(cd)).intValue();
-       FlagDescriptor[] fd=(FlagDescriptor[])flags.get(cd);
-
-       q_retval=new LinkedList<FlagState>();
-       //***Debug Block***
-
-       //while (q.size() != 0) {
-           System.out.println("inside while loop in analysetasks \n");
+       Stack nodestack=new Stack();
+       HashSet discovered=new HashSet();
+       nodestack.push(fm);
+       discovered.add(fm);
+       //Iterating through the nodes
+       
+       while(!nodestack.isEmpty()) {
+           FlatNode fn1 = (FlatNode) nodestack.pop();
            
-           //***Debug Block***
-           //FlagDescriptor[] ftemp=(FlagDescriptor[])flags.get(cd);
-           //System.out.println("Processing state: "+cd.getSymbol()+" " + fsworking.toString(ftemp));
-           //***Debug Block***
-
-                   
-           for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator();it_tasks.hasNext();) {
-               TaskDescriptor td = (TaskDescriptor)it_tasks.next();
-               boolean taskistriggered=false;
-               int trigger_ctr=0;
-               String taskname=getTaskName(td);
-               
-               
-
-               //***Debug Block***
-               
-               System.out.println("Method: AnalyseTasks");
-               System.out.println(taskname);
-               System.out.println();
-               
-               //***Debug Block***
-               
-               
-               
-               for(int i=0; i < td.numParameters(); i++) {
-                   FlagExpressionNode fen=td.getFlag(td.getParameter(i));
-                   //if ( (td.getParamType(i).equals(cd))&&(isTaskTrigger(fen,fs))){
-                       if ((isParamOfSameClass(td.getParamType(i),cd)) && (isTaskTrigger(fen,fs))){
-                               taskistriggered = true;
-                               System.out.println(td.getParamType(i).toString()+"   "+cd.toString());
-                               temp=(TempDescriptor)map.get(td.getParameter(i));
-                               trigger_ctr++;
-                       }
-               }
-               
-               if (trigger_ctr>1)
-                       throw new Error("Illegal Operation: A single flagstate cannot satisfy more than one parameter of a task.");
-
-               if (taskistriggered) {
-                   //***Debug Block***
-                   //
-                   System.out.println("inside taskistriggered");
-                   
-                   //***Debug Block***
-                   
-                   taskistriggered=false;
-                  
-                   fs=canonicalizeFlagState(sourcenodes, fs);
-                                       
-                       //Iterating through the nodes
-                   FlatMethod fm = state.getMethodFlat(td);
-                   FlatNode fn=fm.methodEntryNode();
-                   
-                   HashSet tovisit= new HashSet();
-                   HashSet visited= new HashSet();
-                   
-                   tovisit.add(fn);
-                   while(!tovisit.isEmpty()) {
-                       FlatNode fn1 = (FlatNode)tovisit.iterator().next();
-                       tovisit.remove(fn1);
-                       visited.add(fn1);
-                       for(int i = 0; i < fn1.numNext(); i++) {
-                           FlatNode nn=fn1.getNext(i);
-                           if (nn.kind()==FKind.FlatFlagActionNode) {
-                               //***Debug Block***
-                               if (((FlatFlagActionNode)nn).getTaskType() == FlatFlagActionNode.PRE) {
-                                   throw new Error("PRE FlagActions not supported");
-                                   
-                               } else if (((FlatFlagActionNode)nn).getTaskType() == FlatFlagActionNode.NEWOBJECT) {
-                                   //***Debug Block***
-                                   System.out.println("NEWObject");
-                                   //***Debug Block***
-                                   
-                                   q_retval.offer(evalNewObjNode(nn));
-                               }
-                               if (((FlatFlagActionNode)nn).getTaskType() == FlatFlagActionNode.TASKEXIT) {
-                                   //***Debug Block***
-                                       System.out.println("TaskExit");
-                                   //***Debug Block***
-                                   FlagState fs_taskexit=evalTaskExitNode(nn,cd,fs);
-                                   
-                                   fs_taskexit=canonicalizeFlagState(sourcenodes,fs_taskexit);
-                   
-                                   Edge newedge=new Edge(fs_taskexit,taskname);
-                                   if (!edgeexists(fs,newedge)) {
-                                               fs.addEdge(newedge);
-                                   }
-                                  // if ((!existsInQMain(fs_taskexit)) && (!existsInQ(q_retval,fs_taskexit)) && !wasFlagStateAnalyzed(sourcenodes,fs_taskexit)){
-                                           if ((!existsInQMain(fs_taskexit)) && (!existsInQ(q_retval,fs_taskexit)) && !wasFlagStateAnalyzed(sourcenodes,fs_taskexit)){
-                                       q_retval.offer(fs_taskexit);
-                                   }
-                               }
-                           }
-                           
-                           if (!visited.contains(nn) && !tovisit.contains(nn)) {
-                               tovisit.add(nn);
-                           }
-                       }
+           if (fn1.kind()==FKind.FlatReturnNode) {
+               /* Self edge */
+               FEdge newedge=new FEdge(fs, taskname);
+               fs.addEdge(newedge);
+               continue;
+           } else if (fn1.kind()==FKind.FlatFlagActionNode) {
+               FlatFlagActionNode ffan=(FlatFlagActionNode)fn1;
+               if (ffan.getTaskType() == FlatFlagActionNode.PRE) {
+                   if (ffan.getTempFlagPairs().hasNext()||ffan.getTempTagPairs().hasNext())
+                       throw new Error("PRE FlagActions not supported");
                    
+               } else if (ffan.getTaskType() == FlatFlagActionNode.TASKEXIT) {
+                   Vector<FlagState> fsv_taskexit=evalTaskExitNode(ffan,cd,fs,temp);
+                   for(Enumeration en=fsv_taskexit.elements();en.hasMoreElements();){
+                       FlagState fs_taskexit=(FlagState)en.nextElement();
+                       if (!sourcenodes.containsKey(fs_taskexit)) {
+                           toprocess.add(fs_taskexit);
                        }
+                       //seen this node already
+                       fs_taskexit=canonicalizeFlagState(sourcenodes,fs_taskexit);
+                       FEdge newedge=new FEdge(fs_taskexit,taskname);
+                       fs.addEdge(newedge);
+                   }
+                   continue;
+               }
+           }
+           /* Queue other nodes past this one */
+           for(int i=0;i<fn1.numNext();i++) {
+               FlatNode fnext=fn1.getNext(i);
+               if (!discovered.contains(fnext)) {
+                   discovered.add(fnext);
+                   nodestack.push(fnext);
+               }
            }
        }
-       if (q_retval.size()==0)
-           return null;
-       else
-           return q_retval;
     }
+}
 
-    private boolean isTaskTrigger(FlagExpressionNode fen,FlagState fs) {
-       if (fen instanceof FlagNode)
-           return fs.get(((FlagNode)fen).getFlag());
-       else
-           switch (((FlagOpNode)fen).getOp().getOp()) {
-           case Operation.LOGIC_AND:
-               return ((isTaskTrigger(((FlagOpNode)fen).getLeft(),fs)) && (isTaskTrigger(((FlagOpNode)fen).getRight(),fs)));
-           case Operation.LOGIC_OR:
-               return ((isTaskTrigger(((FlagOpNode)fen).getLeft(),fs)) || (isTaskTrigger(((FlagOpNode)fen).getRight(),fs)));
-           case Operation.LOGIC_NOT:
-               return !(isTaskTrigger(((FlagOpNode)fen).getLeft(),fs));
-           default:
-               return false;
-           }
-    }
-    
-    private boolean isParamOfSameClass(TypeDescriptor typedesc, ClassDescriptor classdesc){
-          /* Set subclasses=typeutil.getSubClasses(classdesc);
-           if (subclasses!=null){
-                       if (subclasses.contains(typedesc.getClassDesc()) || typedesc.getClassDesc().equals(classdesc))
-                               return true;
-                       else
-                               return false;
-               }
-               else{
-                       if (typedesc.getClassDesc().equals(classdesc))
-                               return true;
-                       else
-                               return false;
-               }*/
-               
-                return typeutil.isSuperorType(classdesc,typedesc.getClassDesc());
-                       
-                       
-       }
-    
-    
-    private FlagState evalNewObjNode(FlatNode nn){
-           TempDescriptor[] tdArray = ((FlatFlagActionNode)nn).readsTemps();
-                                   
-               //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;
-               }       
-               return fstemp;
+
+/** Determines whether the given flagstate satisfies a 
+ *  single parameter in the given task.
+ *  @param fen FlagExpressionNode
+ *  @see FlagExpressionNode
+ *  @param fs  FlagState
+ *  @see FlagState
+ *  @return <CODE>true</CODE> if fs satisfies the boolean expression
+    denoted by fen else <CODE>false</CODE>.
+ */
+
+
+private boolean isTaskTrigger_flag(FlagExpressionNode fen,FlagState fs) {
+    if (fen==null)
+       return true;
+    else if (fen instanceof FlagNode)
+       return fs.get(((FlagNode)fen).getFlag());
+    else
+       switch (((FlagOpNode)fen).getOp().getOp()) {
+       case Operation.LOGIC_AND:
+           return ((isTaskTrigger_flag(((FlagOpNode)fen).getLeft(),fs)) && (isTaskTrigger_flag(((FlagOpNode)fen).getRight(),fs)));
+       case Operation.LOGIC_OR:
+           return ((isTaskTrigger_flag(((FlagOpNode)fen).getLeft(),fs)) || (isTaskTrigger_flag(((FlagOpNode)fen).getRight(),fs)));
+       case Operation.LOGIC_NOT:
+           return !(isTaskTrigger_flag(((FlagOpNode)fen).getLeft(),fs));
+       default:
+           return false;
        }
+}
+
+private boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs){
        
-       private FlagState evalTaskExitNode(FlatNode nn,ClassDescriptor cd,FlagState fs){
-               FlagState fstemp=fs;
-                                   
-               for(Iterator it_tfp=((FlatFlagActionNode)nn).getTempFlagPairs();it_tfp.hasNext();) {
-                       TempFlagPair tfp=(TempFlagPair)it_tfp.next();
-                       if (temp.toString().equals(tfp.getTemp().toString()))
-                               fstemp=fstemp.setFlag(tfp.getFlag(),((FlatFlagActionNode)nn).getFlagChange(tfp));
+       if (tel!=null){
+       for (int i=0;i<tel.numTags() ; i++){
+               switch (fs.getTagCount(tel.getType(i))){
+                       case FlagState.ONETAG:
+                       case FlagState.MULTITAGS:
+                               break;
+                       case FlagState.NOTAGS:
+                               return false;
                }
-               return fstemp;
-       }               
-           
-
-    private boolean wasFlagStateCreated(Hashtable sourcenodes,FlagState fs) {
-               if (sourcenodes.containsKey(fs))
-                       return true;
-               else
-                       return false;
-    }
-    
-    private boolean wasFlagStateAnalyzed(Hashtable sourcenodes, FlagState fs){
-           Iterator it_edges=((FlagState)sourcenodes.get(fs)).edges();
-               if (it_edges.hasNext())
-                       return true;
-               else
-                       return false;
        }
-    
-    private FlagState canonicalizeFlagState(Hashtable sourcenodes, FlagState fs){
-               if (wasFlagStateCreated(sourcenodes, fs))
-                       return (FlagState)sourcenodes.get(fs);
-               else{
-                       sourcenodes.put(fs,fs);
-                       return fs;
-               }
        }
-       
-   /* private boolean existsInQueue(TriggerState ts) {
-       throw new Error("Use hashcode/contains of set method to find...no linear search allowed");
-    }*/
-
-    private boolean existsInQMain(FlagState fs) {
-               if (q_main.contains(fs))
-                       return true;
-               else
-                       return false;    
-    }
-    
-    private boolean existsInQ(Queue q,FlagState fs) {
-               if (q.contains(fs))
-                       return true;
-               else
-                       return false;    
-    }
-
+       return true;
+}
 
-   /* public void printAdjList(ClassDescriptor cd) {
-       Enumeration e=((Hashtable)Adj_List.get(cd)).keys();
-       while(e.hasMoreElements()) {
-           FlagState fsv = (FlagState)(e.nextElement());
-           System.out.println(fsv.toString((FlagDescriptor [])flags.get(cd)));
+/*private int tagTypeCount(TagExpressionList tel, String tagtype){
+       int ctr=0;
+       for(int i=0;i<tel.numTags() ; i++){
+               if (tel.getType(i).equals(tagtype))
+                       ctr++;
        }
-    }*/
+       return ctr;
+} */
 
-   public void createDOTfile(ClassDescriptor cd) throws java.io.IOException {
-          
-       File dotfile= new File("graph"+cd.getSymbol()+".dot");
+    private Vector<FlagState> evalTaskExitNode(FlatFlagActionNode ffan,ClassDescriptor cd,FlagState fs, TempDescriptor temp){
+       FlagState fstemp=fs;
+       Vector<FlagState> processed=new Vector<FlagState>();
 
-       FileOutputStream dotstream=new FileOutputStream(dotfile,true);
+       //Process the flag changes
        
-       FlagState.DOTVisitor.visit(dotstream,((Hashtable)flagstates.get(cd)).values());
-   }
+       for(Iterator it_tfp=ffan.getTempFlagPairs();it_tfp.hasNext();) {
+           TempFlagPair tfp=(TempFlagPair)it_tfp.next();
+           if (temp==tfp.getTemp())
+               fstemp=fstemp.setFlag(tfp.getFlag(),ffan.getFlagChange(tfp));
+       }
        
+       //Process the tag changes
 
-    private String getTaskName(TaskDescriptor td) {
-       StringTokenizer st = new StringTokenizer(td.toString(),"(");
-       return st.nextToken();
-    }
-
-   /* private boolean edgeexists(Hashtable Adj_List_local,FlagState v1, FlagState v2,String label) {
-       Vector edges=(Vector)Adj_List_local.get(v1);
+       processed.add(fstemp);
        
-       if (edges != null) {
-           for(int i=0;i < edges.size();i++) {
-               FlagState fs=((Edge)edges.get(i)).getTarget();
-               if (fs.equals(v2) && (label.compareTo(((Edge)edges.get(i)).getLabel())==0))
-                   return true;
+       //Process clears first
+       for(Iterator it_ttp=ffan.getTempTagPairs();it_ttp.hasNext();) {
+           TempTagPair ttp=(TempTagPair)it_ttp.next();
+           
+           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 (!ffan.getTagChange(ttp)){
+                       processed.addAll(Arrays.asList(fsworking.clearTag(ttp.getTag())));
+                   } else processed.add(fsworking);
+               }
            }
        }
-       return false;
-    }*/
-    
-    private boolean edgeexists(FlagState fs, Edge newedge){
-               for(Iterator it_edges=fs.edges();it_edges.hasNext();){
-                               Edge e=(Edge)it_edges.next();
-                               if (newedge.equals(e))
-                                       return true;
+       //Process sets next
+       for(Iterator it_ttp=ffan.getTempTagPairs();it_ttp.hasNext();) {
+           TempTagPair ttp=(TempTagPair)it_ttp.next();
+           
+           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 (ffan.getTagChange(ttp)){
+                       processed.addAll(Arrays.asList(fsworking.setTag(ttp.getTag())));
+                   } else processed.add(fsworking);
                }
-               return false;
+           }
        }
+       return processed;
+    }          
+    
 
-    private Queue createPossibleRuntimeStates(FlagState fs) throws java.io.IOException {
-       
-               int noOfIterations, externs;
-               Hashtable<FlagState,FlagState> sourcenodes;
-       
-       
-               System.out.println("Inside CreatePossible runtime states");
-       
-               ClassDescriptor cd = fs.getClassDescriptor();
-       
-               sourcenodes=(Hashtable<FlagState,FlagState>)flagstates.get(cd);
-               FlagDescriptor[] fd=(FlagDescriptor[])flags.get(cd);    
-               externs=((Integer)extern_flags.get(cd)).intValue();
-               //System.out.println("No of externs:"+externs);
-       
+    private FlagState canonicalizeFlagState(Hashtable sourcenodes, FlagState fs){
+       if (sourcenodes.containsKey(fs))
+           return (FlagState)sourcenodes.get(fs);
+       else{
+           sourcenodes.put(fs,fs);
+           return fs;
+       }
+    }
 
-               Queue<FlagState>  q_ret=new LinkedList<FlagState>();
+   /** Creates a DOT file using the flagstates for a given class
+    *  @param cd ClassDescriptor of the class
+    *  @throws java.io.IOException
+    *  @see ClassDescriptor
+    */
+    
+    public void createDOTfile(ClassDescriptor cd) throws java.io.IOException {
+       File dotfile_flagstates= new File("graph"+cd.getSymbol()+".dot");
+       FileOutputStream dotstream=new FileOutputStream(dotfile_flagstates,true);
+       FlagState.DOTVisitor.visit(dotstream,((Hashtable)flagstates.get(cd)).values());
+    }
 
-       
-           noOfIterations=(1<<externs) - 1;
-          // System.out.println("No of iterations: "+noOfIterations);
-           boolean BoolValTable[]=new boolean[externs];
+    /** Returns the flag states for the class descriptor. */
+    public Set getFlagStates(ClassDescriptor cd) {
+       if (flagstates.containsKey(cd))
+           return ((Hashtable)flagstates.get(cd)).keySet();
+       else
+           return null;
+    }
 
-           for(int i=0; i < externs ; i++) {
-               System.out.println(fd[i].getSymbol());
-               BoolValTable[i]=fs.get(fd[i]);
-           }
 
-          /* if (! wasFlagStateCreated(Adj_List_temp,fs)) {
-                       Adj_List_temp.put(fs,new Vector());
-           }
-           */
-           if (externs > 0){
-               fs=canonicalizeFlagState(sourcenodes,fs);
-           
-                       for(int k=0; k<noOfIterations; k++) {
-                               for(int j=0; j < externs ;j++) {
-                                   if ((k% (1<<j)) == 0)
-                                               BoolValTable[j]=(!BoolValTable[j]);
-                               }
-
-                               FlagState fstemp=fs;
-               
-                               for(int i=0; i < externs;i++) {
-                                   fstemp=fstemp.setFlag(fd[i],BoolValTable[i]);
-                               }
-                               fstemp=canonicalizeFlagState(sourcenodes,fstemp);
-                               fs.addEdge(new Edge(fstemp,"Runtime"));
-                       
-                               if (!existsInQMain(fstemp) && ! wasFlagStateAnalyzed(sourcenodes, fstemp)){
-                                       q_ret.add(fstemp);
-                               }
-               
-                       }
-               } 
-               return q_ret;
-       }
-           
+    private void createPossibleRuntimeStates(FlagState fs) {
+    ClassDescriptor cd = fs.getClassDescriptor();
+    Hashtable<FlagState,FlagState> sourcenodes=(Hashtable<FlagState,FlagState>)flagstates.get(cd);
+    FlagDescriptor[] fd=(FlagDescriptor[])flags.get(cd);       
+    int externs=((Integer)extern_flags.get(cd)).intValue();
+    
+    if(externs==0)
+       return;
 
+    int noOfIterations=(1<<externs) - 1;
+    boolean BoolValTable[]=new boolean[externs];
 
 
-    private void processTasksWithPost(ClassDescriptor cd, Hashtable pre) {
+    for(int i=0; i < externs ; i++) {
+       BoolValTable[i]=fs.get(fd[i]);
     }
 
-    private ClassDescriptor processFlatNew(FlatNode fn) {
-       if (! (fn.getNext(0).kind() == 13)) {
-           return (((FlatNew)fn).getType().getClassDesc());
+       for(int k=0; k<noOfIterations; k++) {
+       for(int j=0; j < externs ;j++) {
+           if ((k% (1<<j)) == 0)
+               BoolValTable[j]=(!BoolValTable[j]);
+       }
+       
+       FlagState fstemp=fs;
+       
+       for(int i=0; i < externs;i++) {
+           fstemp=fstemp.setFlag(fd[i],BoolValTable[i]);
        }
-       return null;
+       if (!sourcenodes.containsKey(fstemp))
+           toprocess.add(fstemp);
+
+       fstemp=canonicalizeFlagState(sourcenodes,fstemp);
+       fs.addEdge(new FEdge(fstemp,"Runtime"));
     }
+       }
+       
+       public Vector getRootNodes(ClassDescriptor cd){
+               return (Vector)cdtorootnodes.get(cd);
+       }
+
+
+   
+} 
 
-}