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

PredicateCompiler.java

00001 package gov.nasa.arc.ase.jpf.tools;
00002 
00003 //#ifdef BUCHI && BANDERA
00004 import edu.ksu.cis.bandera.specification.predicate.lexer.*;
00005 import edu.ksu.cis.bandera.specification.predicate.node.*;
00006 import edu.ksu.cis.bandera.specification.predicate.parser.*;
00007 import gov.nasa.arc.ase.jpf.JPFErrorException;
00008 import java.io.*;
00009 import java.lang.reflect.*;
00010 
00011 public class PredicateCompiler {
00012   public static void compile(String fname, String cname, String mname) {
00013     Reader in = null;
00014     if(fname.equals("-"))
00015       in = new InputStreamReader(System.in);
00016     else if(fname.endsWith(".p")) {
00017       try {
00018     in = new FileReader(fname);
00019       } catch(FileNotFoundException e) {
00020     throw new JPFErrorException("Can't open file: " + fname);
00021       }
00022     } else
00023       in = new StringReader(fname);
00024 
00025     Parser p =
00026       new Parser(
00027       new Lexer(
00028         new PushbackReader(in, 1024)));
00029 
00030     Start tree;
00031     try {
00032       tree = p.parse();
00033     } catch(IOException e) {
00034       throw new JPFErrorException("io error: " + e.getMessage());
00035     } catch(LexerException e) {
00036       throw new JPFErrorException("lexer error: " + e.getMessage());
00037     } catch(ParserException e) {
00038       throw new JPFErrorException("parse error: " + e.getMessage());
00039     }
00040 
00041     try {
00042       Class c = cname == null ? null : Class.forName(cname);
00043       Method m = mname == null ? null : getMethod(c, mname);
00044       tree.apply(
00045       new Translation(c, m));
00046     } catch(ClassNotFoundException e) {
00047       throw new JPFErrorException("class not found: " + cname);
00048     } catch(NoSuchMethodException e) {
00049       throw new JPFErrorException("method not found: " + mname);
00050     }
00051   }  
00052   private static Method getMethod(Class c, String m) throws NoSuchMethodException {
00053     while(c != null) {
00054       Method[] ms = c.getDeclaredMethods();
00055 
00056       for(int i = 0, l = ms.length; i < l; i++)
00057     if(Signature.getSignature(ms[i]).equals(m))
00058       return ms[i];
00059 
00060       c = c.getSuperclass();
00061     }
00062 
00063     throw new NoSuchMethodException(m);
00064   }  
00065   public static void main(String[] args) {
00066     switch(args.length) {
00067       case 1: compile(args[0], null, null); break;
00068       case 2: compile(args[0], args[1], null); break;
00069       case 3: compile(args[0], args[1], args[2]); break;
00070 
00071       default:
00072     usage();
00073     }
00074   }  
00075   public static void usage() {
00076     System.err.println("usage:");
00077     System.err.println("\t java gov.nasa.arc.ase.jpf.jvm.tool.PredicateCompiler <filename> [<classname> [<methodname>]]");
00078     System.exit(1);
00079   }  
00080 }

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