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

PredicateAbstractor.java

00001 package edu.ksu.cis.bandera.abstraction;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998-2001 SAnToS Laboratories (santos@cis.ksu.edu)  *
00006 
00007  * All rights reserved.                                              *
00008  *                                                                   *
00009  * This work was done as a project in the SAnToS Laboratory,         *
00010  * Department of Computing and Information Sciences, Kansas State    *
00011  * University, USA (http://www.cis.ksu.edu/santos).                  *
00012  * It is understood that any modification not identified as such is  *
00013  * not covered by the preceding statement.                           *
00014  *                                                                   *
00015  * This work is free software; you can redistribute it and/or        *
00016  * modify it under the terms of the GNU Library General Public       *
00017  * License as published by the Free Software Foundation; either      *
00018  * version 2 of the License, or (at your option) any later version.  *
00019  *                                                                   *
00020  * This work is distributed in the hope that it will be useful,      *
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00023  * Library General Public License for more details.                  *
00024  *                                                                   *
00025  * You should have received a copy of the GNU Library General Public *
00026  * License along with this toolkit; if not, write to the             *
00027  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00028  * Boston, MA  02111-1307, USA.                                      *
00029  *                                                                   *
00030  * Java is a trademark of Sun Microsystems, Inc.                     *
00031  *                                                                   *
00032  * To submit a bug report, send a comment, or get the latest news on *
00033  * this project and other SAnToS projects, please visit the web-site *
00034  *                http://www.cis.ksu.edu/santos                      *
00035  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00036 import ca.mcgill.sable.soot.*;
00037 import ca.mcgill.sable.soot.grimp.*;
00038 import ca.mcgill.sable.soot.jimple.*;
00039 import edu.ksu.cis.bandera.jext.*;
00040 import edu.ksu.cis.bandera.abstraction.typeinference.*;
00041 import edu.ksu.cis.bandera.abstraction.util.*;
00042 import java.util.*;
00043 public class PredicateAbstractor extends AbstractBanderaValueSwitch {
00044     private static Grimp grimp = Grimp.v();
00045     private PredicateInterpreter pi = new PredicateInterpreter();
00046     private TypeTable typeTable;
00047     private Hashtable variableSetTable;
00048     private TypeTable coercedTypeTable;
00049 /**
00050  * 
00051  * @param typeTable edu.ksu.cis.bandera.abstraction.typeinference.TypeTable
00052  * @param varSetTable java.util.Hashtable
00053  */
00054 public PredicateAbstractor(TypeTable typeTable, Hashtable varSetTable) {
00055     this.typeTable = typeTable;
00056     this.variableSetTable = varSetTable;
00057 }
00058 /**
00059  * 
00060  * @param v ca.mcgill.sable.soot.jimple.Value
00061  */
00062 public static Value abs(CoercionManager cm, TypeTable typeTable, Value v) {
00063     if (typeTable.size() == 0) return v;
00064     Hashtable varSetTable = new Hashtable();
00065     PredicateTypeChecker.check(cm, typeTable, v, varSetTable);
00066     PredicateAbstractor pa = new PredicateAbstractor(typeTable, varSetTable);
00067     v.apply(pa);
00068     return (Value) pa.getResult();
00069 }
00070 /**
00071  * 
00072  * @param expr edu.ksu.cis.bandera.jext.ComplementExpr
00073  */
00074 public void caseComplementExpr(ComplementExpr expr) {
00075     expr.getOp().apply(this);
00076     expr.setOp((Value) getResult());
00077     setResult(expr);
00078 }
00079 /**
00080  * 
00081  * @param e edu.ksu.cis.bandera.jext.LocationTestExpr
00082  */
00083 public void caseLocationTestExpr(LocationTestExpr e) {
00084     defaultCase(e);
00085 }
00086 /**
00087  * 
00088  * @param expr edu.ksu.cis.bandera.jext.LogicalAndExpr
00089  */
00090 public void caseLogicalAndExpr(LogicalAndExpr expr) {
00091     expr.getOp1().apply(this);
00092     expr.setOp1((Value) getResult());
00093     expr.getOp2().apply(this);
00094     expr.setOp2((Value) getResult());
00095     setResult(expr);
00096 }
00097 /**
00098  * 
00099  * @param expr edu.ksu.cis.bandera.jext.LogicalOrExpr
00100  */
00101 public void caseLogicalOrExpr(LogicalOrExpr expr) {
00102     expr.getOp1().apply(this);
00103     expr.setOp1((Value) getResult());
00104     expr.getOp2().apply(this);
00105     expr.setOp2((Value) getResult());
00106     setResult(expr);
00107 }
00108 /**
00109  * 
00110  * @param v java.lang.Object
00111  */
00112 public void defaultCase(Object o) {
00113     Value v = (Value) o;
00114     Abstraction a = typeTable.get(v);
00115     if (!((a instanceof RealAbstraction) && !(a instanceof ConcreteRealAbstraction)) && !((a instanceof IntegralAbstraction) && !(a instanceof ConcreteIntegralAbstraction))) {
00116         setResult(v);
00117         return;
00118     }
00119     Vector variables = new Vector();
00120     for (Iterator i = ((Set) variableSetTable.get(v)).iterator(); i.hasNext();) {
00121         Value var = (Value) i.next();
00122         if (var.getType() instanceof BaseType)
00123             variables.add(var);
00124     }
00125     int size = variables.size();
00126     int[] absNumOfTokens = new int[size];
00127     int numOfPossibleTokens = 1;
00128     for (int i = 0; i < size; i++) {
00129         a = typeTable.get(variables.elementAt(i));
00130         absNumOfTokens[i] = ((Integer) AbstractionClassLoader.invokeMethod(a.getClass().getName(), "getNumOfTokens", new Class[0], null, new Object[0])).intValue();
00131         numOfPossibleTokens *= absNumOfTokens[i];
00132     }
00133     int[] changes = new int[size];
00134     for (int i = size - 1, change = 1; i >= 0; change *= absNumOfTokens[i], i--) {
00135         changes[i] = change;
00136     }
00137     int tokens[] = new int[size];
00138     int token[] = new int[size];
00139     Value result = null;
00140     for (int i = 0; i < numOfPossibleTokens; i++) {
00141         for (int j = 0; j < size; j++) {
00142             token[j] = (i / changes[j]) % absNumOfTokens[j];
00143             tokens[j] = 1 << token[j];
00144         }
00145         if (pi.isTrue(typeTable, variables, tokens, v)) {
00146             Value temp = null;
00147             int k = 0; 
00148             for (Iterator j = variables.iterator(); j.hasNext(); k++) {
00149                  if (temp == null) {
00150                      temp = grimp.newEqExpr((Value) j.next(), IntConstant.v(token[k]));
00151                  } else {
00152                      temp = new LogicalAndExpr(temp, grimp.newEqExpr((Value) j.next(), IntConstant.v(token[k])));
00153                  }
00154             }
00155             if (result == null) {
00156                 result = temp;
00157             } else {
00158                 result = new LogicalOrExpr(result, temp);
00159             }
00160         }
00161     }
00162     setResult(result);
00163 }
00164 }

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