qtbindings 4.8.6.0 → 4.8.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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
- enum TypeId {
224
- t_voidp,
225
- t_bool,
226
- t_char,
227
- t_uchar,
228
- t_short,
229
- t_ushort,
230
- t_int,
231
- t_uint,
232
- t_long,
233
- t_ulong,
234
- t_float,
235
- t_double,
236
- t_enum,
237
- t_class,
238
- t_last // number of pre-defined types
239
- };
240
-
241
- // Passed to constructor
242
- /**
243
- * The classes array defines every class for this module
244
- */
245
- Class *classes;
246
- Index numClasses;
247
-
248
- /**
249
- * The methods array defines every method in every class for this module
250
- */
251
- Method *methods;
252
- Index numMethods;
253
-
254
- /**
255
- * methodMaps maps the munged method prototypes
256
- * to the methods entries.
257
- */
258
- MethodMap *methodMaps;
259
- Index numMethodMaps;
260
-
261
- /**
262
- * Array of method names, for Method.name and MethodMap.name
263
- */
264
- const char **methodNames;
265
- Index numMethodNames;
266
-
267
- /**
268
- * List of all types needed by the methods (arguments and return values)
269
- */
270
- Type *types;
271
- Index numTypes;
272
-
273
- /**
274
- * Groups of Indexes (0 separated) used as super class lists.
275
- * For classes with super classes: Class.parents = index into this array.
276
- */
277
- Index *inheritanceList;
278
- /**
279
- * Groups of type IDs (0 separated), describing the types of argument for a method.
280
- * Method.args = index into this array.
281
- */
282
- Index *argumentList;
283
- /**
284
- * Groups of method prototypes with the same number of arguments, but different types.
285
- * Used to resolve overloading.
286
- */
287
- Index *ambiguousMethodList;
288
- /**
289
- * Function used for casting from/to the classes defined by this module.
290
- */
291
- CastFn castFn;
292
-
293
- /**
294
- * Constructor
295
- */
296
- Smoke(const char *_moduleName,
297
- Class *_classes, Index _numClasses,
298
- Method *_methods, Index _numMethods,
299
- MethodMap *_methodMaps, Index _numMethodMaps,
300
- const char **_methodNames, Index _numMethodNames,
301
- Type *_types, Index _numTypes,
302
- Index *_inheritanceList,
303
- Index *_argumentList,
304
- Index *_ambiguousMethodList,
305
- CastFn _castFn) :
306
- module_name(_moduleName),
307
- classes(_classes), numClasses(_numClasses),
308
- methods(_methods), numMethods(_numMethods),
309
- methodMaps(_methodMaps), numMethodMaps(_numMethodMaps),
310
- methodNames(_methodNames), numMethodNames(_numMethodNames),
311
- types(_types), numTypes(_numTypes),
312
- inheritanceList(_inheritanceList),
313
- argumentList(_argumentList),
314
- ambiguousMethodList(_ambiguousMethodList),
315
- castFn(_castFn)
316
- {
317
- for (Index i = 1; i <= numClasses; ++i) {
318
- if (!classes[i].external) {
319
- classMap[className(i)] = ModuleIndex(this, i);
320
- }
321
- }
322
- }
323
-
324
- /**
325
- * Returns the name of the module (e.g. "qt" or "kde")
326
- */
327
- inline const char *moduleName() {
328
- return module_name;
329
- }
330
-
331
- inline void *cast(void *ptr, const ModuleIndex& from, const ModuleIndex& to) {
332
- if (castFn == 0) {
333
- return ptr;
334
- }
335
-
336
- if (from.smoke == to.smoke) {
337
- return (*castFn)(ptr, from.index, to.index);
338
- }
339
-
340
- const Smoke::Class &klass = to.smoke->classes[to.index];
341
- return (*castFn)(ptr, from.index, idClass(klass.className, true).index);
342
- }
343
-
344
- inline void *cast(void *ptr, Index from, Index to) {
345
- if(!castFn) return ptr;
346
- return (*castFn)(ptr, from, to);
347
- }
348
-
349
- // return classname directly
350
- inline const char *className(Index classId) {
351
- return classes[classId].className;
352
- }
353
-
354
- inline int leg(Index a, Index b) { // ala Perl's <=>
355
- if(a == b) return 0;
356
- return (a > b) ? 1 : -1;
357
- }
358
-
359
- inline Index idType(const char *t) {
360
- Index imax = numTypes;
361
- Index imin = 1;
362
- Index icur = -1;
363
- int icmp = -1;
364
-
365
- while (imax >= imin) {
366
- icur = (imin + imax) / 2;
367
- icmp = strcmp(types[icur].name, t);
368
- if (icmp == 0) {
369
- return icur;
370
- }
371
-
372
- if (icmp > 0) {
373
- imax = icur - 1;
374
- } else {
375
- imin = icur + 1;
376
- }
377
- }
378
-
379
- return 0;
380
- }
381
-
382
- inline ModuleIndex idClass(const char *c, bool external = false) {
383
- Index imax = numClasses;
384
- Index imin = 1;
385
- Index icur = -1;
386
- int icmp = -1;
387
-
388
- while (imax >= imin) {
389
- icur = (imin + imax) / 2;
390
- icmp = strcmp(classes[icur].className, c);
391
- if (icmp == 0) {
392
- if (classes[icur].external && !external) {
393
- return NullModuleIndex;
394
- } else {
395
- return ModuleIndex(this, icur);
396
- }
397
- }
398
-
399
- if (icmp > 0) {
400
- imax = icur - 1;
401
- } else {
402
- imin = icur + 1;
403
- }
404
- }
405
-
406
- return NullModuleIndex;
407
- }
408
-
409
- static inline ModuleIndex findClass(const char *c) {
410
- ClassMap::iterator i = classMap.find(c);
411
- if (i == classMap.end()) {
412
- return NullModuleIndex;
413
- } else {
414
- return i->second;
415
- }
416
- }
417
-
418
- inline ModuleIndex idMethodName(const char *m) {
419
- Index imax = numMethodNames;
420
- Index imin = 1;
421
- Index icur = -1;
422
- int icmp = -1;
423
-
424
- while (imax >= imin) {
425
- icur = (imin + imax) / 2;
426
- icmp = strcmp(methodNames[icur], m);
427
- if (icmp == 0) {
428
- return ModuleIndex(this, icur);
429
- }
430
-
431
- if (icmp > 0) {
432
- imax = icur - 1;
433
- } else {
434
- imin = icur + 1;
435
- }
436
- }
437
-
438
- return NullModuleIndex;
439
- }
440
-
441
- inline ModuleIndex findMethodName(const char *c, const char *m) {
442
- ModuleIndex mni = idMethodName(m);
443
- if (mni.index) return mni;
444
-
445
- ModuleIndex cmi = findClass(c);
446
- if (cmi.smoke && cmi.smoke != this) {
447
- return cmi.smoke->findMethodName(c, m);
448
- } else if (cmi.smoke == this) {
449
- if (!classes[cmi.index].parents) return NullModuleIndex;
450
- for (Index p = classes[cmi.index].parents; inheritanceList[p]; p++) {
451
- Index ci = inheritanceList[p];
452
- const char* cName = className(ci);
453
- ModuleIndex mi = classMap[cName].smoke->findMethodName(cName, m);
454
- if (mi.index) return mi;
455
- }
456
- }
457
- return NullModuleIndex;
458
- }
459
-
460
- inline ModuleIndex idMethod(Index c, Index name) {
461
- Index imax = numMethodMaps;
462
- Index imin = 1;
463
- Index icur = -1;
464
- int icmp = -1;
465
-
466
- while (imax >= imin) {
467
- icur = (imin + imax) / 2;
468
- icmp = leg(methodMaps[icur].classId, c);
469
- if (icmp == 0) {
470
- icmp = leg(methodMaps[icur].name, name);
471
- if (icmp == 0) {
472
- return ModuleIndex(this, icur);
473
- }
474
- }
475
-
476
- if (icmp > 0) {
477
- imax = icur - 1;
478
- } else {
479
- imin = icur + 1;
480
- }
481
- }
482
-
483
- return NullModuleIndex;
484
- }
485
-
486
- inline ModuleIndex findMethod(ModuleIndex c, ModuleIndex name) {
487
- if (!c.index || !name.index) {
488
- return NullModuleIndex;
489
- } else if (name.smoke == this && c.smoke == this) {
490
- ModuleIndex mi = idMethod(c.index, name.index);
491
- if (mi.index) return mi;
492
- } else if (c.smoke != this) {
493
- return c.smoke->findMethod(c, name);
494
- }
495
-
496
- for (Index *i = inheritanceList + classes[c.index].parents; *i; ++i) {
497
- const char *cName = className(*i);
498
- ModuleIndex ci = findClass(cName);
499
- if (!ci.smoke)
500
- return NullModuleIndex;
501
- ModuleIndex ni = ci.smoke->findMethodName(cName, name.smoke->methodNames[name.index]);
502
- ModuleIndex mi = ci.smoke->findMethod(ci, ni);
503
- if (mi.index) return mi;
504
- }
505
- return NullModuleIndex;
506
- }
507
-
508
- inline ModuleIndex findMethod(const char *c, const char *name) {
509
- ModuleIndex idc = idClass(c);
510
- if (!idc.smoke) idc = findClass(c);
511
- if (!idc.smoke || !idc.index) return NullModuleIndex;
512
- ModuleIndex idname = idc.smoke->findMethodName(c, name);
513
- return idc.smoke->findMethod(idc, idname);
514
- }
515
-
516
- static inline bool isDerivedFrom(const ModuleIndex& classId, const ModuleIndex& baseClassId) {
517
- return isDerivedFrom(classId.smoke, classId.index, baseClassId.smoke, baseClassId.index);
518
- }
519
-
520
- static inline bool isDerivedFrom(Smoke *smoke, Index classId, Smoke *baseSmoke, Index baseId) {
521
- if (!classId || !baseId || !smoke || !baseSmoke)
522
- return false;
523
- if (smoke == baseSmoke && classId == baseId)
524
- return true;
525
-
526
- for(Index p = smoke->classes[classId].parents; smoke->inheritanceList[p]; p++) {
527
- Class& cur = smoke->classes[smoke->inheritanceList[p]];
528
- if (cur.external) {
529
- ModuleIndex mi = findClass(cur.className);
530
- if (isDerivedFrom(mi.smoke, mi.index, baseSmoke, baseId))
531
- return true;
532
- }
533
- if (isDerivedFrom(smoke, smoke->inheritanceList[p], baseSmoke, baseId))
534
- return true;
535
- }
536
- return false;
537
- }
538
-
539
- static inline bool isDerivedFrom(const char *className, const char *baseClassName) {
540
- ModuleIndex classId = findClass(className);
541
- ModuleIndex baseId = findClass(baseClassName);
542
- return isDerivedFrom(classId.smoke, classId.index, baseId.smoke, baseId.index);
543
- }
544
- };
545
-
546
- class SmokeBinding {
547
- protected:
548
- Smoke *smoke;
549
- public:
550
- SmokeBinding(Smoke *s) : smoke(s) {}
551
- virtual void deleted(Smoke::Index classId, void *obj) = 0;
552
- virtual bool callMethod(Smoke::Index method, void *obj, Smoke::Stack args, bool isAbstract = false) = 0;
553
- virtual char* className(Smoke::Index classId) = 0;
554
- virtual ~SmokeBinding() {}
555
- };
556
-
557
- #endif
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