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

PredicateTransformer.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 java.util.*;
00040 import edu.ksu.cis.bandera.jext.*;
00041 import edu.ksu.cis.bandera.abstraction.typeinference.*;
00042 public class PredicateTransformer extends AbstractBanderaValueSwitch {
00043     private static Grimp grimp = Grimp.v();
00044     private boolean foundComplement;
00045 /**
00046  * 
00047  */
00048 private PredicateTransformer() {}
00049 /**
00050  * 
00051  * @param expr edu.ksu.cis.bandera.jext.ComplementExpr
00052  */
00053 public void caseComplementExpr(ComplementExpr expr) {
00054     foundComplement = !foundComplement;
00055     expr.getOp().apply(this);
00056 }
00057 public void caseEqExpr(EqExpr v) {
00058     if (foundComplement)
00059         setResult(grimp.newNeExpr(v.getOp1(), v.getOp2()));
00060     else
00061         defaultCase(v);
00062 }
00063 public void caseGeExpr(GeExpr v) {
00064     if (foundComplement)
00065         setResult(grimp.newLtExpr(v.getOp1(), v.getOp2()));
00066     else
00067         defaultCase(v);
00068 }
00069 public void caseGtExpr(GtExpr v) {
00070     if (foundComplement)
00071         setResult(grimp.newLeExpr(v.getOp1(), v.getOp2()));
00072     else
00073         defaultCase(v);
00074 }
00075 public void caseLeExpr(LeExpr v) {
00076     if (foundComplement)
00077         setResult(grimp.newGtExpr(v.getOp1(), v.getOp2()));
00078     else
00079         defaultCase(v);
00080 }
00081 /**
00082  * 
00083  * @param expr edu.ksu.cis.bandera.jext.LogicalAndExpr
00084  */
00085 public void caseLogicalAndExpr(LogicalAndExpr expr) {
00086     boolean foundComplement = this.foundComplement;
00087     expr.getOp1().apply(this);
00088     Value op1 = (Value) getResult();
00089     this.foundComplement = foundComplement;
00090     expr.getOp2().apply(this);
00091     Value op2 = (Value) getResult();
00092     if (foundComplement) {
00093         setResult(new LogicalOrExpr(op1, op2));
00094     } else {
00095         expr.setOp1(op1);
00096         expr.setOp2(op2);
00097         setResult(expr);
00098     }
00099 }
00100 /**
00101  * 
00102  * @param expr edu.ksu.cis.bandera.jext.LogicalOrExpr
00103  */
00104 public void caseLogicalOrExpr(LogicalOrExpr expr) {
00105     boolean foundComplement = this.foundComplement;
00106     expr.getOp1().apply(this);
00107     Value op1 = (Value) getResult();
00108     this.foundComplement = foundComplement;
00109     expr.getOp2().apply(this);
00110     Value op2 = (Value) getResult();
00111     if (foundComplement) {
00112         setResult(new LogicalAndExpr(op1, op2));
00113     } else {
00114         expr.setOp1(op1);
00115         expr.setOp2(op2);
00116         setResult(expr);
00117     }
00118 }
00119 public void caseLtExpr(LtExpr v) {
00120     if (foundComplement)
00121         setResult(grimp.newGeExpr(v.getOp1(), v.getOp2()));
00122     else
00123         defaultCase(v);
00124 }
00125 public void caseNeExpr(NeExpr v) {
00126     if (foundComplement)
00127         setResult(grimp.newEqExpr(v.getOp1(), v.getOp2()));
00128     else
00129         defaultCase(v);
00130 }
00131 /**
00132  * 
00133  * @param o java.lang.Object
00134  */
00135 public void defaultCase(Object o) {
00136     if (foundComplement)
00137         setResult(new ComplementExpr((Value) o));
00138     else
00139         setResult(o);
00140 }
00141 /**
00142  * 
00143  */
00144 public static Value negate(Value v) {
00145     return pushComplement(new ComplementExpr(v));
00146 }
00147 /**
00148  * 
00149  * @return ca.mcgill.sable.soot.jimple.Value
00150  */
00151 public static Value pushComplement(Value v) {
00152     PredicateTransformer pt = new PredicateTransformer();
00153     v.apply(pt);
00154     return (Value) pt.getResult();
00155 }
00156 }

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