src/ffi: add some missing doc and clean up
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 8 May 2015 14:23:36 +0000 (10:23 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 11 May 2015 15:19:32 +0000 (11:19 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

src/compiler/compiler_ffi/compiler_ffi.nit
src/compiler/compiler_ffi/light.nit
src/ffi/ffi_base.nit
src/ffi/light_ffi_base.nit

index 9b0dc27..8b8f9de 100644 (file)
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# FFI support for the compilers
+# Full FFI support for the compiler
 module compiler_ffi
 
 intrude import light
index c7e3b0e..dbe819a 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# FFI support for the compilers
+# Light FFI support for the compiler
 module light
 
 intrude import abstract_compiler
 intrude import ffi::light_ffi
 
 redef class MModule
+       # `CCompilationUnit` used for nitni signatures and code specific to the compiler
        var nitni_ccu: nullable CCompilationUnit = null
 
        private fun nmodule(v: AbstractCompilerVisitor): nullable AModule
@@ -82,7 +83,6 @@ redef class AMethPropdef
        private fun compile_ffi_support_to_c(v: AbstractCompilerVisitor)
        do
                var mmodule = mpropdef.mclassdef.mmodule
-               var mainmodule = v.compiler.mainmodule
                var amodule = v.compiler.modelbuilder.mmodule2node(mmodule)
                var mclass_type = mpropdef.mclassdef.bound_mtype
 
@@ -220,6 +220,7 @@ redef class AMethPropdef
 end
 
 redef class CCompilationUnit
+       # Compile a `_nitni` files, used to implement nitni features for the compiler
        fun write_as_nitni(mmodule: MModule, compdir: String)
        do
                var base_name = "{mmodule.c_name}._nitni"
index 963df27..77a982d 100644 (file)
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Tools and utilities for language targetted FFI implementations
+# Tools and utilities for implement FFI with different languages
 module ffi_base
 
 import c_tools
index e3014a5..6791e5c 100644 (file)
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Tools and utilities for language targetted FFI implementations
+# Tools and utilities for implement FFI with different languages
 module light_ffi_base
 
 import c_tools
@@ -23,9 +23,13 @@ import modelbuilder
 import nitni::nitni_utilities
 
 redef class ToolContext
+       # Phase that assign a `FFILanguage` to all `AExternCodeBlock`
        var ffi_language_assignation_phase: Phase = new FFILanguageAssignationPhase(self, null)
 end
 
+# Phase that assign a `FFILanguage` to all `AExternCodeBlock`
+#
+# It will also report errors when using an unknown foreign langages.
 class FFILanguageAssignationPhase
        super Phase
 
@@ -75,27 +79,34 @@ class FFILanguageAssignationPhase
 end
 
 redef class MModule
+       # All FFI files linked to this module
        var ffi_files = new Array[ExternFile]
 end
 
 redef class AExternCodeBlock
+       # User entered name for the language of this block
        fun language_name: nullable String do
                if n_in_language == null then return null
                return n_in_language.n_string.without_quotes
        end
-       fun language_name_lowered: nullable String do
+
+       # `language_name`, in lower case
+       protected fun language_name_lowered: nullable String do
                if language_name == null then return null
                return language_name.to_lower
        end
 
+       # User entered foreign code in the block
        fun code: String do return n_extern_code_segment.without_guard
 
+       # `FFILanguage` assigned to this block
        var language: nullable FFILanguage = null
 end
 
 # Visitor for a specific languages. Works kinda like a `Phase` and is executed
 # by a `Phase`.
 class FFILanguage
+       # `FFILanguageAssignationPhase` assigning `self` to `AExternCodeBlock`s
        var ffi_language_assignation_phase: FFILanguageAssignationPhase
 
        init
@@ -143,6 +154,7 @@ redef class TExternCodeSegment
 end
 
 redef class CCompilationUnit
+       # Compile as `_ffi` files which contains the implementation of extern methods
        fun write_as_impl(mmodule: MModule, compdir: String)
        do
                var base_name = "{mmodule.c_name}._ffi"
@@ -157,6 +169,7 @@ redef class CCompilationUnit
                files.add( "{compdir}/{c_file}" )
        end
 
+       # Write the header part to `file` including all `includes` using the `guard`
        fun write_header_to_file(mmodule: MModule, file: String, includes: Array[String], guard: String)
        do
                var stream = new FileWriter.open( file )
@@ -178,6 +191,7 @@ redef class CCompilationUnit
                stream.close
        end
 
+       # Write the body part to `file` including all `includes`
        fun write_body_to_file(mmodule: MModule, file: String, includes: Array[String])
        do
                var stream = new FileWriter.open(file)
@@ -193,6 +207,8 @@ redef class CCompilationUnit
        end
 end
 
+# Foreign equivalent types of extern classes
 class ForeignType
+       # C type of `self`, by default it is `void*`
        fun ctype: String do return "void*"
 end