qtbindings 4.8.6.0 → 4.8.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/ruby/qtruby/src/handlers.cpp +2668 -2642
- data/ext/ruby/qtruby/src/marshall_primitives.h +19 -3
- data/ext/smoke/qtgui/smokeconfig.xml +0 -0
- data/ext/smoke/smoke.h +559 -557
- data/extconf.rb +2 -2
- data/lib/Qt/qtruby4.rb +16 -0
- data/lib/qtbindings_version.rb +2 -2
- metadata +3 -3
- data/README.txt +0 -148
@@ -234,7 +234,7 @@ unsigned char* ruby_to_primitive<unsigned char *>(VALUE rv)
|
|
234
234
|
{
|
235
235
|
if(rv == Qnil)
|
236
236
|
return 0;
|
237
|
-
|
237
|
+
|
238
238
|
return (unsigned char*)StringValuePtr(rv);
|
239
239
|
}
|
240
240
|
|
@@ -244,7 +244,7 @@ VALUE primitive_to_ruby<int*>(int* sv)
|
|
244
244
|
if(!sv) {
|
245
245
|
return Qnil;
|
246
246
|
}
|
247
|
-
|
247
|
+
|
248
248
|
return primitive_to_ruby<int>(*sv);
|
249
249
|
}
|
250
250
|
|
@@ -256,9 +256,13 @@ WId ruby_to_primitive<WId>(VALUE v)
|
|
256
256
|
return 0;
|
257
257
|
#ifdef Q_WS_MAC32
|
258
258
|
return (WId) NUM2INT(v);
|
259
|
+
#else
|
260
|
+
#if __x86_64__
|
261
|
+
return (WId) NUM2LL(v);
|
259
262
|
#else
|
260
263
|
return (WId) NUM2LONG(v);
|
261
264
|
#endif
|
265
|
+
#endif
|
262
266
|
}
|
263
267
|
|
264
268
|
template <>
|
@@ -266,9 +270,13 @@ VALUE primitive_to_ruby<WId>(WId sv)
|
|
266
270
|
{
|
267
271
|
#ifdef Q_WS_MAC32
|
268
272
|
return INT2NUM((unsigned long) sv);
|
273
|
+
#else
|
274
|
+
#if __x86_64__
|
275
|
+
return LL2NUM((unsigned long long) sv);
|
269
276
|
#else
|
270
277
|
return LONG2NUM((unsigned long) sv);
|
271
278
|
#endif
|
279
|
+
#endif
|
272
280
|
}
|
273
281
|
|
274
282
|
template <>
|
@@ -276,14 +284,22 @@ Q_PID ruby_to_primitive<Q_PID>(VALUE v)
|
|
276
284
|
{
|
277
285
|
if(v == Qnil)
|
278
286
|
return 0;
|
279
|
-
|
287
|
+
|
288
|
+
#if __x86_64__
|
289
|
+
return (Q_PID) NUM2ULL(v);
|
290
|
+
#else
|
280
291
|
return (Q_PID) NUM2ULONG(v);
|
292
|
+
#endif
|
281
293
|
}
|
282
294
|
|
283
295
|
template <>
|
284
296
|
VALUE primitive_to_ruby<Q_PID>(Q_PID sv)
|
285
297
|
{
|
298
|
+
#if __x86_64__
|
299
|
+
return ULL2NUM((unsigned long long) sv);
|
300
|
+
#else
|
286
301
|
return ULONG2NUM((unsigned long) sv);
|
302
|
+
#endif
|
287
303
|
}
|
288
304
|
#endif
|
289
305
|
|
File without changes
|
data/ext/smoke/smoke.h
CHANGED
@@ -1,557 +1,559 @@
|
|
1
|
-
#ifndef SMOKE_H
|
2
|
-
#define SMOKE_H
|
3
|
-
|
4
|
-
#include <cstddef>
|
5
|
-
#include <cstring>
|
6
|
-
#include <string>
|
7
|
-
#include <map>
|
8
|
-
|
9
|
-
/*
|
10
|
-
Copyright (C) 2002, Ashley Winters <qaqortog@nwlink.com>
|
11
|
-
Copyright (C) 2007, Arno Rehn <arno@arnorehn.de>
|
12
|
-
|
13
|
-
BSD License
|
14
|
-
|
15
|
-
Redistribution and use in source and binary forms, with or
|
16
|
-
without modification, are permitted provided that the following
|
17
|
-
conditions are met:
|
18
|
-
|
19
|
-
Redistributions of source code must retain the above
|
20
|
-
copyright notice, this list of conditions and the following disclaimer.
|
21
|
-
|
22
|
-
Redistributions in binary form must reproduce the above
|
23
|
-
copyright notice, this list of conditions and the following
|
24
|
-
disclaimer in the documentation and/or other materials
|
25
|
-
provided with the distribution.>
|
26
|
-
|
27
|
-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
|
28
|
-
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
29
|
-
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
30
|
-
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
|
31
|
-
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
32
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
33
|
-
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
34
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
35
|
-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
36
|
-
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
37
|
-
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
38
|
-
THE POSSIBILITY OF SUCH DAMAGE.
|
39
|
-
*/
|
40
|
-
|
41
|
-
#ifdef WIN32
|
42
|
-
// Define this when building a smoke lib that doesn't have any parents - else Smoke::classMap is not exported.
|
43
|
-
#ifdef BASE_SMOKE_BUILDING
|
44
|
-
#define BASE_SMOKE_EXPORT __declspec(dllexport)
|
45
|
-
#else
|
46
|
-
#define BASE_SMOKE_EXPORT __declspec(dllimport)
|
47
|
-
#endif
|
48
|
-
// Define this when building a smoke lib.
|
49
|
-
#ifdef SMOKE_BUILDING
|
50
|
-
#define SMOKE_EXPORT __declspec(dllexport)
|
51
|
-
#else
|
52
|
-
#define SMOKE_EXPORT __declspec(dllimport)
|
53
|
-
#endif
|
54
|
-
#define SMOKE_IMPORT __declspec(dllimport)
|
55
|
-
#else
|
56
|
-
#ifdef GCC_VISIBILITY
|
57
|
-
#define SMOKE_EXPORT __attribute__ ((visibility("default")))
|
58
|
-
#define BASE_SMOKE_EXPORT __attribute__ ((visibility("default")))
|
59
|
-
#else
|
60
|
-
#define SMOKE_EXPORT
|
61
|
-
#define BASE_SMOKE_EXPORT
|
62
|
-
#endif
|
63
|
-
#define SMOKE_IMPORT
|
64
|
-
#endif
|
65
|
-
|
66
|
-
class SmokeBinding;
|
67
|
-
|
68
|
-
class BASE_SMOKE_EXPORT Smoke {
|
69
|
-
private:
|
70
|
-
const char *module_name;
|
71
|
-
|
72
|
-
public:
|
73
|
-
union StackItem; // defined below
|
74
|
-
/**
|
75
|
-
* A stack is an array of arguments, passed to a method when calling it.
|
76
|
-
*/
|
77
|
-
typedef StackItem* Stack;
|
78
|
-
|
79
|
-
enum EnumOperation {
|
80
|
-
EnumNew,
|
81
|
-
EnumDelete,
|
82
|
-
EnumFromLong,
|
83
|
-
EnumToLong
|
84
|
-
};
|
85
|
-
|
86
|
-
typedef short Index;
|
87
|
-
typedef void (*ClassFn)(Index method, void* obj, Stack args);
|
88
|
-
typedef void* (*CastFn)(void* obj, Index from, Index to);
|
89
|
-
typedef void (*EnumFn)(EnumOperation, Index, void*&, long&);
|
90
|
-
|
91
|
-
/**
|
92
|
-
* Describe one index in a given module.
|
93
|
-
*/
|
94
|
-
struct ModuleIndex {
|
95
|
-
Smoke* smoke;
|
96
|
-
Index index;
|
97
|
-
ModuleIndex() : smoke(0), index(0) {}
|
98
|
-
ModuleIndex(Smoke * s, Index i) : smoke(s), index(i) {}
|
99
|
-
|
100
|
-
inline bool operator==(const Smoke::ModuleIndex& other) const {
|
101
|
-
return index == other.index && smoke == other.smoke;
|
102
|
-
}
|
103
|
-
|
104
|
-
inline bool operator!=(const Smoke::ModuleIndex& other) const {
|
105
|
-
return index != other.index || smoke != other.smoke;
|
106
|
-
}
|
107
|
-
};
|
108
|
-
/**
|
109
|
-
* A ModuleIndex with both fields set to 0.
|
110
|
-
*/
|
111
|
-
static ModuleIndex NullModuleIndex;
|
112
|
-
|
113
|
-
typedef std::map<std::string, ModuleIndex> ClassMap;
|
114
|
-
static ClassMap classMap;
|
115
|
-
|
116
|
-
enum ClassFlags {
|
117
|
-
cf_constructor = 0x01, // has a constructor
|
118
|
-
cf_deepcopy = 0x02, // has copy constructor
|
119
|
-
cf_virtual = 0x04, // has virtual destructor
|
120
|
-
cf_namespace = 0x08, // is a namespace
|
121
|
-
cf_undefined = 0x10 // defined elsewhere
|
122
|
-
};
|
123
|
-
/**
|
124
|
-
* Describe one class.
|
125
|
-
*/
|
126
|
-
struct Class {
|
127
|
-
const char *className; // Name of the class
|
128
|
-
bool external; // Whether the class is in another module
|
129
|
-
Index parents; // Index into inheritanceList
|
130
|
-
ClassFn classFn; // Calls any method in the class
|
131
|
-
EnumFn enumFn; // Handles enum pointers
|
132
|
-
unsigned short flags; // ClassFlags
|
133
|
-
unsigned int size;
|
134
|
-
};
|
135
|
-
|
136
|
-
enum MethodFlags {
|
137
|
-
mf_static = 0x01,
|
138
|
-
mf_const = 0x02,
|
139
|
-
mf_copyctor = 0x04, // Copy constructor
|
140
|
-
mf_internal = 0x08, // For internal use only
|
141
|
-
mf_enum = 0x10, // An enum value
|
142
|
-
mf_ctor = 0x20,
|
143
|
-
mf_dtor = 0x40,
|
144
|
-
mf_protected = 0x80,
|
145
|
-
mf_attribute = 0x100, // accessor method for a field
|
146
|
-
mf_property = 0x200, // accessor method of a property
|
147
|
-
mf_virtual = 0x400,
|
148
|
-
mf_purevirtual = 0x800,
|
149
|
-
mf_signal = 0x1000, // method is a signal
|
150
|
-
mf_slot = 0x2000, // method is a slot
|
151
|
-
mf_explicit = 0x4000 // method is an 'explicit' constructor
|
152
|
-
};
|
153
|
-
/**
|
154
|
-
* Describe one method of one class.
|
155
|
-
*/
|
156
|
-
struct Method {
|
157
|
-
Index classId; // Index into classes
|
158
|
-
Index name; // Index into methodNames; real name
|
159
|
-
Index args; // Index into argumentList
|
160
|
-
unsigned char numArgs; // Number of arguments
|
161
|
-
unsigned short flags; // MethodFlags (const/static/etc...)
|
162
|
-
Index ret; // Index into types for the return type
|
163
|
-
Index method; // Passed to Class.classFn, to call method
|
164
|
-
};
|
165
|
-
|
166
|
-
/**
|
167
|
-
* One MethodMap entry maps the munged method prototype
|
168
|
-
* to the Method entry.
|
169
|
-
*
|
170
|
-
* The munging works this way:
|
171
|
-
* $ is a plain scalar
|
172
|
-
* # is an object
|
173
|
-
* ? is a non-scalar (reference to array or hash, undef)
|
174
|
-
*
|
175
|
-
* e.g. QApplication(int &, char **) becomes QApplication$?
|
176
|
-
*/
|
177
|
-
struct MethodMap {
|
178
|
-
Index classId; // Index into classes
|
179
|
-
Index name; // Index into methodNames; munged name
|
180
|
-
Index method; // Index into methods
|
181
|
-
};
|
182
|
-
|
183
|
-
enum TypeFlags {
|
184
|
-
// The first 4 bits indicate the TypeId value, i.e. which field
|
185
|
-
// of the StackItem union is used.
|
186
|
-
tf_elem = 0x0F,
|
187
|
-
|
188
|
-
// Always only one of the next three flags should be set
|
189
|
-
tf_stack = 0x10, // Stored on the stack, 'type'
|
190
|
-
tf_ptr = 0x20, // Pointer, 'type*'
|
191
|
-
tf_ref = 0x30, // Reference, 'type&'
|
192
|
-
// Can | whatever ones of these apply
|
193
|
-
tf_const = 0x40 // const argument
|
194
|
-
};
|
195
|
-
/**
|
196
|
-
* One Type entry is one argument type needed by a method.
|
197
|
-
* Type entries are shared, there is only one entry for "int" etc.
|
198
|
-
*/
|
199
|
-
struct Type {
|
200
|
-
const char *name; // Stringified type name
|
201
|
-
Index classId; // Index into classes. -1 for none
|
202
|
-
unsigned short flags; // TypeFlags
|
203
|
-
};
|
204
|
-
|
205
|
-
// We could just pass everything around using void* (pass-by-reference)
|
206
|
-
// I don't want to, though. -aw
|
207
|
-
union StackItem {
|
208
|
-
void* s_voidp;
|
209
|
-
bool s_bool;
|
210
|
-
signed char s_char;
|
211
|
-
unsigned char s_uchar;
|
212
|
-
short s_short;
|
213
|
-
unsigned short s_ushort;
|
214
|
-
int s_int;
|
215
|
-
unsigned int s_uint;
|
216
|
-
long s_long;
|
217
|
-
unsigned long s_ulong;
|
218
|
-
float s_float;
|
219
|
-
double s_double;
|
220
|
-
long s_enum;
|
221
|
-
void* s_class;
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
Index
|
303
|
-
|
304
|
-
Index *
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
Index
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
}
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
Index
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
return
|
396
|
-
}
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
}
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
return
|
415
|
-
}
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
Index
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
Index
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
}
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
}
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
if (
|
524
|
-
return
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
virtual
|
554
|
-
virtual
|
555
|
-
|
556
|
-
|
557
|
-
|
1
|
+
#ifndef SMOKE_H
|
2
|
+
#define SMOKE_H
|
3
|
+
|
4
|
+
#include <cstddef>
|
5
|
+
#include <cstring>
|
6
|
+
#include <string>
|
7
|
+
#include <map>
|
8
|
+
|
9
|
+
/*
|
10
|
+
Copyright (C) 2002, Ashley Winters <qaqortog@nwlink.com>
|
11
|
+
Copyright (C) 2007, Arno Rehn <arno@arnorehn.de>
|
12
|
+
|
13
|
+
BSD License
|
14
|
+
|
15
|
+
Redistribution and use in source and binary forms, with or
|
16
|
+
without modification, are permitted provided that the following
|
17
|
+
conditions are met:
|
18
|
+
|
19
|
+
Redistributions of source code must retain the above
|
20
|
+
copyright notice, this list of conditions and the following disclaimer.
|
21
|
+
|
22
|
+
Redistributions in binary form must reproduce the above
|
23
|
+
copyright notice, this list of conditions and the following
|
24
|
+
disclaimer in the documentation and/or other materials
|
25
|
+
provided with the distribution.>
|
26
|
+
|
27
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
|
28
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
29
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
30
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
|
31
|
+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
32
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
33
|
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
34
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
35
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
36
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
37
|
+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
38
|
+
THE POSSIBILITY OF SUCH DAMAGE.
|
39
|
+
*/
|
40
|
+
|
41
|
+
#ifdef WIN32
|
42
|
+
// Define this when building a smoke lib that doesn't have any parents - else Smoke::classMap is not exported.
|
43
|
+
#ifdef BASE_SMOKE_BUILDING
|
44
|
+
#define BASE_SMOKE_EXPORT __declspec(dllexport)
|
45
|
+
#else
|
46
|
+
#define BASE_SMOKE_EXPORT __declspec(dllimport)
|
47
|
+
#endif
|
48
|
+
// Define this when building a smoke lib.
|
49
|
+
#ifdef SMOKE_BUILDING
|
50
|
+
#define SMOKE_EXPORT __declspec(dllexport)
|
51
|
+
#else
|
52
|
+
#define SMOKE_EXPORT __declspec(dllimport)
|
53
|
+
#endif
|
54
|
+
#define SMOKE_IMPORT __declspec(dllimport)
|
55
|
+
#else
|
56
|
+
#ifdef GCC_VISIBILITY
|
57
|
+
#define SMOKE_EXPORT __attribute__ ((visibility("default")))
|
58
|
+
#define BASE_SMOKE_EXPORT __attribute__ ((visibility("default")))
|
59
|
+
#else
|
60
|
+
#define SMOKE_EXPORT
|
61
|
+
#define BASE_SMOKE_EXPORT
|
62
|
+
#endif
|
63
|
+
#define SMOKE_IMPORT
|
64
|
+
#endif
|
65
|
+
|
66
|
+
class SmokeBinding;
|
67
|
+
|
68
|
+
class BASE_SMOKE_EXPORT Smoke {
|
69
|
+
private:
|
70
|
+
const char *module_name;
|
71
|
+
|
72
|
+
public:
|
73
|
+
union StackItem; // defined below
|
74
|
+
/**
|
75
|
+
* A stack is an array of arguments, passed to a method when calling it.
|
76
|
+
*/
|
77
|
+
typedef StackItem* Stack;
|
78
|
+
|
79
|
+
enum EnumOperation {
|
80
|
+
EnumNew,
|
81
|
+
EnumDelete,
|
82
|
+
EnumFromLong,
|
83
|
+
EnumToLong
|
84
|
+
};
|
85
|
+
|
86
|
+
typedef short Index;
|
87
|
+
typedef void (*ClassFn)(Index method, void* obj, Stack args);
|
88
|
+
typedef void* (*CastFn)(void* obj, Index from, Index to);
|
89
|
+
typedef void (*EnumFn)(EnumOperation, Index, void*&, long&);
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Describe one index in a given module.
|
93
|
+
*/
|
94
|
+
struct ModuleIndex {
|
95
|
+
Smoke* smoke;
|
96
|
+
Index index;
|
97
|
+
ModuleIndex() : smoke(0), index(0) {}
|
98
|
+
ModuleIndex(Smoke * s, Index i) : smoke(s), index(i) {}
|
99
|
+
|
100
|
+
inline bool operator==(const Smoke::ModuleIndex& other) const {
|
101
|
+
return index == other.index && smoke == other.smoke;
|
102
|
+
}
|
103
|
+
|
104
|
+
inline bool operator!=(const Smoke::ModuleIndex& other) const {
|
105
|
+
return index != other.index || smoke != other.smoke;
|
106
|
+
}
|
107
|
+
};
|
108
|
+
/**
|
109
|
+
* A ModuleIndex with both fields set to 0.
|
110
|
+
*/
|
111
|
+
static ModuleIndex NullModuleIndex;
|
112
|
+
|
113
|
+
typedef std::map<std::string, ModuleIndex> ClassMap;
|
114
|
+
static ClassMap classMap;
|
115
|
+
|
116
|
+
enum ClassFlags {
|
117
|
+
cf_constructor = 0x01, // has a constructor
|
118
|
+
cf_deepcopy = 0x02, // has copy constructor
|
119
|
+
cf_virtual = 0x04, // has virtual destructor
|
120
|
+
cf_namespace = 0x08, // is a namespace
|
121
|
+
cf_undefined = 0x10 // defined elsewhere
|
122
|
+
};
|
123
|
+
/**
|
124
|
+
* Describe one class.
|
125
|
+
*/
|
126
|
+
struct Class {
|
127
|
+
const char *className; // Name of the class
|
128
|
+
bool external; // Whether the class is in another module
|
129
|
+
Index parents; // Index into inheritanceList
|
130
|
+
ClassFn classFn; // Calls any method in the class
|
131
|
+
EnumFn enumFn; // Handles enum pointers
|
132
|
+
unsigned short flags; // ClassFlags
|
133
|
+
unsigned int size;
|
134
|
+
};
|
135
|
+
|
136
|
+
enum MethodFlags {
|
137
|
+
mf_static = 0x01,
|
138
|
+
mf_const = 0x02,
|
139
|
+
mf_copyctor = 0x04, // Copy constructor
|
140
|
+
mf_internal = 0x08, // For internal use only
|
141
|
+
mf_enum = 0x10, // An enum value
|
142
|
+
mf_ctor = 0x20,
|
143
|
+
mf_dtor = 0x40,
|
144
|
+
mf_protected = 0x80,
|
145
|
+
mf_attribute = 0x100, // accessor method for a field
|
146
|
+
mf_property = 0x200, // accessor method of a property
|
147
|
+
mf_virtual = 0x400,
|
148
|
+
mf_purevirtual = 0x800,
|
149
|
+
mf_signal = 0x1000, // method is a signal
|
150
|
+
mf_slot = 0x2000, // method is a slot
|
151
|
+
mf_explicit = 0x4000 // method is an 'explicit' constructor
|
152
|
+
};
|
153
|
+
/**
|
154
|
+
* Describe one method of one class.
|
155
|
+
*/
|
156
|
+
struct Method {
|
157
|
+
Index classId; // Index into classes
|
158
|
+
Index name; // Index into methodNames; real name
|
159
|
+
Index args; // Index into argumentList
|
160
|
+
unsigned char numArgs; // Number of arguments
|
161
|
+
unsigned short flags; // MethodFlags (const/static/etc...)
|
162
|
+
Index ret; // Index into types for the return type
|
163
|
+
Index method; // Passed to Class.classFn, to call method
|
164
|
+
};
|
165
|
+
|
166
|
+
/**
|
167
|
+
* One MethodMap entry maps the munged method prototype
|
168
|
+
* to the Method entry.
|
169
|
+
*
|
170
|
+
* The munging works this way:
|
171
|
+
* $ is a plain scalar
|
172
|
+
* # is an object
|
173
|
+
* ? is a non-scalar (reference to array or hash, undef)
|
174
|
+
*
|
175
|
+
* e.g. QApplication(int &, char **) becomes QApplication$?
|
176
|
+
*/
|
177
|
+
struct MethodMap {
|
178
|
+
Index classId; // Index into classes
|
179
|
+
Index name; // Index into methodNames; munged name
|
180
|
+
Index method; // Index into methods
|
181
|
+
};
|
182
|
+
|
183
|
+
enum TypeFlags {
|
184
|
+
// The first 4 bits indicate the TypeId value, i.e. which field
|
185
|
+
// of the StackItem union is used.
|
186
|
+
tf_elem = 0x0F,
|
187
|
+
|
188
|
+
// Always only one of the next three flags should be set
|
189
|
+
tf_stack = 0x10, // Stored on the stack, 'type'
|
190
|
+
tf_ptr = 0x20, // Pointer, 'type*'
|
191
|
+
tf_ref = 0x30, // Reference, 'type&'
|
192
|
+
// Can | whatever ones of these apply
|
193
|
+
tf_const = 0x40 // const argument
|
194
|
+
};
|
195
|
+
/**
|
196
|
+
* One Type entry is one argument type needed by a method.
|
197
|
+
* Type entries are shared, there is only one entry for "int" etc.
|
198
|
+
*/
|
199
|
+
struct Type {
|
200
|
+
const char *name; // Stringified type name
|
201
|
+
Index classId; // Index into classes. -1 for none
|
202
|
+
unsigned short flags; // TypeFlags
|
203
|
+
};
|
204
|
+
|
205
|
+
// We could just pass everything around using void* (pass-by-reference)
|
206
|
+
// I don't want to, though. -aw
|
207
|
+
union StackItem {
|
208
|
+
void* s_voidp;
|
209
|
+
bool s_bool;
|
210
|
+
signed char s_char;
|
211
|
+
unsigned char s_uchar;
|
212
|
+
short s_short;
|
213
|
+
unsigned short s_ushort;
|
214
|
+
int s_int;
|
215
|
+
unsigned int s_uint;
|
216
|
+
long s_long;
|
217
|
+
unsigned long s_ulong;
|
218
|
+
float s_float;
|
219
|
+
double s_double;
|
220
|
+
long s_enum;
|
221
|
+
void* s_class;
|
222
|
+
size_t s_size_t;
|
223
|
+
};
|
224
|
+
enum TypeId {
|
225
|
+
t_voidp,
|
226
|
+
t_bool,
|
227
|
+
t_char,
|
228
|
+
t_uchar,
|
229
|
+
t_short,
|
230
|
+
t_ushort,
|
231
|
+
t_int,
|
232
|
+
t_uint,
|
233
|
+
t_long,
|
234
|
+
t_ulong,
|
235
|
+
t_float,
|
236
|
+
t_double,
|
237
|
+
t_enum,
|
238
|
+
t_class,
|
239
|
+
t_size_t,
|
240
|
+
t_last // number of pre-defined types
|
241
|
+
};
|
242
|
+
|
243
|
+
// Passed to constructor
|
244
|
+
/**
|
245
|
+
* The classes array defines every class for this module
|
246
|
+
*/
|
247
|
+
Class *classes;
|
248
|
+
Index numClasses;
|
249
|
+
|
250
|
+
/**
|
251
|
+
* The methods array defines every method in every class for this module
|
252
|
+
*/
|
253
|
+
Method *methods;
|
254
|
+
Index numMethods;
|
255
|
+
|
256
|
+
/**
|
257
|
+
* methodMaps maps the munged method prototypes
|
258
|
+
* to the methods entries.
|
259
|
+
*/
|
260
|
+
MethodMap *methodMaps;
|
261
|
+
Index numMethodMaps;
|
262
|
+
|
263
|
+
/**
|
264
|
+
* Array of method names, for Method.name and MethodMap.name
|
265
|
+
*/
|
266
|
+
const char **methodNames;
|
267
|
+
Index numMethodNames;
|
268
|
+
|
269
|
+
/**
|
270
|
+
* List of all types needed by the methods (arguments and return values)
|
271
|
+
*/
|
272
|
+
Type *types;
|
273
|
+
Index numTypes;
|
274
|
+
|
275
|
+
/**
|
276
|
+
* Groups of Indexes (0 separated) used as super class lists.
|
277
|
+
* For classes with super classes: Class.parents = index into this array.
|
278
|
+
*/
|
279
|
+
Index *inheritanceList;
|
280
|
+
/**
|
281
|
+
* Groups of type IDs (0 separated), describing the types of argument for a method.
|
282
|
+
* Method.args = index into this array.
|
283
|
+
*/
|
284
|
+
Index *argumentList;
|
285
|
+
/**
|
286
|
+
* Groups of method prototypes with the same number of arguments, but different types.
|
287
|
+
* Used to resolve overloading.
|
288
|
+
*/
|
289
|
+
Index *ambiguousMethodList;
|
290
|
+
/**
|
291
|
+
* Function used for casting from/to the classes defined by this module.
|
292
|
+
*/
|
293
|
+
CastFn castFn;
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Constructor
|
297
|
+
*/
|
298
|
+
Smoke(const char *_moduleName,
|
299
|
+
Class *_classes, Index _numClasses,
|
300
|
+
Method *_methods, Index _numMethods,
|
301
|
+
MethodMap *_methodMaps, Index _numMethodMaps,
|
302
|
+
const char **_methodNames, Index _numMethodNames,
|
303
|
+
Type *_types, Index _numTypes,
|
304
|
+
Index *_inheritanceList,
|
305
|
+
Index *_argumentList,
|
306
|
+
Index *_ambiguousMethodList,
|
307
|
+
CastFn _castFn) :
|
308
|
+
module_name(_moduleName),
|
309
|
+
classes(_classes), numClasses(_numClasses),
|
310
|
+
methods(_methods), numMethods(_numMethods),
|
311
|
+
methodMaps(_methodMaps), numMethodMaps(_numMethodMaps),
|
312
|
+
methodNames(_methodNames), numMethodNames(_numMethodNames),
|
313
|
+
types(_types), numTypes(_numTypes),
|
314
|
+
inheritanceList(_inheritanceList),
|
315
|
+
argumentList(_argumentList),
|
316
|
+
ambiguousMethodList(_ambiguousMethodList),
|
317
|
+
castFn(_castFn)
|
318
|
+
{
|
319
|
+
for (Index i = 1; i <= numClasses; ++i) {
|
320
|
+
if (!classes[i].external) {
|
321
|
+
classMap[className(i)] = ModuleIndex(this, i);
|
322
|
+
}
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
/**
|
327
|
+
* Returns the name of the module (e.g. "qt" or "kde")
|
328
|
+
*/
|
329
|
+
inline const char *moduleName() {
|
330
|
+
return module_name;
|
331
|
+
}
|
332
|
+
|
333
|
+
inline void *cast(void *ptr, const ModuleIndex& from, const ModuleIndex& to) {
|
334
|
+
if (castFn == 0) {
|
335
|
+
return ptr;
|
336
|
+
}
|
337
|
+
|
338
|
+
if (from.smoke == to.smoke) {
|
339
|
+
return (*castFn)(ptr, from.index, to.index);
|
340
|
+
}
|
341
|
+
|
342
|
+
const Smoke::Class &klass = to.smoke->classes[to.index];
|
343
|
+
return (*castFn)(ptr, from.index, idClass(klass.className, true).index);
|
344
|
+
}
|
345
|
+
|
346
|
+
inline void *cast(void *ptr, Index from, Index to) {
|
347
|
+
if(!castFn) return ptr;
|
348
|
+
return (*castFn)(ptr, from, to);
|
349
|
+
}
|
350
|
+
|
351
|
+
// return classname directly
|
352
|
+
inline const char *className(Index classId) {
|
353
|
+
return classes[classId].className;
|
354
|
+
}
|
355
|
+
|
356
|
+
inline int leg(Index a, Index b) { // ala Perl's <=>
|
357
|
+
if(a == b) return 0;
|
358
|
+
return (a > b) ? 1 : -1;
|
359
|
+
}
|
360
|
+
|
361
|
+
inline Index idType(const char *t) {
|
362
|
+
Index imax = numTypes;
|
363
|
+
Index imin = 1;
|
364
|
+
Index icur = -1;
|
365
|
+
int icmp = -1;
|
366
|
+
|
367
|
+
while (imax >= imin) {
|
368
|
+
icur = (imin + imax) / 2;
|
369
|
+
icmp = strcmp(types[icur].name, t);
|
370
|
+
if (icmp == 0) {
|
371
|
+
return icur;
|
372
|
+
}
|
373
|
+
|
374
|
+
if (icmp > 0) {
|
375
|
+
imax = icur - 1;
|
376
|
+
} else {
|
377
|
+
imin = icur + 1;
|
378
|
+
}
|
379
|
+
}
|
380
|
+
|
381
|
+
return 0;
|
382
|
+
}
|
383
|
+
|
384
|
+
inline ModuleIndex idClass(const char *c, bool external = false) {
|
385
|
+
Index imax = numClasses;
|
386
|
+
Index imin = 1;
|
387
|
+
Index icur = -1;
|
388
|
+
int icmp = -1;
|
389
|
+
|
390
|
+
while (imax >= imin) {
|
391
|
+
icur = (imin + imax) / 2;
|
392
|
+
icmp = strcmp(classes[icur].className, c);
|
393
|
+
if (icmp == 0) {
|
394
|
+
if (classes[icur].external && !external) {
|
395
|
+
return NullModuleIndex;
|
396
|
+
} else {
|
397
|
+
return ModuleIndex(this, icur);
|
398
|
+
}
|
399
|
+
}
|
400
|
+
|
401
|
+
if (icmp > 0) {
|
402
|
+
imax = icur - 1;
|
403
|
+
} else {
|
404
|
+
imin = icur + 1;
|
405
|
+
}
|
406
|
+
}
|
407
|
+
|
408
|
+
return NullModuleIndex;
|
409
|
+
}
|
410
|
+
|
411
|
+
static inline ModuleIndex findClass(const char *c) {
|
412
|
+
ClassMap::iterator i = classMap.find(c);
|
413
|
+
if (i == classMap.end()) {
|
414
|
+
return NullModuleIndex;
|
415
|
+
} else {
|
416
|
+
return i->second;
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
420
|
+
inline ModuleIndex idMethodName(const char *m) {
|
421
|
+
Index imax = numMethodNames;
|
422
|
+
Index imin = 1;
|
423
|
+
Index icur = -1;
|
424
|
+
int icmp = -1;
|
425
|
+
|
426
|
+
while (imax >= imin) {
|
427
|
+
icur = (imin + imax) / 2;
|
428
|
+
icmp = strcmp(methodNames[icur], m);
|
429
|
+
if (icmp == 0) {
|
430
|
+
return ModuleIndex(this, icur);
|
431
|
+
}
|
432
|
+
|
433
|
+
if (icmp > 0) {
|
434
|
+
imax = icur - 1;
|
435
|
+
} else {
|
436
|
+
imin = icur + 1;
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
return NullModuleIndex;
|
441
|
+
}
|
442
|
+
|
443
|
+
inline ModuleIndex findMethodName(const char *c, const char *m) {
|
444
|
+
ModuleIndex mni = idMethodName(m);
|
445
|
+
if (mni.index) return mni;
|
446
|
+
|
447
|
+
ModuleIndex cmi = findClass(c);
|
448
|
+
if (cmi.smoke && cmi.smoke != this) {
|
449
|
+
return cmi.smoke->findMethodName(c, m);
|
450
|
+
} else if (cmi.smoke == this) {
|
451
|
+
if (!classes[cmi.index].parents) return NullModuleIndex;
|
452
|
+
for (Index p = classes[cmi.index].parents; inheritanceList[p]; p++) {
|
453
|
+
Index ci = inheritanceList[p];
|
454
|
+
const char* cName = className(ci);
|
455
|
+
ModuleIndex mi = classMap[cName].smoke->findMethodName(cName, m);
|
456
|
+
if (mi.index) return mi;
|
457
|
+
}
|
458
|
+
}
|
459
|
+
return NullModuleIndex;
|
460
|
+
}
|
461
|
+
|
462
|
+
inline ModuleIndex idMethod(Index c, Index name) {
|
463
|
+
Index imax = numMethodMaps;
|
464
|
+
Index imin = 1;
|
465
|
+
Index icur = -1;
|
466
|
+
int icmp = -1;
|
467
|
+
|
468
|
+
while (imax >= imin) {
|
469
|
+
icur = (imin + imax) / 2;
|
470
|
+
icmp = leg(methodMaps[icur].classId, c);
|
471
|
+
if (icmp == 0) {
|
472
|
+
icmp = leg(methodMaps[icur].name, name);
|
473
|
+
if (icmp == 0) {
|
474
|
+
return ModuleIndex(this, icur);
|
475
|
+
}
|
476
|
+
}
|
477
|
+
|
478
|
+
if (icmp > 0) {
|
479
|
+
imax = icur - 1;
|
480
|
+
} else {
|
481
|
+
imin = icur + 1;
|
482
|
+
}
|
483
|
+
}
|
484
|
+
|
485
|
+
return NullModuleIndex;
|
486
|
+
}
|
487
|
+
|
488
|
+
inline ModuleIndex findMethod(ModuleIndex c, ModuleIndex name) {
|
489
|
+
if (!c.index || !name.index) {
|
490
|
+
return NullModuleIndex;
|
491
|
+
} else if (name.smoke == this && c.smoke == this) {
|
492
|
+
ModuleIndex mi = idMethod(c.index, name.index);
|
493
|
+
if (mi.index) return mi;
|
494
|
+
} else if (c.smoke != this) {
|
495
|
+
return c.smoke->findMethod(c, name);
|
496
|
+
}
|
497
|
+
|
498
|
+
for (Index *i = inheritanceList + classes[c.index].parents; *i; ++i) {
|
499
|
+
const char *cName = className(*i);
|
500
|
+
ModuleIndex ci = findClass(cName);
|
501
|
+
if (!ci.smoke)
|
502
|
+
return NullModuleIndex;
|
503
|
+
ModuleIndex ni = ci.smoke->findMethodName(cName, name.smoke->methodNames[name.index]);
|
504
|
+
ModuleIndex mi = ci.smoke->findMethod(ci, ni);
|
505
|
+
if (mi.index) return mi;
|
506
|
+
}
|
507
|
+
return NullModuleIndex;
|
508
|
+
}
|
509
|
+
|
510
|
+
inline ModuleIndex findMethod(const char *c, const char *name) {
|
511
|
+
ModuleIndex idc = idClass(c);
|
512
|
+
if (!idc.smoke) idc = findClass(c);
|
513
|
+
if (!idc.smoke || !idc.index) return NullModuleIndex;
|
514
|
+
ModuleIndex idname = idc.smoke->findMethodName(c, name);
|
515
|
+
return idc.smoke->findMethod(idc, idname);
|
516
|
+
}
|
517
|
+
|
518
|
+
static inline bool isDerivedFrom(const ModuleIndex& classId, const ModuleIndex& baseClassId) {
|
519
|
+
return isDerivedFrom(classId.smoke, classId.index, baseClassId.smoke, baseClassId.index);
|
520
|
+
}
|
521
|
+
|
522
|
+
static inline bool isDerivedFrom(Smoke *smoke, Index classId, Smoke *baseSmoke, Index baseId) {
|
523
|
+
if (!classId || !baseId || !smoke || !baseSmoke)
|
524
|
+
return false;
|
525
|
+
if (smoke == baseSmoke && classId == baseId)
|
526
|
+
return true;
|
527
|
+
|
528
|
+
for(Index p = smoke->classes[classId].parents; smoke->inheritanceList[p]; p++) {
|
529
|
+
Class& cur = smoke->classes[smoke->inheritanceList[p]];
|
530
|
+
if (cur.external) {
|
531
|
+
ModuleIndex mi = findClass(cur.className);
|
532
|
+
if (isDerivedFrom(mi.smoke, mi.index, baseSmoke, baseId))
|
533
|
+
return true;
|
534
|
+
}
|
535
|
+
if (isDerivedFrom(smoke, smoke->inheritanceList[p], baseSmoke, baseId))
|
536
|
+
return true;
|
537
|
+
}
|
538
|
+
return false;
|
539
|
+
}
|
540
|
+
|
541
|
+
static inline bool isDerivedFrom(const char *className, const char *baseClassName) {
|
542
|
+
ModuleIndex classId = findClass(className);
|
543
|
+
ModuleIndex baseId = findClass(baseClassName);
|
544
|
+
return isDerivedFrom(classId.smoke, classId.index, baseId.smoke, baseId.index);
|
545
|
+
}
|
546
|
+
};
|
547
|
+
|
548
|
+
class SmokeBinding {
|
549
|
+
protected:
|
550
|
+
Smoke *smoke;
|
551
|
+
public:
|
552
|
+
SmokeBinding(Smoke *s) : smoke(s) {}
|
553
|
+
virtual void deleted(Smoke::Index classId, void *obj) = 0;
|
554
|
+
virtual bool callMethod(Smoke::Index method, void *obj, Smoke::Stack args, bool isAbstract = false) = 0;
|
555
|
+
virtual char* className(Smoke::Index classId) = 0;
|
556
|
+
virtual ~SmokeBinding() {}
|
557
|
+
};
|
558
|
+
|
559
|
+
#endif
|