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