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