Merge: remove some unwanted files
authorJean Privat <jean@pryen.org>
Wed, 21 Oct 2015 21:52:26 +0000 (17:52 -0400)
committerJean Privat <jean@pryen.org>
Wed, 21 Oct 2015 21:52:26 +0000 (17:52 -0400)
Pull-Request: #1779
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Romain Chanoir <romain.chanoir@viacesi.fr>

19 files changed:
lib/core/bytes.nit
lib/core/text/flat.nit
lib/niti_runtime.nit
lib/serialization/serialization.nit
src/doc/doc_phases/doc_html.nit
src/doc/doc_phases/doc_phases.nit
src/doc/doc_phases/doc_test.nit [new file with mode: 0644]
src/loader.nit
src/nitdoc.nit
tests/nit.args
tests/nitdoc.args
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_test_phase_args2.res [new file with mode: 0644]
tests/test_test_phase.args

index 227759a..94d3d27 100644 (file)
@@ -289,6 +289,20 @@ redef class Text
                end
                return ret
        end
+
+       # Gets the hexdigest of the bytes of `self`
+       #
+       #     assert "&lt;STRING&#47;&rt;".hexdigest == "266C743B535452494E47262334373B2672743B"
+       fun hexdigest: String do
+               var ln = bytelen
+               var outns = new NativeString(ln * 2)
+               var oi = 0
+               for i in [0 .. ln[ do
+                       bytes[i].add_digest_at(outns, oi)
+                       oi += 2
+               end
+               return new FlatString.with_infos(outns, ln * 2, 0, ln * 2 - 1)
+       end
 end
 
 redef class FlatText
index 6cf1584..c89b222 100644 (file)
@@ -85,6 +85,104 @@ redef class FlatText
                return ns_i
        end
 
+       # By escaping `self` to HTML, how many more bytes will be needed ?
+       fun chars_to_html_escape: Int do
+               var its = _items
+               var max = last_byte
+               var pos = first_byte
+               var endlen = 0
+               while pos <= max do
+                       var c = its[pos]
+                       if c == 0x3Cu8 then
+                               endlen += 3
+                       else if c == 0x3Eu8 then
+                               endlen += 3
+                       else if c == 0x26u8 then
+                               endlen += 4
+                       else if c == 0x22u8 then
+                               endlen += 4
+                       else if c == 0x27u8 then
+                               endlen += 4
+                       else if c == 0x2Fu8 then
+                               endlen += 4
+                       end
+                       pos += 1
+               end
+               return endlen
+       end
+
+       redef fun html_escape
+       do
+               var extra = chars_to_html_escape
+               if extra == 0 then return to_s
+               var its = _items
+               var max = last_byte
+               var pos = first_byte
+               var nlen = extra + _bytelen
+               var nits = new NativeString(nlen)
+               var outpos = 0
+               while pos <= max do
+                       var c = its[pos]
+                       # Special codes:
+                       # Some HTML characters are used as meta-data, they need
+                       # to be replaced by an HTML-Escaped equivalent
+                       #
+                       # * 0x3C (<) => &lt;
+                       # * 0x3E (>) => &gt;
+                       # * 0x26 (&) => &amp;
+                       # * 0x22 (") => &#34;
+                       # * 0x27 (') => &#39;
+                       # * 0x2F (/) => &#47;
+                       if c == 0x3Cu8 then
+                               nits[outpos] = 0x26u8
+                               nits[outpos + 1] = 0x6Cu8
+                               nits[outpos + 2] = 0x74u8
+                               nits[outpos + 3] = 0x3Bu8
+                               outpos += 4
+                       else if c == 0x3Eu8 then
+                               nits[outpos] = 0x26u8
+                               nits[outpos + 1] = 0x67u8
+                               nits[outpos + 2] = 0x74u8
+                               nits[outpos + 3] = 0x3Bu8
+                               outpos += 4
+                       else if c == 0x26u8 then
+                               nits[outpos] = 0x26u8
+                               nits[outpos + 1] = 0x61u8
+                               nits[outpos + 2] = 0x6Du8
+                               nits[outpos + 3] = 0x70u8
+                               nits[outpos + 4] = 0x3Bu8
+                               outpos += 5
+                       else if c == 0x22u8 then
+                               nits[outpos] = 0x26u8
+                               nits[outpos + 1] = 0x23u8
+                               nits[outpos + 2] = 0x33u8
+                               nits[outpos + 3] = 0x34u8
+                               nits[outpos + 4] = 0x3Bu8
+                               outpos += 5
+                       else if c == 0x27u8 then
+                               nits[outpos] = 0x26u8
+                               nits[outpos + 1] = 0x23u8
+                               nits[outpos + 2] = 0x33u8
+                               nits[outpos + 3] = 0x39u8
+                               nits[outpos + 4] = 0x3Bu8
+                               outpos += 5
+                       else if c == 0x2Fu8 then
+                               nits[outpos] = 0x26u8
+                               nits[outpos + 1] = 0x23u8
+                               nits[outpos + 2] = 0x34u8
+                               nits[outpos + 3] = 0x37u8
+                               nits[outpos + 4] = 0x3Bu8
+                               outpos += 5
+                       else
+                               nits[outpos] = c
+                               outpos += 1
+                       end
+                       pos += 1
+               end
+               var s = new FlatString.with_infos(nits, nlen, 0, nlen - 1)
+               return s
+       end
+
        # By escaping `self` to C, how many more bytes will be needed ?
        #
        # This enables a double-optimization in `escape_to_c` since if this
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 ebc1193..30a15c2 100644 (file)
@@ -70,6 +70,9 @@ redef class ToolContext
        # FIXME redo the plugin
        var opt_github_gitdir = new OptionString("Git working directory used to resolve path name (ex: /home/me/mypackage/)", "--github-gitdir")
 
+       # Do not produce HTML files
+       var opt_no_render = new OptionBool("do not render HTML files", "--no-render")
+
        redef init do
                super
 
@@ -77,7 +80,8 @@ redef class ToolContext
                        opt_source, opt_sharedir, opt_shareurl, opt_custom_title,
                        opt_custom_footer, opt_custom_intro, opt_custom_brand,
                        opt_github_upstream, opt_github_base_sha1, opt_github_gitdir,
-                       opt_piwik_tracker, opt_piwik_site_id)
+                       opt_piwik_tracker, opt_piwik_site_id,
+                       opt_no_render)
        end
 
        redef fun process_options(args) do
