metamodel: rename 'universal' to 'enum'
[nit.git] / src / abstracttool.nit
index a2ad03b..3f5e50b 100644 (file)
@@ -21,32 +21,46 @@ package abstracttool
 
 import mmloader
 import syntax
+import nit_version
 
 class AbstractCompiler
-special ToolContext
+       super ToolContext
 
-       init
+       init(tool_name: String)
        do
+               _tool_name = tool_name
                super
                register_loader(new SrcModuleLoader)
        end
 
-       meth exec_cmd_line
+       # The name of the tool
+       # Used in help messages for instance
+       readable var _tool_name: String
+
+       fun exec_cmd_line
        do
                process_options
 
+               if opt_version.value then
+                       print "{tool_name} version {nit_version}"
+                       exit(0)
+               end
+
                if opt_help.value then
+                       print "usage: {tool_name} [options] file..."
                        option_context.usage
                        exit(0)
                end
 
                if option_context.rest.length == 0 then
+                       print "usage: {tool_name} [options] file..."
                        option_context.usage
                        exit(1)
                end
 
                var rest = option_context.rest
                var to_do = new Array[MMModule]
+               info("Syntax analysis",1)
                for i in [0..rest.length[ do
                        var mod = get_module_from_filename(rest[i])
                        to_do.add(mod)
@@ -55,37 +69,36 @@ special ToolContext
                        dump_context_info
                end
 
-               if not to_do.is_empty and not opt_only_metamodel.value then
+               if not to_do.is_empty and not opt_only_metamodel.value and not opt_only_parse.value then
                        perform_work(to_do)
                end
        end
 
-       meth perform_work(mods: Array[MMModule]) is abstract
+       fun perform_work(mods: Array[MMModule]) is abstract
 
-       meth dump_context_info
+       fun dump_context_info
        do
                for mod in module_hierarchy do
-                       mod.dump_module_info
+                       mod.dump_module_info(log_directory)
                end     
                var tab = new Array[MMModule]
                tab.add_all(module_hierarchy)
                var name = module_hierarchy.select_smallests(tab).join("-")
 
-               var f = new OFStream.open("{name}.full_class_hierarchy.new.dot")
+               var f = new OFStream.open("{log_directory}/{name}.full_class_hierarchy.new.dot")
                        f.write(class_hierarchy.to_dot)
                f.close
 
-               f = new OFStream.open("{name}.module_hierarchy.new.dot")
+               f = new OFStream.open("{log_directory}/{name}.module_hierarchy.new.dot")
                        f.write(module_hierarchy.to_dot)
                f.close
        end
 end
 
 redef class MMModule
-       meth dump_module_info
+       fun dump_module_info(directory: String)
        do
-               var p = filename.file_path
-               var fname = "{p}/{name}"
+               var fname = "{directory}/{name}"
                var f = new OFStream.open("{fname}.class_hierarchy.new.dot")
                f.write(class_specialization_hierarchy.to_dot)
                f.close
@@ -100,12 +113,18 @@ redef class MMModule
 end
 
 redef class MMLocalClass
-       meth dump_properties(file: OStream)
+       fun dump_properties(file: OStream)
        do
                file.write("class {self}\n")
-               for p in global_properties do
-                       var lp = self[p]
-                       file.write("\t{lp}{lp.signature_for(get_type)}\n")
+               if global.visibility_level == 3 and not self == global.intro then
+                       file.write("\tclass not visible in this module\n")
+               else if mmmodule.visibility_for(global.mmmodule) == 0 then
+                       file.write("\tclass is defined later in the hierarchy\n")
+               else
+                       for p in global_properties do
+                               var lp = self[p]
+                               file.write("\t{lp}{lp.signature_for(get_type)}\n")
+                       end
                end
                file.write("end # {self}\n")
        end