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

AbstractionPrinter.java

00001 package edu.ksu.cis.bandera.abstraction.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 java.io.*;
00036 import java.util.*;
00037 import edu.ksu.cis.bandera.abstraction.specification.node.*;
00038 import edu.ksu.cis.bandera.abstraction.specification.analysis.*;
00039 public class AbstractionPrinter extends DepthFirstAdapter {
00040     private static final String lineSeparator = System.getProperty("line.separator");
00041     private StringBuffer buffer = new StringBuffer();
00042     private Vector expAbstractDefs = new Vector();
00043     private boolean isFull;
00044 /**
00045  * 
00046  * @param isFull boolean
00047  */
00048 private AbstractionPrinter(boolean isFull) {
00049     this.isFull = isFull;
00050 }
00051 /**
00052  * 
00053  * @param node edu.ksu.cis.bandera.abstraction.specification.node.AAbstractFunction
00054  */
00055 public void caseAAbstractFunction(AAbstractFunction node) {
00056     println("    abstract (" + node.getId().toString().trim() + ")");
00057     println("      begin");
00058     {
00059         Object temp[] = node.getAbstractDef().toArray();
00060         for (int i = 0; i < temp.length; i++) {
00061             ((PAbstractDef) temp[i]).apply(this);
00062         }
00063     }
00064     println("      end");
00065 }
00066 /**
00067  * 
00068  * @param node edu.ksu.cis.bandera.abstraction.specification.node.AAnyAbstractDef
00069  */
00070 public void caseAAnyAbstractDef(AAnyAbstractDef node) {
00071     if (expAbstractDefs.size() > 0) {
00072         Iterator i = expAbstractDefs.iterator();
00073         String result = (String) i.next();
00074         if (result.startsWith("(")) result = "!" + result;
00075         else result = "!(" + result + ")";
00076         while (i.hasNext()) {
00077             String temp = (String) i.next();
00078             if (temp.startsWith("(")) result = result + " && !" + temp;
00079             else result = result + " && !(" + temp + ")";
00080         }
00081         println("        " + result + " -> " + node.getId().toString().trim() + ";");
00082     } else {
00083         println("        _" + " -> " + node.getId().toString().trim() + ";");
00084     }
00085 }
00086 /**
00087  * 
00088  * @param node edu.ksu.cis.bandera.abstraction.specification.node.AAnyPattern
00089  */
00090 public void caseAAnyPattern(AAnyPattern node) {
00091     String result = "";
00092     int i = 0;
00093     for (StringTokenizer t = new StringTokenizer(node.getTokenTokenSet().toString(), ",{} "); t.hasMoreTokens(); i++) {
00094         result += (t.nextToken() + ", ");
00095     }
00096     if (i == 1) {
00097         println("        _ -> " + result.substring(0, result.length() - 2) + ";");
00098     } else {
00099         println("        _ -> {" + result.substring(0, result.length() - 2) + "};");
00100     }
00101 }
00102 /**
00103  * 
00104  * @param node edu.ksu.cis.bandera.abstraction.specification.node.ADefaultToken
00105  */
00106 public void caseADefaultToken(ADefaultToken node) {
00107     println("    DEFAULT = " + node.getId().toString().trim() + ";");
00108 }
00109 /**
00110  * 
00111  * @param node edu.ksu.cis.bandera.abstraction.specification.node.AExpAbstractDef
00112  */
00113 public void caseAExpAbstractDef(AExpAbstractDef node) {
00114     String exp = node.getExp().toString().trim();
00115     expAbstractDefs.add(exp);
00116     println("        " + exp + " -> " + node.getId().toString().trim() + ";");
00117 }
00118 /**
00119  * 
00120  * @param node edu.ksu.cis.bandera.abstraction.specification.node.AOne2oneSet
00121  */
00122 public void caseAOne2oneSet(AOne2oneSet node) {
00123     if (node.getIdList() != null) {
00124         String result = "";
00125         for (StringTokenizer t = new StringTokenizer(node.getIdList().toString(), ", "); t.hasMoreTokens();) {
00126             result += (t.nextToken() + ", ");
00127         }
00128         println("    ONE2ONE = {" + result.substring(0, result.length() - 2) + "};");
00129     } else {
00130         println("    ONE2ONE = {};");
00131     }
00132 }
00133 /**
00134  * 
00135  * @param node edu.ksu.cis.bandera.abstraction.specification.node.AOperator
00136  */
00137 public void caseAOperator(AOperator node) {
00138     println("    operator " + node.getOp() + node.getId());
00139     println("      begin");
00140     {
00141         Object temp[] = node.getPattern().toArray();
00142         for (int i = 0; i < temp.length; i++) {
00143             ((PPattern) temp[i]).apply(this);
00144         }
00145     }
00146     println("      end");
00147 }
00148 /**
00149  * 
00150  * @param node edu.ksu.cis.bandera.abstraction.specification.node.APatternPattern
00151  */
00152 public void caseAPatternPattern(APatternPattern node) {
00153     String result = "";
00154     int i = 0;
00155     for (StringTokenizer t = new StringTokenizer(node.getTokenTokenSet().toString(), ",{} "); t.hasMoreTokens();) {
00156         result += (t.nextToken() + ", ");
00157         i++;
00158     }
00159     if (i == 1) {
00160         println("        (" + node.getLId().toString().trim() + ", " + node.getRId().toString().trim() + ") -> " + result.substring(0, result.length() - 2) + ";");
00161     } else {
00162         println("        (" + node.getLId().toString().trim() + ", " + node.getRId().toString().trim() + ") -> {" + result.substring(0, result.length() - 2) + "};");
00163     }
00164 }
00165 /**
00166  * 
00167  * @param node edu.ksu.cis.bandera.abstraction.specification.node.ATest
00168  */
00169 public void caseATest(ATest node) {
00170     println("    test " + node.getTOp() + node.getId());
00171     println("      begin");
00172     {
00173         Object temp[] = node.getPattern().toArray();
00174         for (int i = 0; i < temp.length; i++) {
00175             ((PPattern) temp[i]).apply(this);
00176         }
00177     }
00178     println("      end");
00179 }
00180 /**
00181  * 
00182  * @param node edu.ksu.cis.bandera.abstraction.specification.node.ATokenSet
00183  */
00184 public void caseATokenSet(ATokenSet node) {
00185     String result = "";
00186     for (StringTokenizer t = new StringTokenizer(node.getIdSet().toString(), ",{} "); t.hasMoreTokens();) {
00187         result += (t.nextToken() + ", ");
00188     }
00189     println("    TOKENS = {" + result.substring(0, result.length() - 2) + "};");
00190 }
00191 /**
00192  * 
00193  * @param node edu.ksu.cis.bandera.abstraction.specification.node.AUnit
00194  */
00195 public void caseAUnit(AUnit node) {
00196     println("abstraction " + node.getId() + "extends " + node.getType());
00197     println("  begin");
00198     node.getTokenSet().apply(this);
00199     if (isFull) {
00200         if (node.getDefaultToken() != null) {
00201             node.getDefaultToken().apply(this);
00202         }
00203         if (node.getOne2oneSet() != null) {
00204             node.getOne2oneSet().apply(this);
00205         }
00206     }
00207     node.getAbstractFunction().apply(this);
00208     
00209     if (isFull) {
00210         Object temp[] = node.getOperatorTest().toArray();
00211         for (int i = 0; i < temp.length; i++) {
00212             ((POperatorTest) temp[i]).apply(this);
00213         }
00214     }
00215     println("  end");
00216 }
00217 /**
00218  * 
00219  * @return java.lang.String
00220  * @param node edu.ksu.cis.bandera.abstraction.specification.node.Start
00221  * @param isFull boolean
00222  */
00223 public static String print(Start node, boolean isFull) {
00224     if (node != null) {
00225         AbstractionPrinter printer = new AbstractionPrinter(isFull);
00226         node.apply(printer);
00227         return printer.buffer.toString();
00228     }
00229     return null;
00230 }
00231 /**
00232  * 
00233  * @param writer java.io.Writer
00234  * @param node edu.ksu.cis.bandera.abstraction.specification.node.Start
00235  * @param boolean isFull
00236  */
00237 public static void print(Writer writer, Start Node, boolean isFull) throws IOException {
00238     writer.write(print(Node, isFull));
00239     writer.flush();
00240 }
00241 /**
00242  * 
00243  * @param s java.lang.String
00244  */
00245 private void println(String s) {
00246     buffer.append(s + lineSeparator);
00247 }
00248 }

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