Sync API with GLib GDir head
[gnome.introspection-doc-generator] / JSDOC / Introspect / Basic.js
1 //<script type="text/javascript">
2 //Gtk = imports.gi.Gtk;
3 GI      = imports.gi.GIRepository;
4 GLib    = imports.gi.GLib;
5 xml     = imports.libxml;
6 //GObject = imports.gi.GObject;
7 imports['Object.js'].load(Object);
8
9 console     = imports['console.js'].console;
10 Introspect = imports['JSDOC/Introspect.js'].Introspect;
11
12
13
14 /**
15  * Base class for Properties, functions, methods etc.
16  */
17
18
19 Basic = Object.define(
20     function( ) {
21          // never called?
22     },
23     Object,
24     {
25         
26         typeToName : function (type_info) {
27             var ty = GI.type_tag_to_string( GI.type_info_get_tag(type_info));
28             
29             if ((ty == 'void') && GI.type_info_is_pointer(type_info)) {
30                 return 'void*'; // it's a fake string?!?!!? - slightly naughty...
31             }
32             if (ty == 'array') {
33                 // array of what!?!?
34                 var param_type = GI.type_info_get_param_type (type_info, 0);
35                 var atype = GI.type_info_get_tag(param_type);
36                 if (atype == GI.ITypeTag.UINT8) {
37                     return 'utf8';
38                 }
39                 
40                             
41                 return ty;
42             }
43             if (ty != 'interface') {
44                 return ty;
45             }
46             var interface_info = GI.type_info_get_interface (type_info);        
47             var interface_type = GI.base_info_get_type (interface_info);
48             if (interface_type  == GI.IInfoType.CALLBACK) {
49                 // callback.. 
50                 var Callback = Introspect.Callback ;
51                 var ret=  new Callback(interface_info, this, false, false);
52                 ret.alias = GI.base_info_get_namespace(interface_info) + '.' + GI.base_info_get_name(interface_info);
53                 return ret;
54                  
55                 
56             }
57
58             return  GI.base_info_get_namespace(interface_info) + '.' + GI.base_info_get_name(interface_info);
59             
60         },
61         
62         directions : [ "in", "out"," inout"],
63         
64         argsToArrays : function(m,  returnArray) 
65         {
66             
67             var outIntoReturn = false;
68             if (returnArray && returnArray.length == 1 && returnArray[0].type == 'void') {
69                 outIntoReturn = true;
70             }
71             
72             var outArg = {
73                 name : 'out_values',
74                 ns : '',
75                 type : 'Object',
76                 direction : 'out',
77                 be_null :  true, // in theory..
78                 desc : "Return Object, use an empty Object, and the properties will get set as follows",
79                 properties : []
80             };
81             
82             var args = [];
83             var firstOut = -1;
84             for(var a_i  =0; a_i   < GI.callable_info_get_n_args(m); a_i++) {
85                 var arg = GI.callable_info_get_arg(m, a_i);
86                 
87                 var direction = this.directions[GI.arg_info_get_direction(arg)];
88                 
89                 var add = {
90                     name : GI.base_info_get_name(arg),
91                     ns : GI.base_info_get_namespace(arg),
92                     type : this.typeToName(GI.arg_info_get_type(arg)),
93                     direction : direction,
94                     be_null :  GI.arg_info_may_be_null(arg) || GI.arg_info_is_optional(arg),
95                     desc : GI.base_info_get_attribute(arg, 'doc') || ''
96                 };
97                 
98                 
99                 add.alias = add.ns + '.' + add.name;
100                 
101                 if (direction == 'out') {
102                     firstOut = firstOut  > -1 ? firstOut : a_i;
103                     if (outIntoReturn) {
104                         returnArray.push(add);
105                     } else {
106                         outArg.properties.push(add);
107                     }
108                 }
109                 
110                 
111                 args.push(add);
112             }
113             
114             // drop all the 'out args from the end of args..
115             if (returnArray) {
116                     
117                 while (true) {
118                     if (!args.length) {
119                         break;
120                     }
121                     var l = args.pop(); // drop!
122                     if (l.direction == 'out') {
123                         // got an out arg..
124                         continue;
125                     }
126                     args.push(l); // put it back in (it's not a out).
127                     break;
128                     
129                 }
130             }
131             if (outArg.properties.length) {
132                 // put the out arg in there...
133                 if (firstOut >= args.length) {
134                     args.push(outArg);
135                 } else {
136                     args[firstOut]  = outArg;
137                 }
138             }
139             
140              
141             // remove void return....
142             
143             if (returnArray && returnArray.length > 1 && returnArray[0].type == 'void') {
144                 returnArray.shift();
145             }
146             
147             return args;
148         }
149 });