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