[Kde-bindings] KDE/kdebindings/php/phpqt/src
Thomas Moenicke
tm at php-qt.org
Sun Oct 26 19:40:53 UTC 2008
SVN commit 876212 by moenicke:
* updated the smokeStackFromQtStack implemention, it is now possible to set bounds for the Smoke::Stack
* updated the QtToMoc implemention, the moc stack is now a QList, more types are covered, Smoke* pointer is set to every item
* slot name is now passed as an argument
CCMAIL: kde-bindings at kde.org
M +3 -1 EmitSignal.cpp
M +7 -10 InvokeSlot.cpp
M +4 -3 InvokeSlot.h
M +75 -71 marshall_types.cpp
M +2 -9 marshall_types.h
M +4 -1 phpqt_internals.cpp
M +58 -23 smokephp.cpp
M +4 -1 smokephp.h
--- trunk/KDE/kdebindings/php/phpqt/src/EmitSignal.cpp #876211:876212
@@ -11,7 +11,7 @@
{
_items = items;
_args = mocStack;
- _id = id;
+// _id = id;
_sp = sp;
_result = result;
_stack = new Smoke::StackItem[ items ];
@@ -19,6 +19,8 @@
EmitSignal::~EmitSignal()
{
+ delete[] _stack;
+
}
Marshall::Action
--- trunk/KDE/kdebindings/php/phpqt/src/InvokeSlot.cpp #876211:876212
@@ -19,24 +19,21 @@
zval **sp,
const int slotId,
const QMetaObject* metaObject,
- void** a
+ void** a,
+ const QByteArray& slotName
) : MethodCallBase( smoke, stack, sp ),
_obj(obj),
_id(slotId),
_metaObject(metaObject),
- _a(a)
+ _a(a),
+ _slotName( slotName )
{
_args = _smoke->argumentList + method().args;
- // break at the first '('
- QByteArray signature( _metaObject->method(_id).signature() );
- _slotName.append( signature.left( signature.indexOf("(") ) );
-
QList<QByteArray> qargs = _metaObject->method(_id).parameterTypes();
_items = qargs.count();
- _mocStack = new MocArgument[ _items + 1 ];
- smokephp_QtToMoc(_a + 1, qargs, _mocStack);
- smokeStackFromQtStack(_stack, _a + 1, _items, _mocStack);
+ _mocStack = smokephp_QtToMoc(smoke, _a + 1, qargs);
+ smokeStackFromQtStack(_stack, _a + 1, 1, _items, _mocStack);
}
InvokeSlot::~InvokeSlot()
@@ -90,7 +87,7 @@
SmokeType
InvokeSlot::type()
{
- return _mocStack[_cur].st;
+ return _mocStack[_cur]->st;
}
Smoke::StackItem &
--- trunk/KDE/kdebindings/php/phpqt/src/InvokeSlot.h #876211:876212
@@ -2,6 +2,7 @@
#define INVOKESLOT_H_
#include "MethodCallBase.h"
+#include <QList>
class QByteArray;
class QMetaObject;
@@ -10,7 +11,7 @@
class InvokeSlot : public MethodCallBase
{
public:
- InvokeSlot(Smoke *smoke, const Smoke::Stack stack, const zval* obj, zval **sp, const int slotId, const QMetaObject* metaObject, void** a);
+ InvokeSlot(Smoke *smoke, const Smoke::Stack stack, const zval* obj, zval **sp, const int slotId, const QMetaObject* metaObject, void** a, const QByteArray& slotName);
virtual ~InvokeSlot();
Marshall::Action action();
@@ -31,8 +32,8 @@
QByteArray _slotName;
const QMetaObject* _metaObject;
void** _a;
- MocArgument* _mocStack;
-
+ QList<MocArgument*> _mocStack;
+
const zval* _obj;
};
--- trunk/KDE/kdebindings/php/phpqt/src/marshall_types.cpp #876211:876212
@@ -30,6 +30,8 @@
#include "smokephp.h"
#include "MethodCallBase.h"
+#include <QList>
+
void
smokeStackToQtStack(const Smoke::Stack stack, void ** o, const int items, MocArgument* args)
{
@@ -124,87 +126,89 @@
}
void
-smokeStackFromQtStack(const Smoke::Stack stack, void ** _o, const int items, MocArgument* args)
+smokeStackFromQtStack(const Smoke::Stack stack, void ** _o, const int start, const int end, QList<MocArgument*> args)
{
- for (int i = 0; i < items; i++) {
- void *o = _o[i];
- switch(args[i].argType) {
- case xmoc_bool:
- stack[i].s_bool = *(bool*)o;
+ for (int i = start, j = 0; i < end; i++, j++)
+ {
+ void *o = _o[i];
+ switch(args[j]->argType)
+ {
+ case xmoc_bool:
+ stack[j].s_bool = *(bool*)o;
break;
- case xmoc_int:
- stack[i].s_int = *(int*)o;
+ case xmoc_int:
+ stack[j].s_int = *(int*)o;
break;
- case xmoc_double:
- stack[i].s_double = *(double*)o;
+ case xmoc_double:
+ stack[j].s_double = *(double*)o;
break;
- case xmoc_charstar:
- stack[i].s_voidp = o;
+ case xmoc_charstar:
+ stack[j].s_voidp = o;
break;
- case xmoc_QString:
- stack[i].s_voidp = o;
+ case xmoc_QString:
+ stack[j].s_voidp = o;
break;
- default: // case xmoc_ptr:
+ default: // case xmoc_ptr:
+ {
+ const SmokeType &t = args[i]->st;
+ void *p = o;
+ switch(t.elem()) {
+ case Smoke::t_bool:
+ stack[j].s_bool = **(bool**)o;
+ break;
+ case Smoke::t_char:
+ stack[j].s_char = **(char**)o;
+ break;
+ case Smoke::t_uchar:
+ stack[j].s_uchar = **(unsigned char**)o;
+ break;
+ case Smoke::t_short:
+ stack[j].s_short = **(short**)p;
+ break;
+ case Smoke::t_ushort:
+ stack[j].s_ushort = **(unsigned short**)p;
+ break;
+ case Smoke::t_int:
+ stack[j].s_int = **(int**)p;
+ break;
+ case Smoke::t_uint:
+ stack[j].s_uint = **(unsigned int**)p;
+ break;
+ case Smoke::t_long:
+ stack[j].s_long = **(long**)p;
+ break;
+ case Smoke::t_ulong:
+ stack[j].s_ulong = **(unsigned long**)p;
+ break;
+ case Smoke::t_float:
+ stack[j].s_float = **(float**)p;
+ break;
+ case Smoke::t_double:
+ stack[j].s_double = **(double**)p;
+ break;
+ case Smoke::t_enum:
{
- const SmokeType &t = args[i].st;
- void *p = o;
- switch(t.elem()) {
- case Smoke::t_bool:
- stack[i].s_bool = **(bool**)o;
+ Smoke::EnumFn fn = SmokeClass(t).enumFn();
+ if (!fn) {
+ php_error(E_WARNING, "Unknown enumeration %s\n", t.name());
+ stack[j].s_enum = **(int**)p;
break;
- case Smoke::t_char:
- stack[i].s_char = **(char**)o;
- break;
- case Smoke::t_uchar:
- stack[i].s_uchar = **(unsigned char**)o;
- break;
- case Smoke::t_short:
- stack[i].s_short = **(short**)p;
- break;
- case Smoke::t_ushort:
- stack[i].s_ushort = **(unsigned short**)p;
- break;
- case Smoke::t_int:
- stack[i].s_int = **(int**)p;
- break;
- case Smoke::t_uint:
- stack[i].s_uint = **(unsigned int**)p;
- break;
- case Smoke::t_long:
- stack[i].s_long = **(long**)p;
- break;
- case Smoke::t_ulong:
- stack[i].s_ulong = **(unsigned long**)p;
- break;
- case Smoke::t_float:
- stack[i].s_float = **(float**)p;
- break;
- case Smoke::t_double:
- stack[i].s_double = **(double**)p;
- break;
- case Smoke::t_enum:
- {
- Smoke::EnumFn fn = SmokeClass(t).enumFn();
- if (!fn) {
- php_error(E_WARNING, "Unknown enumeration %s\n", t.name());
- stack[i].s_enum = **(int**)p;
- break;
- }
- const Smoke::Index id = t.typeId();
- (*fn)(Smoke::EnumToLong, id, p, stack[i].s_enum);
- }
- break;
- case Smoke::t_class:
- case Smoke::t_voidp:
- if (strchr(t.name(), '*') != 0) {
- stack[i].s_voidp = *(void **)p;
- } else {
- stack[i].s_voidp = p;
- }
- break;
- }
+ }
+ const Smoke::Index id = t.typeId();
+ (*fn)(Smoke::EnumToLong, id, p, stack[j].s_enum);
}
+ break;
+ case Smoke::t_class:
+ case Smoke::t_voidp:
+ if (strchr(t.name(), '*') != 0) {
+ stack[j].s_voidp = *(void **)p;
+ } else {
+ stack[j].s_voidp = p;
+ }
+ break;
}
+ }
+ }
}
}
--- trunk/KDE/kdebindings/php/phpqt/src/marshall_types.h #876211:876212
@@ -20,20 +20,13 @@
#define MARSHALL_TYPES_H
#include "marshall.h"
-//#include "smokephp.h"
-//#include "MethodReturnValueBase.h"
-//#include "MethodCallBase.h"
+#include <QList>
-//class QObject;
-//class QMetaObject;
-//class QMetaMethod;
-
class MocArgument;
-//struct SmokeType;
Marshall::HandlerFn getMarshallFn(const SmokeType &type);
extern void smokeStackToQtStack(const Smoke::Stack stack, void ** o, const int items, MocArgument* args);
-extern void smokeStackFromQtStack(const Smoke::Stack stack, void ** _o, const int items, MocArgument* args);
+extern void smokeStackFromQtStack(const Smoke::Stack stack, void ** _o, const int start, const int end, QList<MocArgument*> args);
#endif
--- trunk/KDE/kdebindings/php/phpqt/src/phpqt_internals.cpp #876211:876212
@@ -74,6 +74,9 @@
const QByteArray signature( d->method(_id).signature() );
const QByteArray metaMethodName = signature.left( signature.indexOf("(") );
+ /*
+ * we have a slot overridden in php user space
+ */
if( PHPQt::methodExists( o->ce_ptr() , metaMethodName.constData()) )
{
pDebug( PHPQt::Slot ) << " userspace " << signature << o->className();
@@ -85,7 +88,7 @@
ALLOC_INIT_ZVAL( zmem[i] );
}
// NOTICE is memory allocation safe here?
- InvokeSlot c( o->smoke(), args, o->zval_ptr(), zmem, _id, d, (void**) args[3].s_voidp );
+ InvokeSlot c( o->smoke(), args, o->zval_ptr(), zmem, _id, d, (void**) args[3].s_voidp, metaMethodName );
c.next();
efree(zmem);
return true;
--- trunk/KDE/kdebindings/php/phpqt/src/smokephp.cpp #876211:876212
@@ -36,6 +36,7 @@
#include "smokephp.h"
#include "VirtualMethodCall.h"
#include "InvokeSlot.h"
+#include <QRegExp>
#define ALLOCA_N(type,n) (type*)alloca(sizeof(type)*(n))
@@ -469,38 +470,72 @@
return false;
}
-void
-smokephp_QtToMoc(void** a, const QList<QByteArray> qargs, MocArgument* mocStack)
+QList<MocArgument*>
+smokephp_QtToMoc(Smoke* smoke, void** a, const QList<QByteArray> methodTypes)
{
- for(int i = 0; i < qargs.count(); i++)
+ static QRegExp * rx = 0;
+ if( rx == 0 )
+ rx = new QRegExp("^(bool|int|uint|long|ulong|double|char\\*|QString)&?$");
+
+ QList<MocArgument*> result;
+
+ foreach( QByteArray typeName, methodTypes )
{
- if( qargs[i] == "int" )
- {
- mocStack[i].st = SmokeType(PQ::smoke(),PQ::smoke()->idType("int"));
- mocStack[i].argType = xmoc_int;
+ MocArgument* arg = new MocArgument;
+ Smoke::Index typeId = 0;
+
+ if( typeName.isEmpty() ) {
+ arg->argType = xmoc_void;
+ result.append( arg );
+ } else {
+ typeName.replace( "const ", "" );
+ QString staticType = (rx->indexIn(typeName) != -1 ? rx->cap(1) : "ptr");
+ if (staticType == "ptr") {
+ arg->argType = xmoc_ptr;
+ QByteArray targetType = typeName;
+ typeId = smoke->idType(targetType.constData());
+ if (typeId == 0 && !typeName.contains('*')) {
+ if (!typeName.contains("&")) {
+ targetType += "&";
+ }
+ typeId = smoke->idType(targetType.constData());
+ }
+ } else if ( staticType == "bool" ) {
+ arg->argType = xmoc_bool;
+ } else if ( staticType == "int" ) {
+ arg->argType = xmoc_int;
+ } else if ( staticType == "uint" ) {
+ arg->argType = xmoc_uint;
+ } else if ( staticType == "long" ) {
+ arg->argType = xmoc_long;
+ } else if ( staticType == "ulong" ) {
+ arg->argType = xmoc_ulong;
+ } else if ( staticType == "double" ) {
+ arg->argType = xmoc_double;
+ } else if ( staticType == "char*" ) {
+ arg->argType = xmoc_charstar;
+ } else if ( staticType == "QString" ) {
+ arg->argType = xmoc_QString;
+ typeName += "*";
+ }
+ typeId = smoke->idType( typeName.constData() );
+ smoke = qt_Smoke;
+ if( typeId == 0 ) {
+ pNotice() << "Cannot handle " << typeName << " as slot argument";
+ return result;
+ }
+ arg->st.set( smoke, typeId );
+ result.append( arg );
}
- else if( qargs[i] == "char*" )
+ /*
{
- mocStack[i].st = SmokeType(PQ::smoke(),PQ::smoke()->idType("char*"));
- mocStack[i].argType = xmoc_charstar;
- }
- else if( qargs[i] == "bool" )
- {
- mocStack[i].st = SmokeType(PQ::smoke(),PQ::smoke()->idType("bool"));
- mocStack[i].argType = xmoc_bool;
- }
- else if( qargs[i] == "double" )
- {
- mocStack[i].st = SmokeType(PQ::smoke(),PQ::smoke()->idType("double"));
- mocStack[i].argType = xmoc_double;
- }
- else
- {
smokephp_object *o = PHPQt::getSmokePHPObjectFromQt(a[i]);
mocStack[i].st = SmokeType(PQ::smoke(),o->classId());
mocStack[i].argType = xmoc_void;
}
+ */
}
+ return result;
}
bool SmokeType::operator ==(const SmokeType &b) const
--- trunk/KDE/kdebindings/php/phpqt/src/smokephp.h #876211:876212
@@ -292,6 +292,9 @@
xmoc_ptr,
xmoc_bool,
xmoc_int,
+ xmoc_uint,
+ xmoc_long,
+ xmoc_ulong,
xmoc_double,
xmoc_charstar,
xmoc_QString,
@@ -313,7 +316,7 @@
void smokephp_init();
void* transformArray(const zval* args);
-void smokephp_QtToMoc(void** _a, const QList<QByteArray> qargs, MocArgument* moc);
+QList<MocArgument*> smokephp_QtToMoc(Smoke* smoke, void** _a, const QList<QByteArray> qargs);
extern "C" {
int treatArray(zval **val, const int num_args, va_list args, zend_hash_key *hash_key);
More information about the Kde-bindings
mailing list