/** Iterates over the files in the list and compiles them one at a time. */ private static void compileFiles( List<File> files, CompileEnvironment instanceEnvironment, MetaFile inputFile) { MathSymbolTableBuilder symbolTable = new MathSymbolTableBuilder(); instanceEnvironment.setSymbolTable(symbolTable); for (Iterator<File> i = files.iterator(); i.hasNext(); ) { File file = i.next(); if (file.isDirectory()) { if (compileDirs) { compileFilesInDir(file, instanceEnvironment); } else { System.err.println("Skipping directory " + file.getName()); } } else if (!isResolveFile(file.getName())) { System.err.println("The file " + file.getName() + " is not a RESOLVE file."); } else if (!file.isFile()) { System.err.println("Cannot find the file " + file.getName() + " in this directory."); } else { instanceEnvironment.setTargetFile(file); compileMainFile(file, instanceEnvironment, symbolTable); } } if (files.size() == 0) { if (instanceEnvironment.flags.isFlagSet(ResolveCompiler.FLAG_WEB)) { compileMainSource(inputFile, instanceEnvironment, symbolTable); } } }
/** * Builds a list of <code>TheoremEntry</code>s representing all available theorems for Theories * currently in scope of the "target file". * * <p>TODO : Currently this will not include theorems included in theories referenced from * included theories. That is, if the target file lists Set_Theory in its "uses" clause, and * Set_Theory lists Boolean_Theory in its "uses" clause, only the theorems from Set_Theory will be * included. * * @return The list of Theorems. */ private void buildTheories() { myTheorems.clear(); myPExpTheorems.clear(); File targetFileName = myInstanceEnvironment.getTargetFile(); ModuleID targetFileID = myInstanceEnvironment.getModuleID(targetFileName); List<ModuleID> availableTheories = myInstanceEnvironment.getTheories(targetFileID); Exp curTheorem; // Add local axioms to the library ModuleDec targetDec = myInstanceEnvironment.getModuleDec(targetFileID); addLocalAxioms(targetDec); // Add any kind of mathematical assertions from any included library SymbolTable curSymbolTable; ModuleScope bindingsInScope; List<Symbol> symbolsInScope; for (ModuleID curModule : availableTheories) { curSymbolTable = myInstanceEnvironment.getSymbolTable(curModule); bindingsInScope = curSymbolTable.getModuleScope(); symbolsInScope = bindingsInScope.getLocalTheoremNames(); for (Symbol s : symbolsInScope) { curTheorem = bindingsInScope.getLocalTheorem(s).getValue(); addTheoremToLibrary(s.getName(), curTheorem); } } }
private String getProofFileName() { File file = myInstanceEnvironment.getTargetFile(); ModuleID cid = myInstanceEnvironment.getModuleID(file); file = myInstanceEnvironment.getFile(cid); String filename = file.toString(); int temp = filename.indexOf("."); String tempfile = filename.substring(0, temp); String mainFileName; mainFileName = tempfile + ".proof"; return mainFileName; }
/** * Constructs a new prover with the given <code>SymbolTable</code> and sets it immediately to work * on the verification conditions represented in the provided <code>Collection</code> of <code> * AssertiveCode</code>. If this constructor returns without throwing an exception, the VCs have * been proved. Otherwise, an exception is thrown indicating which VC could not be proved (or was * proved inconsistent). * * @param symbolTable The current symbol table. May not be <code>null</code>. * @param vCs A list of verification conditions in the form of <code>AssertiveCode</code>. May not * be <code>null</code>. * @param maxDepth The maximum length of proof the prover should consider. * @throws UnableToProveException If a given VC cannot be proved in a reasonable amount of time. * @throws VCInconsistentException If a given VC can be proved inconsistent. * @throes NullPointerException If <code>symbolTable</code> or <code>vC</code> is <code>null * </code>. */ public Prover( final MathExpTypeResolver typer, final Iterable<VerificationCondition> vCs, final CompileEnvironment instanceEnvironment) throws ProverException { if (instanceEnvironment.flags.isFlagSet(FLAG_TIMEOUT)) { TIMEOUT = Long.parseLong( instanceEnvironment.flags.getFlagArgument(FLAG_TIMEOUT, FLAG_TIMEOUT_ARG_NAME)); } else { TIMEOUT = Integer.MAX_VALUE; } myInstanceEnvironment = instanceEnvironment; allProved = true; if (!myInstanceEnvironment.flags.isFlagSet(FLAG_NOGUI)) { myProgressWindow = new ProofProgressWindow("VC", null); } myTyper = typer; buildTheories(); try { proveVCs(vCs); CompileReport myReport = myInstanceEnvironment.getCompileReport(); if (!myReport.hasError() && allProved) { myReport.setProveSuccess(); } } catch (UnsupportedOperationException e) { // Exp.equivalent() is not consistently implemented throughout the // absyn package. By default, it will just throw an // UnsupportedOperationException if it is called and has not been // overridden. This will catch this case and produce a useful // error message. // On the other hand, it's sometimes useful for debugging to see a // full stack trace. Uncomment this next line to see that instead: if (true) throw new RuntimeException(e); ErrorHandler handler = myInstanceEnvironment.getErrorHandler(); handler.error(e.getMessage() + "\n\nTry disabling the -prove option."); } if (!myInstanceEnvironment.flags.isFlagSet(FLAG_NOGUI)) { myProgressWindow.dispose(); } }
public static void compileMainFile( File file, CompileEnvironment instanceEnvironment, MathSymbolTableBuilder symbolTable) { Controller control = new Controller(instanceEnvironment); control.compileTargetFile(file, symbolTable); if (instanceEnvironment.showBuild()) { // LOG.debug("showBuild flag set, printing module dec."); printModuleDec(file, instanceEnvironment); } else if (instanceEnvironment.showEnv()) { printEnvironment(file, instanceEnvironment); } else if (instanceEnvironment.showTable() || instanceEnvironment.showBind()) { // printSymbolTable(file, instanceEnvironment); } }
public static void main(String[] args) { // Environment.newInstance(); // env = Environment.getInstance(); setUpFlagDependencies(); try { CompileEnvironment compileEnvironment = new CompileEnvironment(args); args = compileEnvironment.getRemainingArgs(); ErrorHandler err = new ErrorHandler(compileEnvironment); compileEnvironment.setErrorHandler(err); // compileEnvironment.setUserFileMap(getFakeHashMap()); // Environment env = new Environment(compileEnvironment); // env.setErrorHandler(err); String preferredMainDirectory = null; List<File> files = new List<File>(); if (args.length >= 1 && !compileEnvironment.flags.isFlagSet(FLAG_HELP)) { for (int i = 0; i < args.length; i++) { if (args[i].equals("-showBuild")) { compileEnvironment.setShowBuildFlag(); } else if (args[i].equals("-showEnv")) { compileEnvironment.setShowEnvFlag(); } else if (args[i].equals("-showTable")) { compileEnvironment.setShowTableFlag(); } else if (args[i].equals("-showBind")) { compileEnvironment.setShowBindFlag(); } else if (args[i].equals("-showImports")) { compileEnvironment.setShowImportsFlag(); } else if (args[i].equals("-showIndirect")) { compileEnvironment.setShowIndirectFlag(); } else if (args[i].equals("-R")) { compileDirs = true; } else if (args[i].equals("-PVCs")) { compileEnvironment.setPerformanceFlag(); } else if (args[i].equalsIgnoreCase("-maindir")) { if (i + 1 < args.length) { i++; preferredMainDirectory = args[i]; } } else if (args[i].equals("-D")) { if (i + 1 < args.length) { i++; mainDirName = args[i]; } } else if (args[i].equals("-o")) { if (i + 1 < args.length) { String outputFile; i++; outputFile = args[i]; compileEnvironment.setOutputFileName(outputFile); } } else { files.add(getAbsoluteFile(args[i])); } } if (!compileEnvironment.flags.isFlagSet(ResolveCompiler.FLAG_WEB)) { if (!compileEnvironment.flags.isFlagSet(ResolveCompiler.FLAG_NO_DEBUG)) { System.out.println("RESOLVE Compiler/Verifier - " + VERSION + " Version."); System.out.println(" Use -help flag for options."); } } if (compileEnvironment.flags.isFlagSet(ResolveCompiler.FLAG_NO_DEBUG)) { compileEnvironment.setDebugOff(); } setupEnv(preferredMainDirectory, compileEnvironment); MetaFile dummy = null; compileFiles(files, compileEnvironment, dummy); } else { printHelpMessage(compileEnvironment); } } catch (FlagDependencyException fde) { System.out.println("RESOLVE Compiler/Verifier - " + VERSION + " Version."); System.out.println(" Use -help flag for options."); System.err.println(fde.getMessage()); } }
private static void printEnvironment(File file, CompileEnvironment env) { System.out.println(); System.out.println(env.toString()); }
private static void printModuleDec(File file, CompileEnvironment env) { if (env.contains(file)) { ModuleDec dec = env.getModuleDec(env.getModuleID(file)); System.out.println(dec.asString(0, 2)); } }
/** Sets up the compilation environment */ private static void setupEnv(String preferredMainDirectory, CompileEnvironment env) { /*if (bodies) { env.setCompileBodiesFlag(); }*/ env.setMainDir(getMainDir(preferredMainDirectory)); }
/** * Attempts to prove a single VC. If this method returns without throwing an exception, then the * VC was proved. * * @param vC The verification condition to be proved. May not be <code>null</code>. * @param theorems A list of theorems that may be applied as part of the proof. May not be <code> * null</code>. * @param maxDepth The maximum number of steps the prover should attempt before giving up on a * proof. * @param metrics A reference to the metrics the prover should keep on the proof in progress. May * not be <code>null</code>. * @param p The prover to be used if we're using the new prover, or <code>null</code> if we're * supposed to use to legacy prover. * @throws UnableToProveException If the VC cannot be proved in a reasonable amount of time. * @throws VCInconsistentException If the VC can be proved inconsistent. * @throws NullPointerException If <code>vC</code>, <code>theorems</code>, or <code>metrics</code> * is <code>null</code>. */ private void proveVC( final VerificationCondition vC, final Metrics metrics, FileWriter proofFile, VCProver p) throws VCInconsistentException { if (myInstanceEnvironment.flags.isFlagSet(FLAG_VERBOSE)) { System.out.println("\n\n############################# VC " + "#############################"); System.out.println(vC); } long startTime = System.currentTimeMillis(); vC.propagateExpansionsInPlace(); ProverException exitInformation = null; ActionCanceller c = new ActionCanceller(); if (!myInstanceEnvironment.flags.isFlagSet(FLAG_NOGUI)) { myProgressWindow.setTitle("VC " + vC.getName()); myProgressWindow.setActionCanceller(c); } if (p == null) { if (myInstanceEnvironment.flags.isFlagSet(FLAG_DEBUG)) { p = setUpOldProverDebug(vC); } else { p = setUpOldProver(vC); } } if (myInstanceEnvironment.flags.isFlagSet(ResolveCompiler.FLAG_WEB)) { output.append("<vcProve id=\"" + vC.getName() + "\">"); } else { output.append(vC.getName() + " "); } // System.out.print(vC.getName() + " "); try { p.prove(vC.copy(), myProgressWindow, c, System.currentTimeMillis() + TIMEOUT); } catch (UnableToProveException e) { exitInformation = e; output.append("Skipped after "); // System.out.print("Skipped after "); allProved = false; if (proofFile != null) { try { proofFile.append(vC.getName() + " failed.\n\n"); } catch (IOException ex) { } } } catch (VCProvedException e) { exitInformation = e; output.append("Proved in "); // System.out.print("Proved in "); if (proofFile != null) { try { proofFile.append(vC.getName() + " succeeded.\n\n"); proofFile.append(e.toString()); } catch (IOException ex) { } } } printExitReport(startTime, exitInformation); if (myInstanceEnvironment.flags.isFlagSet(ResolveCompiler.FLAG_WEB)) { output.append("</vcProve>"); myInstanceEnvironment.getCompileReport().setProveVCs(output.toString()); } }