@@ -103,6 +107,7 @@ class RenderHTMLPhase
        var name_sorter = new MEntityNameSorter
 
        redef fun apply do
+               if ctx.opt_no_render.value then return
                init_output_dir
                for page in doc.pages.values do
                        page.render(self, doc).write_to_file("{ctx.output_dir.to_s}/{page.html_url}")
index fefd1ac..24969e4 100644 (file)
@@ -19,3 +19,4 @@ module doc_phases
 
 import doc_html
 import doc_indexing
+import doc_test
diff --git a/src/doc/doc_phases/doc_test.nit b/src/doc/doc_phases/doc_test.nit
new file mode 100644 (file)
index 0000000..ddb5eb7
--- /dev/null
@@ -0,0 +1,59 @@
+# 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.
+
+# Print the generated DocModel in stdout.
+#
+# Mainly used for tests.
+module doc_test
+
+import doc_structure
+import counter
+
+redef class ToolContext
+
+       # File pattern used to link documentation to source code.
+       var opt_test = new OptionBool("print test data", "--test")
+
+       redef init do
+               super
+               option_context.add_option(opt_test)
+       end
+end
+
+# Display the DocModel in stdout.
+class DocTestPhase
+       super DocPhase
+
+       redef fun apply do
+               if not ctx.opt_test.value then return
+               # Pages metrics
+               var page_counter = new Counter[String]
+               var pages = doc.pages.keys.to_a
+               default_comparator.sort(pages)
+               for title in pages do
+                       var page = doc.pages[title]
+                       page_counter.inc page.class_name
+                       print page.pretty_print.write_to_string
+               end
+               print "Generated {doc.pages.length} pages"
+               page_counter.print_elements(100)
+               # Model metrics
+               var model_counter = new Counter[String]
+               for mentity in doc.mentities do
+                       model_counter.inc mentity.class_name
+               end
+               print "Found {doc.mentities.length} mentities"
+               model_counter.print_elements(100)
+       end
+end
index aa88cdc..57238f2 100644 (file)
@@ -152,6 +152,11 @@ redef class ModelBuilder
 
                        var mmodule = identify_module(a)
                        if mmodule == null then
