X-Git-Url: http://nitlanguage.org?ds=sidebyside diff --git a/src/mmloader.nit b/src/mmloader.nit index 0ab6078..c63455f 100644 --- a/src/mmloader.nit +++ b/src/mmloader.nit @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This package is used to load a metamodel +# This module is used to load a metamodel package mmloader import metamodel @@ -27,8 +27,8 @@ class Message special Comparable redef type OTHER: Message - readable attr _location: nullable Location - readable attr _text: String + readable var _location: nullable Location + readable var _text: String redef fun <(other: OTHER): Bool do if location == null then return true @@ -38,10 +38,11 @@ special Comparable end redef fun to_s: String do - if location == null then + var l = location + if l == null then return text else - return "{location}: {text}" + return "{l}: {text}" end end end @@ -55,6 +56,9 @@ special MMContext # Number of warnings readable var _warning_count: Int = 0 + # Directory where to generate log files + readable var _log_directory: String = "logs" + # Messages var _messages: Array[Message] = new Array[Message] var _message_sorter: ComparableSorter[Message] = new ComparableSorter[Message] @@ -101,7 +105,7 @@ special MMContext end # Display an info - meth info(s: String, level: Int) + fun info(s: String, level: Int) do if level <= verbose_level then print "{s}" @@ -123,9 +127,12 @@ special MMContext # Option --path readable var _opt_path: OptionArray = new OptionArray("Set include path for loaders (may be used more than once)", "-I", "--path") - # Option --lop + # Option --log readable var _opt_log: OptionBool = new OptionBool("Generate various log files", "--log") - + + # Option --log-dir + readable var _opt_log_dir: OptionString = new OptionString("Directory where to generate log files", "--log-dir") + # Option --only-metamodel readable var _opt_only_metamodel: OptionBool = new OptionBool("Stop after meta-model processing", "--only-metamodel") @@ -147,7 +154,7 @@ special MMContext init do super - option_context.add_option(opt_warn, opt_path, opt_log, opt_only_parse, opt_only_metamodel, opt_help, opt_version, opt_verbose) + option_context.add_option(opt_warn, opt_path, opt_log, opt_log_dir, opt_only_parse, opt_only_metamodel, opt_help, opt_version, opt_verbose) end # Parse and process the options given on the command line @@ -175,6 +182,12 @@ special MMContext var libname = "{sys.program_name.dirname}/../lib" if libname.file_exists then paths.add(libname) + + if opt_log_dir.value != null then _log_directory = opt_log_dir.value.as(not null) + if _opt_log.value then + # Make sure the output directory exists + log_directory.mkdir + end end # Load and process a module in a directory (or a parent directory). @@ -258,7 +271,6 @@ special MMContext # If the module is already loaded, just return it without further processing. fun get_module(module_name: Symbol, from: nullable MMModule): MMModule do - var m: MMModule if from != null then var dir: nullable MMDirectory = from.directory while dir != null do @@ -352,7 +364,7 @@ class ModuleLoader protected fun parse_file(context: ToolContext, file: IFStream, filename: String, module_name: Symbol, dir: MMDirectory): MODULE is abstract # Process a parsed module - protected fun process_metamodel(context: ToolContext, module: MODULE) is abstract + protected fun process_metamodel(context: ToolContext, mod: MODULE) is abstract end redef class MMModule