//-*-java-*- Cool { static void usage() {{ System.err.println("Usage: demjava cool [-outputdir dir] file.cool"); }} /* * Entry Point */ public static Vector cool(String[] args) throws ParseException {{ // parse input file: if (args.length == 0 || args.length == 2 || args.length > 3) { usage(); return null; } String inputfilename = args[0]; if (args.length == 3) { if (args[0].equals("-outputdir")) { outputdir = args[1]; inputfilename = args[2]; } else { usage(); return null; } } try { FileInputStream infile = new FileInputStream(inputfilename); parsed_input = Cool.parse(infile); } catch(FileNotFoundException e) { throw new RuntimeException(e.toString()); } // set output file: Vector outputfiles = new Vector(); File outdir = new File(outputdir); if(!outdir.exists()) outdir.mkdirs(); try { File outfile = new File(outputdir, "cool.wvr"); outputfiles.addElement(outfile); out = new PrintWriter(new FileOutputStream(outfile)); } catch(IOException e) { throw new RuntimeException(e.toString()); } // generate weaver code: out.print("cool:\n\n"); LockClass.print(out); XVectorClass.print(out); OutputVisitor v_out = new OutputVisitor(out); parsed_input.toMethMans(v_out); parsed_input.toRest(v_out); v_out.output(); // cleanup; out.flush(); out.close(); Err.report(); return outputfiles; }} {{ static Cool parsed_input; static PrintWriter out; static String outputdir = "gen"; }} traversal toMethMans(OutputVisitor) { bypassing {CondVarDeclaration,VarDeclaration,SelfexMethodSet,MutexMethodSet} to *; } traversal toRest(OutputVisitor) { bypassing MethodManager to *; } } {Statement,Expression,CondVarExp} { String unparse() {{ StringWriter sw = new StringWriter(); this.universal_trv0(new PrintVisitor(new PrintWriter(sw))); return sw.toString(); }} }