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

Compiler.java

00001 package edu.ksu.cis.bandera.specification;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 2000   Robby (robby@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 import edu.ksu.cis.bandera.specification.analysis.*;
00036 import edu.ksu.cis.bandera.specification.datastructure.*;
00037 import edu.ksu.cis.bandera.specification.exception.*;
00038 import edu.ksu.cis.bandera.specification.node.*;
00039 import edu.ksu.cis.bandera.specification.pattern.datastructure.*;
00040 import edu.ksu.cis.bandera.annotation.*;
00041 import edu.ksu.cis.bandera.jext.*;
00042 import edu.ksu.cis.bandera.jjjc.*;
00043 import ca.mcgill.sable.soot.*;
00044 import ca.mcgill.sable.soot.jimple.*;
00045 import ca.mcgill.sable.soot.grimp.*;
00046 import java.util.*;
00047 
00048 public class Compiler extends DepthFirstAdapter {
00049     private static Grimp grimp = Grimp.v();
00050     private Hashtable predNodeGrimpTable;
00051     private HashSet placeHolders;
00052     private Pattern pattern;
00053 
00054     private Value currentValue;
00055     private static final String defaultPrefix = "pred__";
00056     private static final String defaultParam = defaultPrefix+"a";  // robbyjo's patch
00057 
00058     private Hashtable parameterTable = new Hashtable();
00059     private Hashtable parameterNameTable = new Hashtable();
00060     private AnnotationManager am = CompilationManager.getAnnotationManager();
00061     private Iterator parametersIterator;
00062 /**
00063  * 
00064  * @param predNodeGrimpTable java.util.Hashtable
00065  * @param placeHolders java.util.HashSet
00066  * @param pattern edu.ksu.cis.bandera.specification.pattern.datastructure.Pattern
00067  * @param node edu.ksu.cis.bandera.specification.node.Node
00068  */
00069 public Compiler(Hashtable predNodeGrimpTable, HashSet placeHolders, Pattern pattern, Node node) {
00070     this.predNodeGrimpTable = predNodeGrimpTable;
00071     this.placeHolders = placeHolders;
00072     this.pattern = pattern;
00073     parametersIterator = pattern.getParametersOccurenceOrder().iterator();
00074     node.apply(this);
00075     buildFormulaConditions();
00076 }
00077 /**
00078  * 
00079  */
00080 private void buildFormulaConditions() {
00081     Value v = null;
00082     QuantifiedVariable qv;
00083     for (Iterator i = placeHolders.iterator(); i.hasNext();) {
00084         StaticFieldRef sfr = (StaticFieldRef) i.next();
00085         SootField sf = sfr.getField();
00086         String fieldName = sf.getName();
00087         String quantifiedVariableName = fieldName.substring(15);
00088         qv = CompilationManager.getQuantifier(quantifiedVariableName);
00089         Value constraint = grimp.newNeExpr(sfr, NullConstant.v());
00090         if (qv.getConstraint() != null) {
00091             constraint = new LogicalAndExpr(constraint, QuantifiedVariableFixer.fix(qv));
00092         }
00093         if (v == null) {
00094             v = constraint;
00095         } else {
00096             v = new LogicalAndExpr(v, constraint);
00097         }
00098     }
00099     if (v != null) {
00100         parameterTable.put(defaultParam, v);
00101     }
00102 }
00103 /**
00104  * 
00105  * @param node edu.ksu.cis.bandera.specification.node.ABinaryExp
00106  */
00107 public void caseABinaryExp(ABinaryExp node) {
00108     node.getLeft().apply(this);
00109     Value leftValue = currentValue;
00110     node.getRight().apply(this);
00111     Value rightValue = currentValue;
00112 
00113     PBinOp binOp = node.getBinOp();
00114     if (binOp instanceof AAndBinOp) {
00115         currentValue = new LogicalAndExpr(leftValue, rightValue);
00116     } else if (binOp instanceof AOrBinOp) {
00117         currentValue = new LogicalOrExpr(leftValue, rightValue);
00118     } else {
00119         currentValue = new LogicalOrExpr(new ComplementExpr(leftValue), rightValue);
00120     }
00121 }
00122 /**
00123  * 
00124  * @param node edu.ksu.cis.bandera.specification.node.AComplementExp
00125  */
00126 public void caseAComplementExp(AComplementExp node) {
00127     node.getExp().apply(this);
00128     currentValue = new ComplementExpr(currentValue);
00129 }
00130 /**
00131  * 
00132  * @param node edu.ksu.cis.bandera.specification.node.AExpWord
00133  */
00134 public void caseAExpWord(AExpWord node) {
00135     node.getExp().apply(this);
00136     String id = (String) parametersIterator.next();
00137     //      String id2 = "pred__" + id.toLowerCase();
00138     String id2 = defaultPrefix + id.toLowerCase(); // robbyjo's patch
00139     parameterNameTable.put(id, id2);
00140     parameterTable.put(id2, currentValue);
00141 }
00142 /**
00143  * 
00144  * @param node edu.ksu.cis.bandera.specification.node.APredicateExp
00145  */
00146 public void caseAPredicateExp(APredicateExp node) {
00147     currentValue = (Value) predNodeGrimpTable.get(node);
00148 }
00149 /**
00150  * 
00151  * @return java.lang.String
00152  * @param mapping java.lang.String
00153  */
00154 public String getFormula(String mapping) throws SpecificationException {
00155     if ("LTL".equalsIgnoreCase(mapping)) {
00156         try {
00157           // (!available U (available && P)) || [] (!available)
00158 //          String ltl = "((pred__a) && (" + pattern.expandMapping("ltl", parameterNameTable) + "))";
00159 //          String result = "((!(pred__a)) U " + ltl + ") || ([](!(pred__a)))";
00160 
00161             // robbyjo's patch
00162             String ltl = "(("+defaultParam+") && (" + pattern.expandMapping("ltl", parameterNameTable) + "))";
00163             String result = "((!("+defaultParam+")) U " + ltl + ") || ([](!("+defaultParam+")))";
00164             return result;
00165         } catch (Exception e) {
00166             throw new SpecificationException(e.getMessage());
00167         }
00168     } else {
00169         throw new SpecificationException("Mapping to " + mapping + " is currently not supported");
00170     }
00171 }
00172 /**
00173  * 
00174  * @return java.util.Hashtable
00175  */
00176 public Hashtable getParameterTable() throws SpecificationException {
00177     return parameterTable;
00178 }
00179 }

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