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