📄 shell.java
字号:
else if (line.startsWith("read ")) cmdRead(line.substring(5), true); else if (line.startsWith("readq ")) cmdRead(line.substring(6), false); else if (line.equals("reset")) cmdReset(); else if (line.equals("step on")) cmdStepOn(); else if (line.equals("undo")) cmdUndo(); else if (line.equals("write")) cmdWrite(null); else if (line.startsWith("write ")) cmdWrite(line.substring(6)); else if (line.startsWith("load -q ")) cmdGenLoadInvariants(line.substring(8), system(), false); else if (line.startsWith("gen loaded")) cmdGenPrintLoadedInvariants(system()); else if (line.startsWith("gen load")) cmdGenLoadInvariants(line.substring(8), system(), true); else if (line.startsWith("gen unload") || line.equals("unload")) cmdGenUnloadInvariants(line.substring(10), system()); else if (line.startsWith("gen start") || line.equals("gen start")) cmdGenStartProcedure(line.substring(9), system()); else if (line.startsWith("gen flags") || line.equals("gen flags")) cmdGenInvariantFlags(line.substring(9), system()); else if (line.startsWith("gen result") || line.equals("gen result")) cmdGenResult(line.substring(10), system()); else Log.error("Unknown command `" + line + "'. " + "Try `help'."); } /** * Checks integrity constraints of current system state. */ private void cmdCheck(String line) throws NoSystemException { boolean verbose = false; boolean details = false; boolean all = false; boolean noGenInv = true; ArrayList invNames = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(line); // skip command tokenizer.nextToken(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.equals("-v")) { verbose = true; } else if (token.equals("-d")) { details = true; } else if (token.equals("-a")) { all = true; } else { MClassInvariant inv = system().model().getClassInvariant(token); if (system().generator() != null && inv == null) { GFlaggedInvariant gInv = system().generator() .flaggedInvariant(token); if (gInv != null) { inv = gInv.classInvariant(); noGenInv = false; } } if (!noGenInv) { if (inv == null) Log.error("Model has no invariant named `" + token + "'."); else invNames.add(token); } } } PrintWriter out; if (Options.quiet && !Options.quietAndVerboseConstraintCheck) { out = new PrintWriter(new NullWriter()); } else { out = new PrintWriter(Log.out()); } fLastCheckResult = system().state().check(out, verbose, details, all, invNames); } /** * Executes an object manipulation command. */ private void cmdExec(String line) throws NoSystemException { if (line.length() == 0) { Log.error("Command expected after `!'. Try `help'."); return; } // compile command MSystem system = system(); List cmdList = USECompiler.compileCmdList(system.model(), system .state(), new StringReader(line), "<input>", new PrintWriter( System.err)); // compile errors? if (cmdList == null) return; Iterator it = cmdList.iterator(); while (it.hasNext()) { MCmd cmd = (MCmd) it.next(); Log.trace(this, "--- Executing command: " + cmd); try { system.executeCmd(cmd); fSession.executedCmd(cmd); } catch (MSystemException ex) { Log.error(ex.getMessage()); } } } /** * Terminates the program. */ private void cmdExit() { // clean up Log.verbose("Exiting..."); // terminate daVinci fDaVinci.close(); // Write command history to file if (!Options.quiet) { try { fReadline.writeHistory(Options.USE_HISTORY_PATH); } catch (IOException ex) { Log.error("Can't write history file " + Options.USE_HISTORY_PATH + " : " + ex.getMessage()); } } synchronized( fReadlineStack ) { fReadlineStack.closeAll(); fFinished = true; int exitCode = 0; if (Options.quiet && ! lastCheckResult() ) exitCode = 1; if (Options.readlineTest) { System.err.println("readline balance: "+ ReadlineTestReadlineDecorator.getBalance()); System.err.flush(); exitCode = ReadlineTestReadlineDecorator.getBalance(); } System.exit(exitCode); } } /** * Writes a VCG file for a class diagram of the model. */ private void cmdGenVCG(String filename) throws NoSystemException { MSystem system = system(); PrintWriter out = null; try { if (filename == null) out = new PrintWriter(System.out); else { out = new PrintWriter(new BufferedWriter(new FileWriter( filename))); } ModelToGraph.write(out, system.model()); } catch (IOException ex) { Log.error(ex.getMessage()); } finally { if (out != null) { out.flush(); if (filename != null) out.close(); } } } /** * Prints commands for generating a metamodel instance. */ private void cmdGenMM(String filename) throws NoSystemException { MSystem system = system(); PrintWriter out = null; try { if (filename == null) out = new PrintWriter(System.out); else { out = new PrintWriter(new BufferedWriter(new FileWriter( filename))); } MMVisitor v = new MMInstanceGenerator(out); system.model().processWithVisitor(v); } catch (IOException ex) { Log.error(ex.getMessage()); } finally { if (out != null) { out.flush(); if (filename != null) out.close(); } } } /** * Writes source files for aspect-based monitoring of applications. */ private void cmdGenMonitor() throws NoSystemException { MSystem system = system(); String filename = "USEMonitor.java"; PrintWriter out = null; try { if (filename == null) out = new PrintWriter(System.out); else { out = new PrintWriter(new BufferedWriter(new FileWriter( filename))); Log.verbose("writing file `" + filename + "'..."); } new MonitorAspectGenerator(out, system.model()).write(); Log.verbose("done."); } catch (IOException ex) { Log.error(ex.getMessage()); } finally { if (out != null) { out.flush(); if (filename != null) out.close(); } } } /** * Show object diagram with daVinci. */ private void cmdGraph() { System.out.println("Command is not available in this version."); // try { // if ( ! fDaVinci.isRunning() ) // fDaVinci.start(); // fDaVinci.send("graph(new_placed(" + fSystem.state().getDaVinciGraph() // + "))"); // } catch (IOException ex) { // Log.error(ex.getMessage()); // } } /** * Prints help. */ private void cmdHelp(String line) { String cmd = ""; if (line.indexOf("--help") < 0) { cmd = line.substring(4, line.length()); } else { cmd = line.substring(0, line.indexOf("--help")); } HelpForCmd.getInstance().printHelp(cmd); } /** * Prints information about various things. */ private void cmdInfo(String line) throws NoSystemException { StringTokenizer tokenizer = new StringTokenizer(line); try { String subCmd = tokenizer.nextToken(); if (subCmd.equals("class")) { String arg = tokenizer.nextToken(); cmdInfoClass(arg); } else if (subCmd.equals("model")) { cmdInfoModel(); } else if (subCmd.equals("state")) { cmdInfoState(); } else if (subCmd.equals("opstack")) { cmdInfoOpStack(); } else if (subCmd.equals("prog")) { cmdInfoProg(); } else if (subCmd.equals("vars")) { cmdInfoVars(); } else Log.error("Syntax error in info command. Try `help'."); } catch (NoSuchElementException ex) { Log.error("Missing argument to `info' command. Try `help'."); } } /** * Prints information about a class. */ private void cmdInfoClass(String classname) throws NoSystemException { MSystem system = system(); MClass cls = system.model().getClass(classname); if (cls == null) Log.error("Class `" + classname + "' not found."); else { MMVisitor v = new MMPrintVisitor(new PrintWriter(System.out, true)); cls.processWithVisitor(v); int numObjects = system.state().objectsOfClass(cls).size(); System.out.println(numObjects + " object" + ((numObjects == 1) ? "" : "s") + " of this class in current state."); } } /** * Prints information about the model. */ private void cmdInfoModel() throws NoSystemException { MSystem system = system(); MMVisitor v = new MMPrintVisitor(new PrintWriter(System.out, true)); system.model().processWithVisitor(v); int numObjects = system.state().allObjects().size(); System.out.println(numObjects + " object" + ((numObjects == 1) ? "" : "s") + " total in current state."); } /** * Prints the stack of active operations. */ private void cmdInfoOpStack() throws NoSystemException { MSystem system = system(); List opStack = system.callStack(); if (opStack.isEmpty()) Log.println("no active operations."); else { Log.println("active operations: "); int j = 1; for (int i = opStack.size() - 1; i >= 0; i--) { MOperationCall opcall = (MOperationCall) opStack.get(i); MOperation op = opcall.operation(); String s = j++ + ". " + op.cls().name() + "::" + op.signature() + " | " + opcall.targetObject().name() + "." + op.name() + "(" + StringUtil.fmtSeq(opcall.argValues(), ",") + ")"; Log.println(s); } } } /** * Prints information about the running program. */ private void cmdInfoProg() { long total = Runtime.getRuntime().totalMemory();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -