lib: update the json module to latest FFI spec
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 9 Nov 2013 02:15:18 +0000 (21:15 -0500)
committerJean Privat <jean@pryen.org>
Mon, 17 Feb 2014 18:56:35 +0000 (13:56 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/json/json_reader.nit
lib/json/json_writer.nit

index f412c87..a87f526 100644 (file)
@@ -18,10 +18,10 @@ intrude import jsonable
 redef class String
        # Deserializes this String and return its value as a Map[String, nullable Jsonable]
        # On error, null is returned.
-       fun json_to_object : nullable Map[String, nullable Jsonable] import NativeString::to_s, JsonObject::json_to_map `{
+       fun json_to_object : nullable Map[String, nullable Jsonable] import NativeString.to_s, JsonObject.json_to_map `{
                char *native_recv;
                json_object *jobj;
-               nullable_Map map;
+               nullable_Map_of_String_nullable_Jsonable map;
 
                native_recv = String_to_cstring( recv );
                jobj = json_tokener_parse( native_recv );
@@ -34,13 +34,13 @@ end
 
 redef extern JsonObject
        # Get this json object as a Map
-       private fun json_to_map : nullable Map[String, nullable Jsonable] import NativeString::to_s, String::to_cstring, HashMap, HashMap::[]=, json_cross, HashMap[String,nullable Jsonable] as( nullable Map[String,nullable Jsonable] ), String as ( Object ), nullable Jsonable as (nullable Object) `{
-               HashMap map;
+       private fun json_to_map : nullable Map[String, nullable Jsonable] import NativeString.to_s, String.to_cstring, HashMap[String,nullable Jsonable], HashMap[String,nullable Jsonable].[]=, json_cross `{
+               HashMap_of_String_nullable_Jsonable map;
                String nit_key;
                nullable_Jsonable nit_val;
                enum json_type type;
 
-               map = new_HashMap();
+               map = new_HashMap_of_String_nullable_Jsonable();
 
                { /* prevents "mixed declaration and code" warning for C90 */
                json_object_object_foreach( recv, key, val ) {
@@ -51,11 +51,11 @@ redef extern JsonObject
 
                        nit_val = JsonObject_json_cross( val, type );
 
-                       HashMap__index_assign( map, String_as_Object( nit_key ), nullable_Jsonable_as_nullable_Object( nit_val ) );
+                       HashMap_of_String_nullable_Jsonable__index_assign( map, String_as_Object( nit_key ), nullable_Jsonable_as_nullable_Object( nit_val ) );
                }
                }
 
-               return HashMap_as_nullable_Map( map );
+               return HashMap_of_String_nullable_Jsonable_as_nullable_Map_of_String_nullable_Jsonable( map );
        `}
 
        # Get this json object as a Bool
@@ -74,31 +74,31 @@ redef extern JsonObject
        `}
 
        # Get this json object as a Sequence
-       private fun json_to_sequence : Sequence[Jsonable] import Array, Array::push, Array[nullable Jsonable] as ( Sequence[nullable Jsonable] ), json_cross `{
+       private fun json_to_sequence : Sequence[nullable Jsonable] import Array[nullable Jsonable], Array[nullable Jsonable].push, json_cross, Array[nullable Jsonable].as(Sequence[nullable Jsonable]) `{
                array_list* jlist;
                json_object* jobj;
                nullable_Jsonable obj;
-               Array dest;
+               Array_of_nullable_Jsonable dest;
                int i;
                int len;
                enum json_type type;
 
                jlist = json_object_get_array( recv );
                len = json_object_array_length( recv );
-               dest = new_Array();
+               dest = new_Array_of_nullable_Jsonable();
                for ( i = 0; i < len; i ++ ) {
                        jobj = json_object_array_get_idx( recv, i );
                        if ( jobj == NULL ) type = json_type_null;
                        else type = json_object_get_type( jobj );
                        obj = JsonObject_json_cross( jobj, type );
-                       Array_push( dest, nullable_Jsonable_as_nullable_Object( obj ) );
+                       Array_of_nullable_Jsonable_push( dest, obj );
                }
 
-               return Array_as_Sequence( dest );
+               return Array_of_nullable_Jsonable_as_Sequence_of_nullable_Jsonable( dest );
        `}
 
        # Get this json object as a String
-       private fun json_to_string : String import NativeString::to_s `{
+       private fun json_to_string : String import NativeString.to_s `{
                const char *cstring;
                cstring = json_object_get_string( recv );
                return NativeString_to_s( (char*)cstring );
index 5e5cef2..58343f8 100644 (file)
@@ -93,7 +93,7 @@ redef class Sequence[ E ]
 end
 
 redef class String
-       redef fun to_json_object import NativeString::to_s `{
+       redef fun to_json_object import NativeString.to_s `{
                char *native_recv = String_to_cstring( recv );
                return json_object_new_string( native_recv );
        `}
@@ -121,7 +121,7 @@ redef class JsonObject
        new `{ return json_object_new_object(); `}
 
        # Add a key and value to the object
-       fun add( key : String, val : nullable JsonObject ) import String::to_cstring, nullable JsonObject as not nullable `{
+       fun add( key : String, val : nullable JsonObject ) import String.to_cstring, nullable JsonObject as not nullable `{
                char* native_key;
 
                native_key = String_to_cstring( key );