+                               if a.file_exists then
+                                       toolcontext.error(null, "Error: `{a}` is not a Nit source file.")
+                               else
+                                       toolcontext.error(null, "Error: cannot find module `{a}`.")
+                               end
                                continue
                        end
 
@@ -238,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
@@ -650,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 bda79e7..2591863 100644 (file)
@@ -19,19 +19,12 @@ module nitdoc
 
 import modelbuilder
 import doc
-import counter
 
 redef class ToolContext
        # Nitdoc generation phase.
        var docphase: Phase = new Nitdoc(self, null)
 
-       # File pattern used to link documentation to source code.
-       var opt_test = new OptionBool("do not render anything, only print test data", "--test")
-
-       redef init do
-               super
-               option_context.add_option(opt_test)
-       end
+       init do super # to fix ambiguous linearization
 end
 
 # Nitdoc phase explores the model and generate pages for each mentities found
@@ -52,37 +45,14 @@ private class Nitdoc
                        new IntroRedefListPhase(toolcontext, doc),
                        new LinListPhase(toolcontext, doc),
                        new GraphPhase(toolcontext, doc),
-                       new ReadmePhase(toolcontext, doc): DocPhase]
-
-               if not toolcontext.opt_test.value then
-                       phases.add new RenderHTMLPhase(toolcontext, doc)
-               end
+                       new ReadmePhase(toolcontext, doc),
+                       new RenderHTMLPhase(toolcontext, doc),
+                       new DocTestPhase(toolcontext, doc): DocPhase]
 
                for phase in phases do
                        toolcontext.info("# {phase.class_name}", 1)
                        phase.apply
                end
-
-               if toolcontext.opt_test.value then
-                       # Pages metrics
-                       var page_counter = new Counter[String]
-                       var pages = doc.pages.keys.to_a
-                       default_comparator.sort(pages)
-                       for title in pages do
-                               var page = doc.pages[title]
-                               page_counter.inc page.class_name
-                               print page.pretty_print.write_to_string
-                       end
-                       print "Generated {doc.pages.length} pages"
-                       page_counter.print_elements(100)
-                       # Model metrics
-                       var model_counter = new Counter[String]
-                       for mentity in doc.mentities do
-                               model_counter.inc mentity.class_name
-                       end
-                       print "Found {doc.mentities.length} mentities"
-                       model_counter.print_elements(100)
-               end
        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 de4c3e4..ee5fd03 100644 (file)
@@ -1,4 +1,4 @@
 module_1.nit -d $WRITE
 base_attr_nullable.nit -d $WRITE
 --private base_attr_nullable.nit -d $WRITE
---test test_prog -d $WRITE
+--no-render --test test_prog -d $WRITE
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_test_phase_args2.res b/tests/sav/test_test_phase_args2.res
new file mode 100644 (file)
index 0000000..729ac10
--- /dev/null
@@ -0,0 +1,3 @@
+Error: cannot find module `fail.nit`.
+Error: `README.md` is not a Nit source file.
+Errors: 2. Warnings: 0.
index 5f3aa2c..7409ad5 100644 (file)
@@ -1 +1,2 @@
 base_simple3.nit
+fail.nit base_simple3.nit README.md