contrib/objcwrapper: add type knowledge checks to ObjcModel
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 26 Aug 2015 19:02:09 +0000 (15:02 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 27 Aug 2015 19:26:48 +0000 (15:26 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/objcwrapper/src/objc_generator.nit
contrib/objcwrapper/src/objc_model.nit

index fb9e4ab..9dd29f0 100644 (file)
@@ -67,6 +67,11 @@ redef class Sys
        end
 end
 
+redef class ObjcModel
+       redef fun knows_type(objc_type) do return super or
+               nit_to_java_types.keys.has(objc_type)
+end
+
 # Wrapper generator
 class CodeGenerator
 
index 46589c9..a082d22 100644 (file)
@@ -19,6 +19,33 @@ module objc_model
 class ObjcModel
        # All analyzed classes
        var classes = new Array[ObjcClass]
+
+       # Is `objc_type` known by this model?
+       fun knows_type(objc_type: Text): Bool
+       do
+               for c in classes do
+                       if c.name == objc_type then return true
+               end
+
+               return imported_types.has(objc_type)
+       end
+
+       # Are all types in the signature or `method` known by this model?
+       fun knows_all_types(method: ObjcMethod): Bool
+       do
+               for param in method.params do
+                       if param.is_single then break
+                       if not knows_type(param.return_type) then return false
+               end
+
+               var r = method.return_type
+               return r == "void" or r == "id" or knows_type(r)
+       end
+
+       # Objective-C types available in imported modules
+       #
+       # TODO seach in existing wrappers
+       private var imported_types: Array[String] = ["NSObject", "NSString"]
 end
 
 # Objective-C class