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

ArrayAbstraction.java

00001 package edu.ksu.cis.bandera.abstraction;
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 java.util.*;
00036 import edu.ksu.cis.bandera.abstraction.util.*;
00037 public class ArrayAbstraction extends Abstraction {
00038     private final Abstraction elementAbstraction;
00039     private final IntegralAbstraction indexAbstraction;
00040 /**
00041  * 
00042  * @param elementAbstraction edu.ksu.cis.bandera.abstraction.Abstraction
00043  * @param indexAbstraction edu.ksu.cis.bandera.abstraction.IntegralAbstraction
00044  */
00045 private ArrayAbstraction(Abstraction elementAbstraction, IntegralAbstraction indexAbstraction) {
00046     this.elementAbstraction = elementAbstraction;
00047     this.indexAbstraction = indexAbstraction;
00048 }
00049 /**
00050  * 
00051  * @return boolean
00052  * @param other java.lang.Object
00053  */
00054 public boolean equals(Object other) {
00055     if (other instanceof ArrayAbstraction) 
00056         return toString().equals(other.toString());
00057     else
00058         return false;
00059 }
00060 /**
00061  * 
00062  * @return java.lang.String
00063  * @param packageName java.lang.String;
00064  */
00065 public String generateAbstraction(String packageName) {
00066     String lineSeparator = System.getProperty("line.separator");
00067     boolean isConcreteIndex = indexAbstraction instanceof ConcreteIntegralAbstraction;
00068     String indexAbstractionClassName = indexAbstraction.getClass().getName();
00069     StringBuffer buffer = new StringBuffer();
00070     if (packageName == null) packageName = "";
00071 
00072     if (elementAbstraction instanceof IntegralAbstraction) {
00073         if ("".equals(packageName)) {
00074             buffer.append("package " + packageName + ";" + lineSeparator + lineSeparator);
00075         }
00076         String className = elementAbstraction.toString() + indexAbstraction + "ArrayAbstraction";
00077         buffer.append("public class " + className + " {" + lineSeparator);
00078         buffer.append("  private final int[] elements;" + lineSeparator);
00079         if (isConcreteIndex) {
00080             buffer.append("  public " + className + "(int length) {" + lineSeparator);
00081         } else {
00082             buffer.append("  public " + className + "() {" + lineSeparator);
00083             buffer.append("    int length = " + AbstractionClassLoader.invokeMethod(indexAbstractionClassName, "getNumOfTokens", new Object[0], null, new Vector()) + ";" + lineSeparator);
00084         }
00085         buffer.append("    elements = new int[length];" + lineSeparator);
00086         buffer.append("  }" + lineSeparator);
00087         buffer.append("  public int lookup(int index) {" + lineSeparator);
00088         buffer.append("    int result;" + lineSeparator);
00089         if (isConcreteIndex) {
00090             buffer.append("    result = elements[index];" + lineSeparator);
00091         } else {
00092             buffer.append("    if (" + indexAbstractionClassName + ".isOne2One(index)) {" + lineSeparator);
00093             buffer.append("      result = elements[index];" + lineSeparator);
00094             buffer.append("    } else {" + lineSeparator);
00095             buffer.append("      result = Abstraction.choose(elements[index]);" + lineSeparator);
00096             buffer.append("    }" + lineSeparator);
00097         }
00098         buffer.append("    return result;" + lineSeparator);
00099         buffer.append("  }" + lineSeparator);
00100         buffer.append("  public void update(int index, int value) {" + lineSeparator);
00101         if (isConcreteIndex) {
00102             buffer.append("    elements[index] = value;" + lineSeparator);
00103         } else {
00104             buffer.append("    if (" + indexAbstractionClassName + ".isOne2One(index)) {" + lineSeparator);
00105             buffer.append("      elements[index] = value;" + lineSeparator);
00106             buffer.append("    } else {" + lineSeparator);
00107             buffer.append("      elements[index] = elements[index] | value;" + lineSeparator);
00108             buffer.append("    }" + lineSeparator);
00109         }
00110         buffer.append("  }" + lineSeparator);
00111         buffer.append("}" + lineSeparator);
00112     } else {
00113     }
00114     return buffer.toString();
00115 }
00116 /**
00117  * 
00118  * @return edu.ksu.cis.bandera.abstraction.Abstraction
00119  */
00120 public final Abstraction getElementAbstraction() {
00121     return elementAbstraction;
00122 }
00123 /**
00124  * 
00125  * @return edu.ksu.cis.bandera.abstraction.IntegralAbstraction
00126  */
00127 public final IntegralAbstraction getIndexAbstraction() {
00128     return indexAbstraction;
00129 }
00130 /**
00131  * 
00132  * @return int
00133  */
00134 public int hashCode() {
00135     return toString().hashCode();
00136 }
00137 /**
00138  * 
00139  * @return java.lang.String
00140  */
00141 public String toString() {
00142     return elementAbstraction + "[" + indexAbstraction + "]";
00143 }
00144 /**
00145  * 
00146  * @return edu.ksu.cis.bandera.abstraction.ArrayAbstraction
00147  * @param elementAbstraction edu.ksu.cis.bandera.abstraction.Abstraction
00148  * @param indexAbstraction edu.ksu.cis.bandera.abstraction.IntegralAbstraction
00149  */
00150 public static ArrayAbstraction v(Abstraction elementAbstraction, IntegralAbstraction indexAbstraction) {
00151     return new ArrayAbstraction(elementAbstraction, indexAbstraction);
00152 }
00153 }

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