Skip to content
Browse files

qtcollider: simplify and optimize referencing SC symbols and classes …

…in C++
  • Loading branch information...
1 parent b2bb1dd commit df52a2b1bf66cf281a159c7e208ae0945e06d269 @jleben jleben committed May 3, 2012
View
58 QtCollider/Common.h
@@ -100,40 +100,30 @@ namespace QtCollider {
QPalette systemPalette();
- extern PyrSymbol *s_interpretCmdLine;
- extern PyrSymbol *s_interpretPrintCmdLine;
- extern PyrSymbol *s_doFunction;
- extern PyrSymbol *s_doDrawFunc;
- extern PyrSymbol *s_prRelease;
- extern PyrSymbol *s_Rect;
- extern PyrSymbol *s_Point;
- extern PyrSymbol *s_Color;
- extern PyrSymbol *s_Size;
- extern PyrSymbol *s_Array;
- extern PyrSymbol *s_FloatArray;
- extern PyrSymbol *s_SymbolArray;
- extern PyrSymbol *s_String;
- extern PyrSymbol *s_QPalette;
- extern PyrSymbol *s_QFont;
- extern PyrSymbol *s_QObject;
- extern PyrSymbol *s_QLayout;
- extern PyrSymbol *s_QTreeViewItem;
-
-#define class_Rect s_Rect->u.classobj
-#define class_Point s_Point->u.classobj
-#define class_Color s_Color->u.classobj
-#define class_Size s_Size->u.classobj
-#define class_Array s_Array->u.classobj
-#define class_FloatArray s_FloatArray->u.classobj
-#define class_SymbolArray s_SymbolArray->u.classobj
-#define class_String s_String->u.classobj
-#define class_QPalette s_QPalette->u.classobj
-#define class_QFont s_QFont->u.classobj
-#define class_QObject s_QObject->u.classobj
-#define class_QLayout s_QLayout->u.classobj
-#define class_QTreeViewItem s_QTreeViewItem->u.classobj
-
-#define SC_CLASS( SYM ) getsym(#SYM)->u.classobj
+#define QC_DO_SYMBOLS \
+ QC_DO_SYMBOL(interpretCmdLine); \
+ QC_DO_SYMBOL(interpretPrintCmdLine); \
+ QC_DO_SYMBOL(doFunction); \
+ QC_DO_SYMBOL(doDrawFunc); \
+ QC_DO_SYMBOL(prRelease); \
+ QC_DO_SYMBOL(Rect); \
+ QC_DO_SYMBOL(Point); \
+ QC_DO_SYMBOL(Color); \
+ QC_DO_SYMBOL(Size); \
+ QC_DO_SYMBOL(QPalette); \
+ QC_DO_SYMBOL(QFont); \
+ QC_DO_SYMBOL(QObject); \
+ QC_DO_SYMBOL(QLayout); \
+ QC_DO_SYMBOL(QTreeViewItem); \
+ QC_DO_SYMBOL(Gradient); \
+ QC_DO_SYMBOL(HiliteGradient);
+
+#define QC_DO_SYMBOL(SYM) extern PyrSymbol * sym_##SYM
+QC_DO_SYMBOLS
+#undef QC_DO_SYMBOL
+
+#define SC_SYM( SYM ) QtCollider::sym_##SYM
+#define SC_CLASS( SYM ) SC_SYM(SYM)->u.classobj
}
View
4 QtCollider/QObjectProxy.cpp
@@ -90,7 +90,7 @@ bool QObjectProxy::invokeMethod( const char *method, PyrSlot *retSlot, PyrSlot *
// get data from argument slots
QtCollider::Variant argSlots[10];
- if( isKindOfSlot( argSlot, class_Array ) ) {
+ if( isKindOfSlot( argSlot, class_array ) ) {
PyrSlot *slots = slotRawObject( argSlot )->slots;
int size = slotRawObject( argSlot )->size;
int i;
@@ -210,7 +210,7 @@ void QObjectProxy::customEvent( QEvent *event )
destroyEvent( static_cast<DestroyEvent*>(event) );
return;
case (QEvent::Type) QtCollider::Event_Proxy_Release:
- invokeScMethod(s_prRelease);
+ invokeScMethod(SC_SYM(prRelease));
return;
default: ;
}
View
2 QtCollider/QWidgetProxy.cpp
@@ -485,7 +485,7 @@ void QWidgetProxy::customPaint( QPainter *painter )
QtCollider::lockLang();
if( QtCollider::beginPainting( painter ) ) {
- invokeScMethod( s_doDrawFunc, QList<QVariant>(), 0, true );
+ invokeScMethod( SC_SYM(doDrawFunc), QList<QVariant>(), 0, true );
QtCollider::endPainting();
}
View
2 QtCollider/QcApplication.cpp
@@ -111,7 +111,7 @@ void QcApplication::interpret( const QString &str, bool print )
SetObject(&slotRawInterpreter(&g->process->interpreter)->cmdLine, strObj);
g->gc->GCWrite(slotRawObject(&g->process->interpreter), strObj);
- runLibrary( print ? QtCollider::s_interpretPrintCmdLine : QtCollider::s_interpretCmdLine );
+ runLibrary( print ? SC_SYM(interpretPrintCmdLine) : SC_SYM(interpretCmdLine) );
}
QtCollider::unlockLang();
}
View
2 QtCollider/QcSignalSpy.h
@@ -174,7 +174,7 @@ class QcFunctionSignalHandler : public QcSignalSpy
args.prepend( QVariant::fromValue( _handler ) );
- _proxy->invokeScMethod( s_doFunction, args );
+ _proxy->invokeScMethod( SC_SYM(doFunction), args );
}
PyrObject * _handler;
View
70 QtCollider/Slot.cpp
@@ -50,7 +50,7 @@ static QPalette::ColorRole paletteColorRoles[] = {
void Slot::setRect( PyrSlot *slot, const QRectF &r )
{
- PyrObject *obj = instantiateObject( gMainVMGlobals->gc, class_Rect, 0, true, true );
+ PyrObject *obj = instantiateObject( gMainVMGlobals->gc, SC_CLASS(Rect), 0, true, true );
SetObject( slot, obj );
PyrSlot *slots = obj->slots;
@@ -62,7 +62,7 @@ void Slot::setRect( PyrSlot *slot, const QRectF &r )
void Slot::setPoint( PyrSlot *slot, const QPointF &pt )
{
- PyrObject *obj = instantiateObject( gMainVMGlobals->gc, class_Point, 0, true, true );
+ PyrObject *obj = instantiateObject( gMainVMGlobals->gc, SC_CLASS(Point), 0, true, true );
SetObject( slot, obj );
PyrSlot *slots = obj->slots;
@@ -72,7 +72,7 @@ void Slot::setPoint( PyrSlot *slot, const QPointF &pt )
void Slot::setSize( PyrSlot *slot, const QSizeF &sz )
{
- PyrObject *obj = instantiateObject( gMainVMGlobals->gc, class_Size, 0, true, true );
+ PyrObject *obj = instantiateObject( gMainVMGlobals->gc, SC_CLASS(Size), 0, true, true );
SetObject( slot, obj );
PyrSlot *slots = obj->slots;
@@ -94,7 +94,7 @@ void Slot::setColor( PyrSlot *slot, const QColor &c )
return;
}
- PyrObject *obj = instantiateObject( gMainVMGlobals->gc, class_Color, 0, true, true );
+ PyrObject *obj = instantiateObject( gMainVMGlobals->gc, SC_CLASS(Color), 0, true, true );
SetObject( slot, obj );
PyrSlot *slots = obj->slots;
@@ -107,7 +107,7 @@ void Slot::setColor( PyrSlot *slot, const QColor &c )
void Slot::setPalette( PyrSlot *slot, const QPalette &plt )
{
PyrGC *gc = gMainVMGlobals->gc;
- PyrObject *obj = instantiateObject( gc, class_QPalette, 0, true, true );
+ PyrObject *obj = instantiateObject( gc, SC_CLASS(QPalette), 0, true, true );
SetObject( slot, obj );
QPalette_Init( gMainVMGlobals, obj, plt );
@@ -129,7 +129,7 @@ void Slot::setQObject( PyrSlot *s, QObject *o )
void Slot::setTreeWidgetItem( PyrSlot *s, const SafePtr<QcTreeWidget::Item> & itemPtr )
{
- PyrObject *obj = instantiateObject( gMainVMGlobals->gc, class_QTreeViewItem, 0, true, true );
+ PyrObject *obj = instantiateObject( gMainVMGlobals->gc, SC_CLASS(QTreeViewItem), 0, true, true );
QcTreeWidget::Item::initialize( gMainVMGlobals, obj, itemPtr );
SetObject( s, obj );
}
@@ -308,7 +308,7 @@ QString Slot::toString( PyrSlot *slot )
if( IsSym(slot) ) {
return QString::fromUtf8( slotRawSymbol(slot)->name );
}
- else if( isKindOfSlot( slot, class_String ) ) {
+ else if( isKindOfSlot( slot, class_string ) ) {
int len = slotRawObject( slot )->size;
return QString::fromUtf8( slotRawString(slot)->s, len );
}
@@ -317,7 +317,7 @@ QString Slot::toString( PyrSlot *slot )
QPointF Slot::toPoint( PyrSlot *slot )
{
- if( !isKindOfSlot( slot, class_Point ) ) {
+ if( !isKindOfSlot( slot, SC_CLASS(Point) ) ) {
return QPointF();
}
PyrSlot *slots = slotRawObject( slot )->slots;
@@ -330,7 +330,7 @@ QPointF Slot::toPoint( PyrSlot *slot )
QRectF Slot::toRect( PyrSlot *slot )
{
- if( !isKindOfSlot( slot, class_Rect ) ) {
+ if( !isKindOfSlot( slot, SC_CLASS(Rect) ) ) {
return QRectF();
}
@@ -347,7 +347,7 @@ QRectF Slot::toRect( PyrSlot *slot )
QSizeF Slot::toSize( PyrSlot *slot )
{
- if( !isKindOfSlot( slot, class_Size ) ) {
+ if( !isKindOfSlot( slot, SC_CLASS(Size) ) ) {
return QSizeF();
}
@@ -390,7 +390,7 @@ QColor Slot::toColor( PyrSlot *slot )
PyrObject *obj = slotRawObject(slot);
PyrClass *klass = obj->classptr;
- if( klass == class_Color )
+ if( klass == SC_CLASS(Color) )
return asColor(obj);
if( klass == SC_CLASS(Gradient) || klass == SC_CLASS(HiliteGradient) )
@@ -411,7 +411,7 @@ QColor Slot::toColor( PyrSlot *slot )
QFont Slot::toFont( PyrSlot *slot )
{
- if( !isKindOfSlot( slot, class_QFont ) )
+ if( !isKindOfSlot( slot, SC_CLASS(QFont) ) )
return QFont();
PyrSlot *slots = slotRawObject(slot)->slots;
@@ -445,7 +445,7 @@ QFont Slot::toFont( PyrSlot *slot )
QPalette Slot::toPalette( PyrSlot *slot )
{
- if( !isKindOfSlot( slot, class_QPalette ) )
+ if( !isKindOfSlot( slot, SC_CLASS(QPalette) ) )
return QPalette();
QPalette *p = QPALETTE_FROM_OBJECT(slotRawObject(slot));
@@ -454,7 +454,7 @@ QPalette Slot::toPalette( PyrSlot *slot )
VariantList Slot::toVariantList( PyrSlot *slot )
{
- if( isKindOfSlot( slot, class_Array ) ) {
+ if( isKindOfSlot( slot, class_array ) ) {
PyrObject *obj = slotRawObject( slot );
PyrSlot *slots = obj->slots;
int size = obj->size;
@@ -463,7 +463,7 @@ VariantList Slot::toVariantList( PyrSlot *slot )
list.data << Slot::toVariant( slots );
return list;
}
- else if( isKindOfSlot( slot, class_SymbolArray ) ) {
+ else if( isKindOfSlot( slot, class_symbolarray ) ) {
PyrSymbolArray *symarray = slotRawSymbolArray( slot );
PyrSymbol **symbols = symarray->symbols;
int size = symarray->size;
@@ -515,7 +515,7 @@ static QVector<numeric_type> toNumericVector( PyrObject *obj )
QObjectProxy* Slot::toObjectProxy( PyrSlot *slot )
{
- if( !isKindOfSlot( slot, class_QObject ) ) return 0;
+ if( !isKindOfSlot( slot, SC_CLASS(QObject) ) ) return 0;
QObjectProxy *proxy = 0;
PyrSlot *proxySlot = slotRawObject( slot )->slots;
if( IsPtr( proxySlot ) ) proxy = (QObjectProxy*) slotRawPtr( proxySlot );
@@ -524,7 +524,7 @@ QObjectProxy* Slot::toObjectProxy( PyrSlot *slot )
QcTreeWidget::ItemPtr Slot::toTreeWidgetItem( PyrSlot *slot )
{
- if( !isKindOfSlot( slot, class_QTreeViewItem ) ) return QcTreeWidget::ItemPtr();
+ if( !isKindOfSlot( slot, SC_CLASS(QTreeViewItem) ) ) return QcTreeWidget::ItemPtr();
PyrSlot *ptrSlot = slotRawObject(slot)->slots+0;
if( IsPtr( ptrSlot ) ) {
QcTreeWidget::ItemPtr *safePtr = static_cast<QcTreeWidget::ItemPtr*>( slotRawPtr(ptrSlot) );
@@ -563,38 +563,38 @@ QVariant Slot::toVariant( PyrSlot *slot )
else if( format == obj_int32 || format == obj_int16 || format == obj_int8 )
return QVariant::fromValue< QVector<int> >( toNumericVector<int>(obj) );
- else if( isKindOfSlot( slot, class_String ) ) {
+ else if( isKindOfSlot( slot, class_string ) ) {
return QVariant( toString(slot) );
}
- else if( isKindOfSlot( slot, class_Point ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(Point) ) ) {
return QVariant( toPoint( slot ) );
}
- else if( isKindOfSlot( slot, class_Rect ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(Rect) ) ) {
return QVariant( toRect(slot) );
}
- else if( isKindOfSlot( slot, class_Size ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(Size) ) ) {
return QVariant( toSize(slot) );
}
- else if( klass == class_Color ||
+ else if( klass == SC_CLASS(Color) ||
klass == SC_CLASS(Gradient) ||
klass == SC_CLASS(HiliteGradient) )
{
return QVariant::fromValue<QColor>( toColor(slot) );
}
- else if( isKindOfSlot( slot, class_QFont ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(QFont) ) ) {
return QVariant::fromValue<QFont>( toFont(slot) );
}
- else if( isKindOfSlot( slot, class_QPalette ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(QPalette) ) ) {
return QVariant::fromValue<QPalette>( toPalette(slot) );
}
- else if( isKindOfSlot( slot, class_QObject ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(QObject) ) ) {
proxy = toObjectProxy(slot);
return QVariant::fromValue<QObjectProxy*>( proxy );
}
- else if( isKindOfSlot( slot, class_Array ) || isKindOfSlot( slot, class_SymbolArray ) ) {
+ else if( isKindOfSlot( slot, class_array ) || isKindOfSlot( slot, class_symbolarray ) ) {
return QVariant::fromValue<VariantList>( toVariantList(slot) );
}
- else if( isKindOfSlot( slot, class_QTreeViewItem ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(QTreeViewItem) ) ) {
return QVariant::fromValue<QcTreeWidget::ItemPtr>( toTreeWidgetItem(slot) );
}
else {
@@ -652,34 +652,34 @@ void QtCollider::Variant::setData( PyrSlot *slot )
_type = qMetaTypeId< QVector<int> >();
_ptr = new QVector<int>( toNumericVector<int>(obj) );
}
- else if( isKindOfSlot( slot, class_String ) ) {
+ else if( isKindOfSlot( slot, class_string ) ) {
_type = QMetaType::QString;
_ptr = new QString( toString(slot) );
}
- else if( isKindOfSlot( slot, class_Point ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(Point) ) ) {
_type = QMetaType::QPointF;
_ptr = new QPointF( toPoint(slot) );
}
- else if( isKindOfSlot( slot, class_Rect ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(Rect) ) ) {
_type = QMetaType::QRectF;
_ptr = new QRectF( toRect(slot) );
}
- else if( isKindOfSlot( slot, class_Size ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(Size) ) ) {
_type = QMetaType::QSizeF;
_ptr = new QSizeF( toSize(slot) );
}
- else if( klass == class_Color ||
+ else if( klass == SC_CLASS(Color) ||
klass == SC_CLASS(Gradient) ||
klass == SC_CLASS(HiliteGradient) )
{
_type = QMetaType::QColor;
_ptr = new QColor( toColor(slot) );
}
- else if( isKindOfSlot( slot, class_Array ) || isKindOfSlot( slot, class_SymbolArray ) ) {
+ else if( isKindOfSlot( slot, class_array ) || isKindOfSlot( slot, class_symbolarray ) ) {
_type = qMetaTypeId<VariantList>();
_ptr = new VariantList( toVariantList(slot) );
}
- else if( isKindOfSlot( slot, class_QObject ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(QObject) ) ) {
proxy = toObjectProxy(slot);
if( !proxy ) {
_type = QMetaType::Void;
@@ -690,7 +690,7 @@ void QtCollider::Variant::setData( PyrSlot *slot )
_ptr = new QObjectProxy*( proxy );
}
}
- else if( isKindOfSlot( slot, class_QTreeViewItem ) ) {
+ else if( isKindOfSlot( slot, SC_CLASS(QTreeViewItem) ) ) {
_type = qMetaTypeId<QcTreeWidget::ItemPtr>();
_ptr = new QcTreeWidget::ItemPtr( toTreeWidgetItem(slot) );
}
View
4 QtCollider/primitives/prim_QObject.cpp
@@ -72,7 +72,7 @@ QC_LANG_PRIMITIVE( QObject_New, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g )
PyrSlot *slotArg = a+1;
- if( isKindOfSlot( slotArg, class_Array ) ) {
+ if( isKindOfSlot( slotArg, class_array ) ) {
PyrObject *array = slotRawObject( slotArg );
PyrSlot *s = array->slots;
int size = array->size;
@@ -464,7 +464,7 @@ QC_LANG_PRIMITIVE( QObject_DisconnectObject, 2, PyrSlot *r, PyrSlot *a, VMGlobal
QC_LANG_PRIMITIVE( QObject_ConnectSlot, 3, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
// Args: signal, receiver, slot
- if( !isKindOfSlot( a+1, class_QObject )
+ if( !isKindOfSlot( a+1, SC_CLASS(QObject) )
|| NotSym( a+0 ) || NotSym( a+2 ) ) return errWrongType;
PyrSymbol *symSig = slotRawSymbol( a+0 );
View
2 QtCollider/primitives/prim_QPalette.cpp
@@ -40,7 +40,7 @@ int QPalette_Finalize( struct VMGlobals *g, struct PyrObject *obj )
void QPalette_Init( struct VMGlobals *g, struct PyrObject *obj, const QPalette & palette )
{
- assert( obj->classptr == class_QPalette );
+ assert( obj->classptr == SC_CLASS(QPalette) );
assert( IsNil(obj->slots) && IsNil(obj->slots+1) );
QPalette *p = new QPalette(palette);
View
2 QtCollider/primitives/prim_QPen.cpp
@@ -215,7 +215,7 @@ QC_QPEN_PRIMITIVE( QPen_SetDashPattern, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g
{
if( !IsObj( a ) ) return errWrongType;
PyrObject *obj = slotRawObject( a );
- if( obj->classptr != class_FloatArray ) return errWrongType;
+ if( obj->classptr != class_floatarray ) return errWrongType;
PyrFloatArray *farray = reinterpret_cast<PyrFloatArray*>(obj);
int s = farray->size;
View
2 QtCollider/primitives/prim_QWidget.cpp
@@ -82,7 +82,7 @@ QC_LANG_PRIMITIVE( QWidget_MapToGlobal, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g
}
QC_LANG_PRIMITIVE( QWidget_SetLayout, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g ) {
- if( !isKindOfSlot( a, class_QLayout ) ) return errWrongType;
+ if( !isKindOfSlot( a, SC_CLASS(QLayout) ) ) return errWrongType;
QWidgetProxy *wProxy = qobject_cast<QWidgetProxy*>( Slot::toObjectProxy(r) );
View
44 QtCollider/primitives/primitives.cpp
@@ -28,24 +28,9 @@
namespace QtCollider {
-PyrSymbol *s_interpretCmdLine;
-PyrSymbol *s_interpretPrintCmdLine;
-PyrSymbol *s_doFunction;
-PyrSymbol *s_doDrawFunc;
-PyrSymbol *s_prRelease;
-PyrSymbol *s_Rect;
-PyrSymbol *s_Point;
-PyrSymbol *s_Color;
-PyrSymbol *s_Size;
-PyrSymbol *s_Array;
-PyrSymbol *s_FloatArray;
-PyrSymbol *s_SymbolArray;
-PyrSymbol *s_String;
-PyrSymbol *s_QPalette;
-PyrSymbol *s_QFont;
-PyrSymbol *s_QObject;
-PyrSymbol *s_QLayout;
-PyrSymbol *s_QTreeViewItem;
+#define QC_DO_SYMBOL(SYM) PyrSymbol * sym_##SYM
+QC_DO_SYMBOLS
+#undef QC_DO_SYMBOL
void defineQObjectPrimitives();
void defineQPenPrimitives();
@@ -68,26 +53,9 @@ void initPrimitives () {
defineMiscPrimitives();
defineQPalettePrimitives();
- s_interpretCmdLine = getsym("interpretCmdLine");
- s_interpretPrintCmdLine = getsym("interpretPrintCmdLine");
-
- s_doFunction = getsym("doFunction");
- s_doDrawFunc = getsym("doDrawFunc");
- s_prRelease = getsym("prRelease");
-
- s_Rect = getsym("Rect");
- s_Point = getsym("Point");
- s_Size = getsym("Size");
- s_Color = getsym("Color");
- s_Array = getsym("Array");
- s_FloatArray = getsym("FloatArray");
- s_SymbolArray = getsym("SymbolArray");
- s_String = getsym("String");
- s_QObject = getsym("QObject");
- s_QLayout = getsym("QLayout");
- s_QFont = getsym("QFont");
- s_QPalette = getsym("QPalette");
- s_QTreeViewItem = getsym("QTreeViewItem");
+#define QC_DO_SYMBOL(SYM) sym_##SYM = getsym(#SYM);
+QC_DO_SYMBOLS
+#undef QC_DO_SYMBOL
}
} // namespace QtCollider
View
2 QtCollider/widgets/QcTreeWidget.cpp
@@ -230,7 +230,7 @@ QcTreeWidget::ItemPtr QcTreeWidget::Item::safePtr( QTreeWidgetItem * item )
void QcTreeWidget::Item::initialize (
VMGlobals *g, PyrObject *obj, const QcTreeWidget::ItemPtr &ptr )
{
- Q_ASSERT( isKindOf( obj, class_QTreeViewItem ) );
+ Q_ASSERT( isKindOf( obj, SC_CLASS(QTreeViewItem) ) );
if( ptr.id() ) {
// store the SafePtr
QcTreeWidget::ItemPtr *newPtr = new QcTreeWidget::ItemPtr( ptr );

0 comments on commit df52a2b

Please sign in to comment.
Something went wrong with that request. Please try again.