Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SliceInterestEnv.java

00001 package edu.ksu.cis.bandera.pdgslicer.dependency;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998, 1999   Hongjun Zheng (zheng@cis.ksu.edu)      *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 
00036 
00037 import edu.ksu.cis.bandera.bui.*;
00038 import edu.ksu.cis.bandera.pdgslicer.datastructure.*;
00039 import ca.mcgill.sable.soot.jimple.*;
00040 import edu.ksu.cis.bandera.jext.*;
00041 import edu.ksu.cis.bandera.jjjc.symboltable.*;
00042 import ca.mcgill.sable.soot.*;
00043 import edu.ksu.cis.bandera.specification.assertion.*;
00044 import edu.ksu.cis.bandera.specification.assertion.datastructure.*;
00045 import edu.ksu.cis.bandera.specification.predicate.*;
00046 import edu.ksu.cis.bandera.specification.predicate.datastructure.*;
00047 import edu.ksu.cis.bandera.specification.datastructure.*;
00048 import java.util.*;
00049 import edu.ksu.cis.bandera.jjjc.*;
00050 import javax.swing.JOptionPane;
00051 public class SliceInterestEnv {
00052     private Dependencies dependFrame;
00053     private CriterionViewer criterionViewer;
00054     private Hashtable importedAssertion = new Hashtable();
00055     private Hashtable importedAssertionSet = new Hashtable();
00056     private HashSet predicates = new HashSet();
00057     private HashSet quantifierSliceInterests = new HashSet();
00058 /**
00059  * 
00060  */
00061 public SliceInterestEnv() {
00062 }
00063 /**
00064  * 
00065  * @return java.util.Vector
00066  */
00067 Vector getSliceInterests() {
00068     if (!runSpecCompiler())
00069         return null;
00070     Vector v = (Vector) AssertionSliceInterestCollector.collect(new Vector());
00071     v.addAll(PredicateSliceInterestCollector.collect(predicates));
00072     v.addAll(quantifierSliceInterests);
00073     //v.addAll(edu.ksu.cis.bandera.core.CoreDriver.getMiscSliceInterests());
00074     //v.addAll(edu.ksu.cis.bandera.bui.Driver.getMiscSliceInterests());
00075     return v;
00076 }
00077 /**
00078  * 
00079  */
00080 public void initAssertions() throws Exception {
00081     for (Iterator i = BUI.property.getImportedAssertion().iterator(); i.hasNext();) {
00082         Name name = (Name) i.next();
00083         Assertion as = AssertionSet.getAssertion(name);
00084         importedAssertion.put(name, as);
00085     }
00086     
00087     for (Iterator i = BUI.property.getImportedAssertionSet().iterator(); i.hasNext();) {
00088         Name name = (Name) i.next();
00089         AssertionSet as = AssertionSet.getAssertionSet(name);
00090         importedAssertionSet.put(name, as);
00091     }
00092 }
00093 /**
00094  * 
00095  * @return edu.ksu.cis.bandera.jjjc.symboltable.Name
00096  * @param name edu.ksu.cis.bandera.jjjc.symboltable.Name
00097  */
00098 public  Assertion resolveAssertionName(Name name) throws Exception {
00099     Assertion a = (Assertion) importedAssertion.get(name);
00100     if (a != null)
00101         return a;
00102 
00103     if (!name.isSimpleName()) {
00104         try {
00105             return AssertionSet.getAssertion(name);
00106         } catch (Exception e) {
00107             throw new Exception("Can't resolve assertion with name '" + name + "'");
00108         }
00109     }
00110 
00111     Vector v = new Vector();
00112 
00113     for (Enumeration e = importedAssertionSet.elements(); e.hasMoreElements();) {
00114         AssertionSet as = (AssertionSet) e.nextElement();
00115         if (as.getAssertionTable().get(new Name(as.getName(), name)) != null) {
00116             v.add(as);
00117         }
00118     }
00119 
00120     if (v.size() > 1)
00121         throw new Exception("Ambiguous assertion with name '" + name + "'");
00122     if (v.size() < 1)
00123         throw new Exception("Can't resolve assertion with name '" + name + "'");
00124 
00125     AssertionSet as = (AssertionSet) v.firstElement();
00126     a = (Assertion) as.getAssertionTable().get(new Name(as.getName(), name));
00127     return a;
00128 }
00129 /**
00130  * 
00131  */
00132 private boolean runSpecCompiler() {
00133     try {
00134         Property property = BUI.property;
00135         Hashtable assertionTable = new Hashtable();
00136         initAssertions();
00137         for (Iterator i = property.getActivatedAssertionProperties().iterator(); i.hasNext();) {
00138             AssertionProperty ap = (AssertionProperty) i.next();
00139             for (Iterator j = ap.getAssertions().iterator(); j.hasNext();) {
00140                 assertionTable.put(resolveAssertionName((Name) j.next()), new HashSet());
00141             }
00142         }
00143         int numOfQuantifiers = 0;
00144         HashSet v = new HashSet();
00145         TemporalLogicProperty tlp = property.getActivatedTemporalLogicProperty();
00146         if (tlp != null) {
00147             tlp.validate(property.getImportedType(), property.getImportedPackage(), property.getImportedAssertion(), property.getImportedAssertionSet(), property.getImportedPredicate(), property.getImportedPredicateSet());
00148             if (tlp.getExceptions().size() > 0) {
00149                 StringBuffer buffer = new StringBuffer();
00150                 for (Iterator i = tlp.getExceptions().iterator(); i.hasNext();) {
00151                     buffer.append(i.next() + "\n");
00152                 }
00153                 JOptionPane.showMessageDialog(criterionViewer, buffer.toString(), "Error", JOptionPane.ERROR_MESSAGE);
00154                 dependFrame.success = false;
00155                 return false;
00156             }
00157             Hashtable qTable = tlp.getQuantifiersTable();
00158             numOfQuantifiers = qTable.size();
00159             for (Enumeration e = qTable.elements(); e.hasMoreElements();) {
00160                 v.add((QuantifiedVariable) e.nextElement());
00161             }
00162         }
00163         if ((assertionTable.size() > 0) || (numOfQuantifiers > 0)) {
00164             CompilationManager.setQuantifiers(tlp.getQuantifiedVariables());
00165             CompilationManager.setModifiedMethodTable(AssertionProcessor.process(assertionTable));
00166             if (!dependFrame.reRunJJJC()) {
00167                 dependFrame.success = false;
00168                 return false;
00169             }
00170             SootClass mainClass = CompilationManager.getMainSootClass();
00171             for (Iterator i = CompilationManager.getQuantifiers().iterator(); i.hasNext();) {
00172                 QuantifiedVariable qv = (QuantifiedVariable) i.next();
00173                 String name = "quantification$" + qv.getName();
00174                 SootField sf = CompilationManager.getFieldForQuantifier(name);
00175                 mainClass.addField(sf);
00176                 SootClass sc = sf.getDeclaringClass(); // robbyjo's patch
00177                 quantifierSliceInterests.add(new SliceField(sc, sf)); // robbyjo's patch
00178             }
00179             CompilationManager.setModifiedMethodTable(new Hashtable());
00180         }
00181 
00182         // Compile predicates to Grimp
00183         if (tlp != null) {
00184             StringBuffer sb = new StringBuffer();
00185             tlp.validate(property.getImportedType(), property.getImportedPackage(), property.getImportedAssertion(), property.getImportedAssertionSet(), property.getImportedPredicate(), property.getImportedPredicateSet());
00186             Hashtable pTable = tlp.getPredicatesTable();
00187             Hashtable pqTable = tlp.getPredicateQuantifierTable();
00188             Hashtable qphTable = new Hashtable();
00189             SootClass mainClass = CompilationManager.getMainSootClass();
00190             Jimple jimple = Jimple.v();
00191             HashSet visitedP = new HashSet();
00192             for (Enumeration e = pTable.keys(); e.hasMoreElements();) {
00193                 Object key = e.nextElement();
00194                 Predicate p = (Predicate) pTable.get(key);
00195                 if (p.getExceptions().size() > 0) {
00196                     if (visitedP.contains(p)) continue;
00197                     visitedP.add(p);
00198                     sb.append("In '" + p + "':\n");
00199                     for (Iterator i = p.getExceptions().iterator(); i.hasNext();) {
00200                         sb.append("* " + ((Exception) i.next()).getMessage() + "\n");
00201                     }
00202                     continue;
00203                 }
00204                 Vector qvs = (Vector) pqTable.get(key);
00205                 Value phThis = null;
00206                 Hashtable phParams = new Hashtable();
00207                 
00208                 for (int i = 0; i < qvs.size(); i++) {
00209                     QuantifiedVariable q = (QuantifiedVariable) qvs.elementAt(i);
00210                     Value cph = null;
00211                     if (q != null) {
00212                         if (qphTable.get(q) == null) {
00213                             String name = "quantification$" + q.getName();
00214                             cph = jimple.newStaticFieldRef(mainClass.getField(name));
00215                             qphTable.put(q, cph);
00216                         } else {
00217                             cph = (Value) qphTable.get(q);
00218                         }
00219                         if ((i == 0) && (!p.isStatic())) {
00220                             phThis = cph;
00221                         } else {
00222                             phParams.put(q.getName(), cph);
00223                         }
00224                     }
00225                 }
00226                 Value value = PredicateProcessor.process(phThis, phParams, p);
00227                 if (!(p instanceof ExpressionPredicate)) {
00228                     if (value instanceof LocationTestExpr) {
00229                         LocationTestExpr lte = (LocationTestExpr) value;
00230                     } else {
00231                         LocationTestExpr lte = (LocationTestExpr) ((LogicalAndExpr) value).getOp1();
00232                     }
00233                 }
00234                 predicates.add(p);
00235             }
00236 
00237             String s = sb.toString();
00238             if (s.length() > 0)
00239                 throw new RuntimeException(s.substring(0, s.length() - 1));
00240         }
00241     } catch (Exception e) {
00242         CompilationManager.setModifiedMethodTable(new Hashtable());
00243         CompilationManager.setQuantifiers(new Vector());
00244         JOptionPane.showMessageDialog(criterionViewer, e.getMessage(), "Bandera SL Phase --- Error", JOptionPane.ERROR_MESSAGE);
00245         e.printStackTrace();
00246         dependFrame.success = false;
00247         return false;
00248     }
00249     dependFrame.success = true;
00250     return true;
00251 }
00252 /**
00253  * Insert the method's description here.
00254  * Creation date: (00-12-9 15:55:54)
00255  * @param cv edu.ksu.cis.bandera.pdgslicer.dependency.CriterionViewer
00256  */
00257 void setCriterionViewer(CriterionViewer cv) {
00258     criterionViewer = cv;
00259 }
00260 /**
00261  * Insert the method's description here.
00262  * Creation date: (00-12-11 17:43:50)
00263  * @param dpnd edu.ksu.cis.bandera.pdgslicer.dependency.Dependencies
00264  */
00265 void setDependFrame(Dependencies dpnd) {
00266     dependFrame = dpnd;
00267 }
00268 }

Generated at Thu Feb 7 06:54:59 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001