📄 smc.java
字号:
} else { _nocatch = true; argsConsumed = 1; } } else if (args[i].startsWith("-ret") == true) { if (_supportsOption(RETURN_FLAG) == false) { retcode = false; _errorMsg = _targetLanguage.name() + " does not support " + RETURN_FLAG + "."; } else { _return = true; argsConsumed = 1; } } else if (args[i].startsWith("-ref") == true) { if (_supportsOption(REFLECT_FLAG) == false) { retcode = false; _errorMsg = _targetLanguage.name() + " does not support " + REFLECT_FLAG + "."; } else { _reflection = true; argsConsumed = 1; } } else if (args[i].startsWith("-se") == true) { if (_supportsOption(SERIAL_FLAG) == false) { retcode = false; _errorMsg = _targetLanguage.name() + " does not support " + SERIAL_FLAG + "."; } else { _serial = true; argsConsumed = 1; } } else if (args[i].startsWith("-verb") == true) { _verbose = true; argsConsumed = 1; } else if (args[i].startsWith("-vverb") == true) { _fsmVerbose = true; argsConsumed = 1; } else { retcode = false; _errorMsg = "Unknown option (" + args[i] + ")"; } } // Was a state map source file given? It must be the // last argument in the list. if (helpFlag == false && retcode == true) { if (i == args.length) { retcode = false; _errorMsg = "Missing source file"; } else { File sourceFile; for (; i < args.length && retcode == true; ++i) { // The file name must end in ".sm". if (args[i].toLowerCase().endsWith(".sm") == false) { retcode = false; _errorMsg = "Source file name must end in " + "\".sm\" (" + args[i] + ")"; } else { sourceFile = new File(args[i]); if (sourceFile.exists() == false) { retcode = false; _errorMsg = "No such file named \"" + args[i] + "\""; } else if (sourceFile.canRead() == false) { retcode = false; _errorMsg = "Source file \"" + args[i] + "\" is not readable"; } else { _sourceFileList.add(args[i]); } } } } } return (retcode); } // Process the -help and -version flags separately. private static boolean _needHelp(String[] args) { int i; boolean retval = false; for (i = 0; i < args.length && retval == false; ++i) { if (args[i].startsWith("-hel") == true) { retval = true; _usage(System.out); } else if (args[i].startsWith("-vers") == true) { retval = true; System.out.println(APP_NAME + " " + _version); } } return (retval); } // Returns the target language found in the command line // arguments. Throws an IllegalArgumentException if more than // one target language is specified. // As a side effect sets the default suffix. private static Language _findTargetLanguage(String[] args) { int i; Language lang; Language retval = null; for (i = 0; i < args.length; ++i) { // Is this argument a language name? if ((lang = _findLanguage(args[i])) != null) { // Only one target langugage can be specified. if (retval != null && retval != lang) { throw ( new IllegalArgumentException( "Only one target language " + "may be specified")); } else { retval = lang; } } } return (retval); } // Returns the langugage record associated with the given // command line option. private static Language _findLanguage(String option) { int index; Language retval = null; for (index = 1; index < _languages.length && retval == null; ++index) { if (option.equals( _languages[index].optionFlag()) == true) { retval = _languages[index]; } } return (retval); } // Returns true if the target language supports the specified // option. private static boolean _supportsOption(String option) { List<Language> languages = _optionMap.get(option); return ( languages != null && languages.contains(_targetLanguage)); } // Returns true if the string is a valid C++ cast. private static boolean _isValidCast(String castType) { return (castType.equals("dynamic_cast") == true || castType.equals("static_cast") == true || castType.equals("reinterpret_cast") == true); } // Returns true if the path is a valid destination directory. private static boolean _isValidDirectory(String path) { boolean retcode = false; try { File pathObj = new File(path); if (pathObj.isDirectory() == false) { _errorMsg = "\"" + path + "\" is not a directory"; } else if (pathObj.canWrite() == false) { _errorMsg = "\"" + path + "\" is not writeable"; } else { retcode = true; } } catch (SecurityException securex) { _errorMsg = "Unable to access \"" + path + "\""; } return (retcode); } private static void _usage(PrintStream stream) { stream.print("usage: "); stream.print(APP_NAME); stream.print(" [-suffix suffix]"); stream.print(" [-g]"); stream.print(" [-nostreams]"); stream.print(" [-version]"); stream.print(" [-verbose]"); stream.print(" [-help]"); stream.print(" [-sync]"); stream.print(" [-noex]"); stream.print(" [-nocatch]"); stream.print(" [-serial]"); stream.print(" [-return]"); stream.print(" [-reflect]"); stream.print(" [-cast cast_type]"); stream.print(" [-d directory]"); stream.print(" [-headerd directory]"); stream.print(" [-glevel int]"); stream.print( " {-c | -c++ | -csharp | -graph | -groovy | -java | "); stream.print( "-lua | -objc | -perl | -php | -python | -ruby | "); stream.print("-scala | -table |-tcl | -vb}"); stream.println(" statemap_file"); stream.println(" where:"); stream.println( "\t-suffix Add this suffix to output file"); stream.println( "\t-g Add debugging to generated code"); stream.println("\t-nostreams Do not use C++ iostreams "); stream.print("\t "); stream.println("(use with -c++ only)"); stream.print("\t-version Print smc version "); stream.println("information to standard out and exit"); stream.print("\t-verbose "); stream.println("Output more compiler messages."); stream.print("\t-help Print this message to "); stream.println("standard out and exit"); stream.println( "\t-sync Synchronize generated Java code "); stream.print("\t "); stream.println("(use with -java, -groovy, -scala, -vb and -csharp only)"); stream.println( "\t-noex Do not generate C++ exception throws "); stream.print("\t "); stream.println("(use with -c++ only)"); stream.print( "\t-nocatch Do not generate try/catch/rethrow "); stream.println("code (not recommended)"); stream.println( "\t-serial Generate serialization code"); stream.print("\t-return "); stream.println("Smc.main() returns, not exits"); stream.print("\t "); stream.println("(use this option with ANT)"); stream.println("\t-reflect Generate reflection code"); stream.print("\t "); stream.print("(use with -java, -tcl, -vb, -csharp, "); stream.println("-groovy, -lua, -perl, -php, -python, -ruby and -scala only)"); stream.println("\t-cast Use this C++ cast type "); stream.print("\t "); stream.println("(use with -c++ only)"); stream.println( "\t-d Place generated files in directory"); stream.print( "\t-headerd Place generated header files in "); stream.println("directory"); stream.print("\t "); stream.println("(use with -c, -c++ only)"); stream.print( "\t-glevel Detail level from 0 (least) to 2 "); stream.println("(greatest)"); stream.print("\t "); stream.println("(use with -graph only)"); stream.println("\t-c Generate C code"); stream.println("\t-c++ Generate C++ code"); stream.println("\t-csharp Generate C# code"); stream.println("\t-graph Generate GraphViz DOT file"); stream.println("\t-groovy Generate Groovy code"); stream.println("\t-java Generate Java code"); stream.println("\t-lua Generate Lua code"); stream.println("\t-objc Generate Objective-C code"); stream.println("\t-perl Generate Perl code"); stream.println("\t-php Generate PHP code"); stream.println("\t-python Generate Python code"); stream.println("\t-ruby Generate Ruby code"); stream.println("\t-scala Generate Scala code"); stream.println("\t-table Generate HTML table code"); stream.println("\t-tcl Generate [incr Tcl] code"); stream.println("\t-vb Generate VB.Net code"); stream.println(); stream.println( " Note: statemap_file must end in \".sm\""); stream.print( " Note: must select one of -c, -c++, -csharp, "); stream.print("-graph, -groovy, -java, -lua, -objc, -perl, "); stream.println( "-php, -python, -ruby, -scala, -table, -tcl or -vb."); return; } // Returns the <name> portion from <path>/<name>.sm. private static String _getFileName(String fullName) { File file = new File(fullName); String fileName = file.getName(); // Note: this works because the file name's form // has already been validated as ending in .sm. return ( fileName.substring( 0, fileName.toLowerCase().indexOf(".sm"))); } // Generate the State pattern in the target language. private static void _generateCode(SmcFSM fsm) throws FileNotFoundException, IOException, ParseException { int endIndex = _sourceFileName.length() - 3; String srcFilePath = "." + System.getProperty("file.separator"); String srcFileBase = _sourceFileName.substring(0, endIndex); String headerFileName = ""; FileOutputStream headerFileStream = null; PrintStream headerStream = null; SmcCodeGenerator headerGenerator = null; String srcFileName = ""; FileOutputStream sourceFileStream = null; PrintStream sourceStream = null; SmcCodeGenerator generator = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -