Merge: Cleanup and synchronize options in manpages
authorJean Privat <jean@pryen.org>
Thu, 22 Oct 2015 00:45:40 +0000 (20:45 -0400)
committerJean Privat <jean@pryen.org>
Thu, 22 Oct 2015 00:45:40 +0000 (20:45 -0400)
A tedious work to detect and fix undocumented options in the manpages of tools.
This also synchronizse the description of `--help` and the text in manpages (when there is a diversion, the best one if often selected).

Cherry on the cake: a new script `check_manpage` can automatically check that new options of tools are documented in the man. Close #1772

Pull-Request: #1778
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

21 files changed:
.hgignore [deleted file]
lib/core/collection/m.dot [deleted file]
lib/niti_runtime.nit
lib/serialization/serialization.nit
src/loader.nit
src/model/model_base.nit
src/model/model_visitor.nit [new file with mode: 0644]
src/test_model_visitor.nit [new file with mode: 0644]
src/uml/uml_class.nit
src/uml/uml_module.nit
tests/nit.args
tests/nitcg.skip
tests/niti.skip
tests/nitvm.skip
tests/sav/nit_args5.res [new file with mode: 0644]
tests/sav/nit_args6.res [new file with mode: 0644]
tests/sav/nitce/test_binary_deserialization_alt1.res
tests/sav/nitce/test_json_deserialization_alt1.res
tests/sav/test_model_visitor.res [new file with mode: 0644]
tests/sav/test_model_visitor_args1.res [new file with mode: 0644]
tests/test_model_visitor.args [new file with mode: 0644]

diff --git a/.hgignore b/.hgignore
deleted file mode 100644 (file)
index 011a9e8..0000000
--- a/.hgignore
+++ /dev/null
@@ -1,19 +0,0 @@
-syntax: glob
-*.bak
-.nit_compile*
-*.orig
-nitc
-nitdoc
-doc/stdlib
-
-c_src/*.o
-c_src/*.cksum
-
-tests/*.res
-tests/*.log
-tests/*.bin
-tests/*.err
-tests/alt
-
-syntax: regexp
-
diff --git a/lib/core/collection/m.dot b/lib/core/collection/m.dot
deleted file mode 100644 (file)
index 762472d..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-digraph g {
-rankdir=BT;node[shape=box];
-subgraph cluster_37053984 {
-label=".."
-       m_41649040 [label="kernel"]
-subgraph cluster_37183344 {
-label="../collection"
-       m_38874592 [label="array"]
-       m_40662960 [label="abstract_collection"]
-}
-}
-       m_38874592 -> m_40662960
-       m_40662960 -> m_41649040
-}
index dd6241b..198f3a8 100644 (file)
@@ -27,17 +27,10 @@ redef class Sys
        # Read the next useful line from file-name arguments
        private fun read_next_line
        do
-               if stdin.eof then
+               while stdin.eof do
                        open_next_stream
                end
-               var line = stdin.read_line
-               loop
-                       if not stdin.eof then break
-                       open_next_stream
-                       if not line.is_empty then break
-                       line = stdin.read_line
-               end
-               self.line = line
+               self.line = stdin.read_line
        end
 
        # Open the next file until there is no more arguments
@@ -49,5 +42,5 @@ redef class Sys
        end
 
        # The next line to process by the main program
-       var line: String
+       var line: String is noautoinit
 end
index e3ca6b3..7c689b6 100644 (file)
@@ -191,7 +191,7 @@ interface Serializable
        # Create an instance of this class from the `deserializer`
        #
        # This constructor is refined by subclasses to correctly build their instances.
-       init from_deserializer(deserializer: Deserializer) do end
+       init from_deserializer(deserializer: Deserializer) is nosuper do end
 end
 
 redef interface Object
index ac9f91d..c80b6dc 100644 (file)
@@ -243,7 +243,9 @@ redef class ModelBuilder
                        end
                end
 
-               var candidate = search_module_in_paths(anode.hot_location, name, lookpaths)
+               var loc = null
+               if anode != null then loc = anode.hot_location
+               var candidate = search_module_in_paths(loc, name, lookpaths)
 
                if candidate == null then
                        if mgroup != null then
@@ -655,6 +657,7 @@ redef class ModelBuilder
                var mmodule = new MModule(model, mgroup, mod_name, nmodule.location)
                nmodule.mmodule = mmodule
                nmodules.add(nmodule)
+               parsed_modules.add mmodule
                self.mmodule2nmodule[mmodule] = nmodule
 
                if parent!= null then
index 8b33f15..a97ede8 100644 (file)
@@ -20,6 +20,7 @@ module model_base
 # The container class of a Nit object-oriented model.
 # A model knows modules, classes and properties and can retrieve them.
 class Model
+       super MEntity
 end
 
 # A named and possibly documented entity in the model.
diff --git a/src/model/model_visitor.nit b/src/model/model_visitor.nit
new file mode 100644 (file)
index 0000000..f6169cf
--- /dev/null
@@ -0,0 +1,141 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Simple visitor framework for Nit models.
+#
+# This module provides the `ModelVisitor` abstract class and
+# refines the classes of the `MEntity` hierarchy to add visiting related methods.
+#
+# A standard approach on complex visitor is to dispatch the `ModelVisitor::visit` on the
+# entities to do specific things.
+#
+# ~~~nitish
+# class FooVisitor
+#   super ModelVisitor
+#   redef fun visit(e) do e.foo_visit(self)
+# end
+#
+# redef class MEntity
+# do
+#   fun foo_vist(v: FooVisitor) do visit_all(v)
+# end
+#
+# redef class MClass
+# do
+#   redef fun foo_visit(v) do
+#      print self
+#      super
+#   end
+# end
+# ~~~
+module model_visitor
+
+import model
+
+# The abstract model visitor template.
+#
+# Specific visitor must implement the `visit` method to perform the work.
+abstract class ModelVisitor
+       # Visit the entity `e`.
+       #
+       # This method setups `current_entity` and call `visit`.
+       # If `e` is null, nothing is done.
+       fun enter_visit(e: nullable MEntity) do
+               if e == null then return
+               var old_entity = current_entity
+               current_entity = e
+               visit(e)
+               current_entity = old_entity
+       end
+
+       # The current visited entity
+       var current_entity: nullable MEntity = null
+
+       # Method to define in specific visitor.
+       #
+       # It should not be called directly but used by `enter_visit`
+       protected fun visit(e: MEntity) is abstract
+
+       # Filter classes and method on the visibility.
+       #
+       # If set, only the classes and method with at least the given
+       # visibility level will be visited.
+       var min_visibility: nullable MVisibility = null is writable
+
+       # Is `visibility` acceptable with regard to `min_visibility`?
+       private fun accept_visitibily(visibility: MVisibility): Bool
+       do
+               var min = min_visibility
+               return min == null or min <= visibility
+       end
+end
+
+redef class MEntity
+       # Call `v.enter_visit` on all nested entities.
+       #
+       # See the specific implementation in the subclasses.
+       fun visit_all(v: ModelVisitor) do end
+end
+
+redef class Model
+       # Visit all the packages of the model.
+       redef fun visit_all(v) do
+               for x in mpackages do v.enter_visit(x)
+       end
+end
+
+redef class MPackage
+       # Visit the root group of the package.
+       redef fun visit_all(v) do
+               v.enter_visit(root)
+       end
+end
+
+redef class MGroup
+       # Visit all the subgroups and modules of the group.
+       redef fun visit_all(v) do
+               for x in in_nesting.direct_smallers do v.enter_visit(x)
+               for x in mmodules do v.enter_visit(x)
+       end
+end
+
+redef class MModule
+       # Visit all the classes and class definitions of the module.
+       #
+       # On class introduction, the `MClass` then the `MClassDef` are visited.
+       # On class refinement, only the `MClassDef` is visited (the `MClass` is visited in an imported module).
+       # On class importation, nothing is visited (the `MClass` and the `MClassDef` are visited in imported modules).
+       redef fun visit_all(v) do
+               for x in mclassdefs do
+                       if not v.accept_visitibily(x.mclass.visibility) then return
+                       if x.is_intro then v.enter_visit(x.mclass)
+                       v.enter_visit(x)
+               end
+       end
+end
+
+redef class MClassDef
+       # Visit all the classes and class definitions of the module.
+       #
+       # On property introduction, the `MProperty` then the `MPropDef` are visited.
+       # On property redefinition, only the `MPropDef` is visited (the `MProperty` is visited in an inherited class).
+       # On property inheritance, nothing is visited (the `MProperty` and the `MPropDef` are visited in inherited classes).
+       redef fun visit_all(v) do
+               for x in mpropdefs do
+                       if not v.accept_visitibily(x.mproperty.visibility) then return
+                       if x.is_intro then v.enter_visit(x.mproperty)
+                       v.enter_visit(x)
+               end
+       end
+end
diff --git a/src/test_model_visitor.nit b/src/test_model_visitor.nit
new file mode 100644 (file)
index 0000000..be2899b
--- /dev/null
@@ -0,0 +1,65 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Example of model_visitor
+module test_model_visitor
+
+import test_phase
+import frontend
+import model_visitor
+import counter
+
+# Example visitor that just count kind of entities.
+class TestModelVisitor
+       super ModelVisitor
+
+       redef fun visit(e) do
+               if not doc_only or e.mdoc != null then
+                       cpt.inc(e.class_name)
+               end
+               e.visit_all(self)
+       end
+
+       # Counter of visited entities (by classnames)
+       var cpt = new Counter[String]
+
+       # Do the visitor only count entities with a documentation?
+       var doc_only = false
+end
+
+# The body of the specific work.
+# The main entry point is provided by `test_phase`,
+# This function is then automatically (unless errors where found).
+redef fun do_work(mainmodule, given_mmodules, modelbuilder)
+do
+       var model = modelbuilder.model
+
+       print "All entities:"
+       var v = new TestModelVisitor
+       v.enter_visit(model)
+       v.cpt.print_elements(10)
+
+       print "\nAll non-private entities:"
+       v = new TestModelVisitor
+       v.min_visibility = protected_visibility
+       v.enter_visit(model)
+       v.cpt.print_elements(10)
+
+       print "\nAll documented non-private entities:"
+       v = new TestModelVisitor
+       v.min_visibility = protected_visibility
+       v.doc_only = true
+       v.enter_visit(model)
+       v.cpt.print_elements(10)
+end
index 92317a4..aa93740 100644 (file)
@@ -44,7 +44,7 @@ end
 redef class Model
 
        # Generates a UML Class diagram from the entities of a `Model`
-       fun tpl_class(ctx: ToolContext, main: MModule): Writable do
+       redef fun tpl_class(ctx, main) do
                var t = new Template
                for i in mclasses do
                        if not ctx.private_gen and i.visibility != public_visibility then continue
index 6e80325..eda98e3 100644 (file)
@@ -42,7 +42,7 @@ end
 
 redef class Model
        # Returns a UML package diagram of `main`
-       fun tpl_module(ctx: ToolContext, main: MModule): Writable do
+       redef fun tpl_module(ctx, main) do
                return main.tpl_module(ctx, main)
        end
 end
index 8a91562..9327c80 100644 (file)
@@ -2,3 +2,5 @@
 base_simple3.nit
 -m test_mixin.nit ../examples/hello_world.nit
 -D text=hello -D num=42 -D flag test_define.nit
+-e 'print "hello world"'
+-n -e 'print line' test_prog/README.md test_prog/test_prog.nit
index d8429ff..cc9df0a 100644 (file)
@@ -4,4 +4,5 @@ test_neo
 test_phase
 test_parser
 test_highlight
+test_model_visitor
 ^nit
index ef83f4d..2fc5a83 100644 (file)
@@ -2,6 +2,8 @@ shoot_logic
 nit_args1
 nit_args3
 nit_args4
+nit_args5
+nit_args6
 nitvm_args1
 nitvm_args3
 nitc_args1
index ef83f4d..2fc5a83 100644 (file)
@@ -2,6 +2,8 @@ shoot_logic
 nit_args1
 nit_args3
 nit_args4
+nit_args5
+nit_args6
 nitvm_args1
 nitvm_args3
 nitc_args1
diff --git a/tests/sav/nit_args5.res b/tests/sav/nit_args5.res
new file mode 100644 (file)
index 0000000..3b18e51
--- /dev/null
@@ -0,0 +1 @@
+hello world
diff --git a/tests/sav/nit_args6.res b/tests/sav/nit_args6.res
new file mode 100644 (file)
index 0000000..bfacdb8
--- /dev/null
@@ -0,0 +1,35 @@
+Test program for model tools.
+
+This program creates a fake model that can be used to test tools like:
+
+* `nitdoc`
+* `nitmetrics`
+* `nitx`
+* or others `modelbuilder`.
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# A test program with a fake model to check model tools.
+module test_prog
+
+import rpg
+import game
+
+class Starter
+       fun start do end
+end
+
+var starter = new Starter
+starter.start
+
index 2c6e10c..4d4a3a0 100644 (file)
@@ -32,5 +32,5 @@ Deserialization Error: Doesn't know how to deserialize class "HashSet", Deserial
 # Src:
 <G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
 # Dst:
-<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
+<G: hs: ; s: ; hm: ; am: >
 
index d3738c4..7681dab 100644 (file)
@@ -70,5 +70,5 @@ null
 {"__kind": "obj", "__id": 0, "__class": "G", "hs": {"__kind": "obj", "__id": 1, "__class": "HashSet", "__items": [-1, 0]}, "s": {"__kind": "obj", "__id": 2, "__class": "ArraySet", "__items": ["one", "two"]}, "hm": {"__kind": "obj", "__id": 3, "__class": "HashMap", "__length": 2, "__keys": ["one", "two"], "__values": [1, 2]}, "am": {"__kind": "obj", "__id": 4, "__class": "ArrayMap", "__length": 2, "__keys": ["three", "four"], "__values": ["3", "4"]}}
 
 # Back in Nit:
-<G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
+<G: hs: ; s: ; hm: ; am: >
 
diff --git a/tests/sav/test_model_visitor.res b/tests/sav/test_model_visitor.res
new file mode 100644 (file)
index 0000000..fd8dbb5
--- /dev/null
@@ -0,0 +1,2 @@
+Usage: [OPTION]... <file.nit>...
+Use --help for help
diff --git a/tests/sav/test_model_visitor_args1.res b/tests/sav/test_model_visitor_args1.res
new file mode 100644 (file)
index 0000000..1b30918
--- /dev/null
@@ -0,0 +1,26 @@
+All entities:
+ list:
+  MMethodDef: 17 (30.35%)
+  MMethod: 15 (26.78%)
+  MClassDef: 7 (12.50%)
+  MClass: 7 (12.50%)
+  MAttributeDef: 3 (5.35%)
+  MAttribute: 3 (5.35%)
+  Model: 1 (1.78%)
+  MGroup: 1 (1.78%)
+  MPackage: 1 (1.78%)
+  MModule: 1 (1.78%)
+
+All non-private entities:
+ list:
+  MMethodDef: 8 (24.24%)
+  MMethod: 7 (21.21%)
+  MClassDef: 7 (21.21%)
+  MClass: 7 (21.21%)
+  MModule: 1 (3.03%)
+  MGroup: 1 (3.03%)
+  MPackage: 1 (3.03%)
+  Model: 1 (3.03%)
+
+All documented non-private entities:
+ list:
diff --git a/tests/test_model_visitor.args b/tests/test_model_visitor.args
new file mode 100644 (file)
index 0000000..5f3aa2c
--- /dev/null
@@ -0,0 +1 @@
+base_simple3.nit