From 2937907080837fe26b41877516f5cef52a195f84 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 24 Nov 2016 17:14:23 +0100 Subject: Drop the return value from QScxmlDataModel::evaluateForEach() This is an inconsistency in the public API. The bool return value is unnecessary as we pass a bool *ok, just like we do for the other evaluation methods. Change-Id: I750e5d6d39df417fec727ef6f3ec1ade5ddc2dfc Reviewed-by: Jarek Kobus --- src/scxml/qscxmlcppdatamodel.cpp | 3 +-- src/scxml/qscxmlcppdatamodel.h | 2 +- src/scxml/qscxmldatamodel.h | 4 ++-- src/scxml/qscxmlecmascriptdatamodel.cpp | 18 +++++++++--------- src/scxml/qscxmlecmascriptdatamodel.h | 2 +- src/scxml/qscxmlexecutablecontent.cpp | 8 +++----- src/scxml/qscxmlnulldatamodel.cpp | 3 +-- src/scxml/qscxmlnulldatamodel.h | 2 +- 8 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/scxml/qscxmlcppdatamodel.cpp b/src/scxml/qscxmlcppdatamodel.cpp index bc09d65..d363c27 100644 --- a/src/scxml/qscxmlcppdatamodel.cpp +++ b/src/scxml/qscxmlcppdatamodel.cpp @@ -167,13 +167,12 @@ void QScxmlCppDataModel::evaluateInitialization(EvaluatorId id, bool *ok) Q_UNREACHABLE(); } -bool QScxmlCppDataModel::evaluateForeach(EvaluatorId id, bool *ok, ForeachLoopBody *body) +void QScxmlCppDataModel::evaluateForeach(EvaluatorId id, bool *ok, ForeachLoopBody *body) { Q_UNUSED(id); Q_UNUSED(ok); Q_UNUSED(body); Q_UNREACHABLE(); - return false; } /*! diff --git a/src/scxml/qscxmlcppdatamodel.h b/src/scxml/qscxmlcppdatamodel.h index fb59336..97ca636 100644 --- a/src/scxml/qscxmlcppdatamodel.h +++ b/src/scxml/qscxmlcppdatamodel.h @@ -66,7 +66,7 @@ public: #ifndef Q_QDOC void evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; void evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; - bool evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) Q_DECL_OVERRIDE Q_DECL_FINAL; + void evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) Q_DECL_OVERRIDE Q_DECL_FINAL; #endif // Q_QDOC void setScxmlEvent(const QScxmlEvent &scxmlEvent) Q_DECL_OVERRIDE Q_DECL_FINAL; diff --git a/src/scxml/qscxmldatamodel.h b/src/scxml/qscxmldatamodel.h index 845d8bf..9f2b921 100644 --- a/src/scxml/qscxmldatamodel.h +++ b/src/scxml/qscxmldatamodel.h @@ -64,7 +64,7 @@ public: { public: virtual ~ForeachLoopBody(); - virtual bool run() = 0; + virtual void run(bool *ok) = 0; }; public: @@ -83,7 +83,7 @@ public: virtual void evaluateToVoid(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0; virtual void evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0; virtual void evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok) = 0; - virtual bool evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) = 0; + virtual void evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) = 0; #endif // Q_QDOC virtual void setScxmlEvent(const QScxmlEvent &event) = 0; diff --git a/src/scxml/qscxmlecmascriptdatamodel.cpp b/src/scxml/qscxmlecmascriptdatamodel.cpp index 32c49f0..4b0329e 100644 --- a/src/scxml/qscxmlecmascriptdatamodel.cpp +++ b/src/scxml/qscxmlecmascriptdatamodel.cpp @@ -469,7 +469,7 @@ void QScxmlEcmaScriptDataModel::evaluateInitialization(EvaluatorId id, bool *ok) evaluateAssignment(id, ok); } -bool QScxmlEcmaScriptDataModel::evaluateForeach(EvaluatorId id, bool *ok, ForeachLoopBody *body) +void QScxmlEcmaScriptDataModel::evaluateForeach(EvaluatorId id, bool *ok, ForeachLoopBody *body) { Q_D(QScxmlEcmaScriptDataModel); Q_ASSERT(ok); @@ -480,7 +480,7 @@ bool QScxmlEcmaScriptDataModel::evaluateForeach(EvaluatorId id, bool *ok, Foreac if (!jsArray.isArray()) { d->submitError(QStringLiteral("error.execution"), QStringLiteral("invalid array '%1' in %2").arg(d->string(info.array), d->string(info.context))); *ok = false; - return false; + return; } QString item = d->string(info.item); @@ -490,7 +490,7 @@ bool QScxmlEcmaScriptDataModel::evaluateForeach(EvaluatorId id, bool *ok, Foreac d->submitError(QStringLiteral("error.execution"), QStringLiteral("invalid item '%1' in %2") .arg(d->string(info.item), d->string(info.context))); *ok = false; - return false; + return; } const int length = jsArray.property(QStringLiteral("length")).toInt(); @@ -502,17 +502,17 @@ bool QScxmlEcmaScriptDataModel::evaluateForeach(EvaluatorId id, bool *ok, Foreac QJSValue currentItem = jsArray.property(static_cast(currentIndex)); *ok = d->setProperty(item, currentItem, context); if (!*ok) - return false; + return; if (hasIndex) { *ok = d->setProperty(idx, currentIndex, context); if (!*ok) - return false; + return; } - if (!body->run()) - return false; + body->run(ok); + if (!*ok) + return; } - - return true; + *ok = true; } /*! diff --git a/src/scxml/qscxmlecmascriptdatamodel.h b/src/scxml/qscxmlecmascriptdatamodel.h index b1d9f55..808830a 100644 --- a/src/scxml/qscxmlecmascriptdatamodel.h +++ b/src/scxml/qscxmlecmascriptdatamodel.h @@ -63,7 +63,7 @@ public: void evaluateToVoid(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; void evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; void evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; - bool evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) Q_DECL_OVERRIDE Q_DECL_FINAL; + void evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) Q_DECL_OVERRIDE Q_DECL_FINAL; #endif // Q_QDOC void setScxmlEvent(const QScxmlEvent &event) Q_DECL_OVERRIDE; diff --git a/src/scxml/qscxmlexecutablecontent.cpp b/src/scxml/qscxmlexecutablecontent.cpp index 5df8b1f..9fbcd15 100644 --- a/src/scxml/qscxmlexecutablecontent.cpp +++ b/src/scxml/qscxmlexecutablecontent.cpp @@ -216,11 +216,9 @@ const InstructionId *QScxmlExecutionEngine::step(const InstructionId *ip, bool * , loopStart(loopStart) {} - bool run() Q_DECL_OVERRIDE + void run(bool *ok) Q_DECL_OVERRIDE { - bool ok = true; - engine->step(loopStart, &ok); - return ok; + engine->step(loopStart, ok); } }; @@ -229,7 +227,7 @@ const InstructionId *QScxmlExecutionEngine::step(const InstructionId *ip, bool * const InstructionId *loopStart = _foreach->blockstart(); ip += _foreach->size(); LoopBody body(this, loopStart); - *ok = dataModel->evaluateForeach(_foreach->doIt, ok, &body) && *ok; + dataModel->evaluateForeach(_foreach->doIt, ok, &body); return ip; } diff --git a/src/scxml/qscxmlnulldatamodel.cpp b/src/scxml/qscxmlnulldatamodel.cpp index 08a9333..35f1b91 100644 --- a/src/scxml/qscxmlnulldatamodel.cpp +++ b/src/scxml/qscxmlnulldatamodel.cpp @@ -203,7 +203,7 @@ void QScxmlNullDataModel::evaluateInitialization(QScxmlExecutableContent::Evalua QStringLiteral("Cannot initialize values on a null data model")); } -bool QScxmlNullDataModel::evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) +void QScxmlNullDataModel::evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) { Q_UNUSED(id); Q_UNUSED(body); @@ -211,7 +211,6 @@ bool QScxmlNullDataModel::evaluateForeach(QScxmlExecutableContent::EvaluatorId i QScxmlStateMachinePrivate::get(stateMachine())->submitError( QStringLiteral("error.execution"), QStringLiteral("Cannot run foreach on a null data model")); - return false; } /*! diff --git a/src/scxml/qscxmlnulldatamodel.h b/src/scxml/qscxmlnulldatamodel.h index e4f7942..f5aeb26 100644 --- a/src/scxml/qscxmlnulldatamodel.h +++ b/src/scxml/qscxmlnulldatamodel.h @@ -62,7 +62,7 @@ public: void evaluateToVoid(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; void evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; void evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; - bool evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) Q_DECL_OVERRIDE Q_DECL_FINAL; + void evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) Q_DECL_OVERRIDE Q_DECL_FINAL; #endif // Q_QDOC void setScxmlEvent(const QScxmlEvent &event) Q_DECL_OVERRIDE; -- cgit v1.2.3 From 066aa32db0b1c49c2b87ebb8920391eecb596c56 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 25 Nov 2016 10:46:28 +0100 Subject: Set ok to false in the evaluate stubs of the C++ data model If those get called, it's definitely an error. Change-Id: I0515e02ff77c2839bc4d31d35d266ecdfecb7624 Reviewed-by: Jarek Kobus --- src/scxml/qscxmlcppdatamodel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scxml/qscxmlcppdatamodel.cpp b/src/scxml/qscxmlcppdatamodel.cpp index d363c27..0c20381 100644 --- a/src/scxml/qscxmlcppdatamodel.cpp +++ b/src/scxml/qscxmlcppdatamodel.cpp @@ -156,22 +156,22 @@ bool QScxmlCppDataModel::setup(const QVariantMap &initialDataValues) void QScxmlCppDataModel::evaluateAssignment(EvaluatorId id, bool *ok) { Q_UNUSED(id); - Q_UNUSED(ok); + *ok = false; Q_UNREACHABLE(); } void QScxmlCppDataModel::evaluateInitialization(EvaluatorId id, bool *ok) { Q_UNUSED(id); - Q_UNUSED(ok); + *ok = false; Q_UNREACHABLE(); } void QScxmlCppDataModel::evaluateForeach(EvaluatorId id, bool *ok, ForeachLoopBody *body) { Q_UNUSED(id); - Q_UNUSED(ok); Q_UNUSED(body); + *ok = false; Q_UNREACHABLE(); } -- cgit v1.2.3 From fd85b14ca803cdda43f8a6437d6d6d7d5560017f Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 28 Nov 2016 14:38:50 +0100 Subject: Pass the factory to QScxmlInvokableService::start() ... instead of the various properties of the factory. This makes the API nicer. Change-Id: I16f3c6382d6cc71500147f8d2dbd35392924b5f0 Reviewed-by: Erik Verbruggen --- src/scxml/qscxmlinvokableservice.cpp | 9 ++++----- src/scxml/qscxmlinvokableservice.h | 9 +++------ src/scxml/qscxmlstatemachine.cpp | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/scxml/qscxmlinvokableservice.cpp b/src/scxml/qscxmlinvokableservice.cpp index 9af6be7..b135e05 100644 --- a/src/scxml/qscxmlinvokableservice.cpp +++ b/src/scxml/qscxmlinvokableservice.cpp @@ -236,18 +236,17 @@ QScxmlScxmlService::QScxmlScxmlService(QScxmlStateMachine *stateMachine, QScxmlStateMachinePrivate::get(stateMachine)->m_parentStateMachine = parentStateMachine; } -bool QScxmlScxmlService::start(const QScxmlExecutableContent::InvokeInfo &invokeInfo, - const QVector ¶meters, - const QVector &names) +bool QScxmlScxmlService::start(const QScxmlInvokableServiceFactory *factory) { Q_D(QScxmlScxmlService); qCDebug(qscxmlLog) << parentStateMachine() << "preparing to start" << d->stateMachine; bool ok = false; - auto id = d->calculateId(parentStateMachine(), invokeInfo, &ok); + auto id = d->calculateId(parentStateMachine(), factory->invokeInfo(), &ok); if (!ok) return false; - auto data = d->calculateData(parentStateMachine(), parameters, names, &ok); + auto data = d->calculateData(parentStateMachine(), factory->parameters(), factory->names(), + &ok); if (!ok) return false; diff --git a/src/scxml/qscxmlinvokableservice.h b/src/scxml/qscxmlinvokableservice.h index 6efc07d..9e317cc 100644 --- a/src/scxml/qscxmlinvokableservice.h +++ b/src/scxml/qscxmlinvokableservice.h @@ -48,6 +48,7 @@ QT_BEGIN_NAMESPACE class QScxmlEvent; class QScxmlStateMachine; +class QScxmlInvokableServiceFactory; class QScxmlInvokableServicePrivate; class Q_SCXML_EXPORT QScxmlInvokableService : public QObject { @@ -63,9 +64,7 @@ public: QScxmlStateMachine *parentStateMachine() const; - virtual bool start(const QScxmlExecutableContent::InvokeInfo &invokeInfo, - const QVector ¶meters, - const QVector &names) = 0; + virtual bool start(const QScxmlInvokableServiceFactory *factory) = 0; virtual QString id() const = 0; virtual QString name() const = 0; virtual void postEvent(QScxmlEvent *event) = 0; @@ -106,9 +105,7 @@ public: QScxmlStateMachine *parentStateMachine, QObject *parent = nullptr); - bool start(const QScxmlExecutableContent::InvokeInfo &invokeInfo, - const QVector ¶meters, - const QVector &names) Q_DECL_OVERRIDE; + bool start(const QScxmlInvokableServiceFactory *factory) Q_DECL_OVERRIDE; QString id() const Q_DECL_OVERRIDE; QString name() const Q_DECL_OVERRIDE; void postEvent(QScxmlEvent *event) Q_DECL_OVERRIDE; diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp index ef5a312..cfa37de 100644 --- a/src/scxml/qscxmlstatemachine.cpp +++ b/src/scxml/qscxmlstatemachine.cpp @@ -449,7 +449,7 @@ void QScxmlStateMachinePrivate::addService(int invokingState) continue; // service failed to start const QString serviceName = service->name(); m_invokedServices[size_t(id)] = { invokingState, service, serviceName }; - service->start(factory->invokeInfo(), factory->parameters(), factory->names()); + service->start(factory); } emitInvokedServicesChanged(); } -- cgit v1.2.3 From 37747423e5d3bd419fa1d413c7d545a2d4e5552f Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 28 Nov 2016 17:13:37 +0100 Subject: Reduce the public API exposed in qscxmlinvokableservice.h We inline QScxmlInvokableService::finalize into the only place where it is used. Furthermore we construct static SCXML state machines through their metaobjects rather than directly calling the constructor. This way we can drop the template, make all the service factories QObjects, drop the intermediate QScxmlScxmlServiceFactory class, and greatly reduce the API exposed in qscxmlinvokableservice.h. In addition, as some of the structs in QScxmlExecutableContent are fairly large, we return them as const references, rather than by value. Change-Id: Ia9ee61b5668b8af44307787339c08f3c6f23f713 Reviewed-by: Erik Verbruggen --- src/scxml/qscxmlcompiler.cpp | 22 +++-- src/scxml/qscxmlinvokableservice.cpp | 161 ++++++++++++++++++----------------- src/scxml/qscxmlinvokableservice.h | 89 +++++++------------ src/scxml/qscxmlinvokableservice_p.h | 41 +++++++-- src/scxml/qscxmlstatemachine.cpp | 13 ++- tools/qscxmlc/decl.t | 2 +- tools/qscxmlc/scxmlcppdumper.cpp | 16 +++- 7 files changed, 186 insertions(+), 158 deletions(-) diff --git a/src/scxml/qscxmlcompiler.cpp b/src/scxml/qscxmlcompiler.cpp index 691f87a..b8434c6 100644 --- a/src/scxml/qscxmlcompiler.cpp +++ b/src/scxml/qscxmlcompiler.cpp @@ -473,13 +473,14 @@ private: }; #ifndef BUILD_QSCXMLC -class InvokeDynamicScxmlFactory: public QScxmlScxmlServiceFactory +class InvokeDynamicScxmlFactory: public QScxmlInvokableServiceFactory { + Q_OBJECT public: InvokeDynamicScxmlFactory(const QScxmlExecutableContent::InvokeInfo &invokeInfo, const QVector &namelist, const QVector ¶ms) - : QScxmlScxmlServiceFactory(invokeInfo, namelist, params) + : QScxmlInvokableServiceFactory(invokeInfo, namelist, params) {} void setContent(const QSharedPointer &content) @@ -647,12 +648,12 @@ inline QScxmlInvokableService *InvokeDynamicScxmlFactory::invoke( QScxmlStateMachine *parentStateMachine) { bool ok = true; - auto srcexpr = d->calculateSrcexpr(parentStateMachine, &ok); + auto srcexpr = calculateSrcexpr(parentStateMachine, invokeInfo().expr, &ok); if (!ok) return Q_NULLPTR; if (!srcexpr.isEmpty()) - return invokeDynamic(parentStateMachine, srcexpr); + return invokeDynamicScxmlService(srcexpr, parentStateMachine, this); auto childStateMachine = DynamicStateMachine::build(m_content.data()); @@ -660,15 +661,16 @@ inline QScxmlInvokableService *InvokeDynamicScxmlFactory::invoke( dm->setParent(childStateMachine); childStateMachine->setDataModel(dm); - return invokeStatic(childStateMachine, parentStateMachine); + return invokeStaticScxmlService(childStateMachine, parentStateMachine, this); } #endif // BUILD_QSCXMLC } // anonymous namespace #ifndef BUILD_QSCXMLC -QScxmlScxmlService *QScxmlScxmlServiceFactory::invokeDynamic( - QScxmlStateMachine *parentStateMachine, const QString &sourceUrl) +QScxmlScxmlService *invokeDynamicScxmlService(const QString &sourceUrl, + QScxmlStateMachine *parentStateMachine, + QScxmlInvokableServiceFactory *factory) { QScxmlCompiler::Loader *loader = parentStateMachine->loader(); @@ -708,7 +710,7 @@ QScxmlScxmlService *QScxmlScxmlServiceFactory::invokeDynamic( dm->setParent(childStateMachine); childStateMachine->setDataModel(dm); - return invokeStatic(childStateMachine, parentStateMachine); + return invokeStaticScxmlService(childStateMachine, parentStateMachine, factory); } #endif // BUILD_QSCXMLC @@ -2483,3 +2485,7 @@ QScxmlCompilerPrivate::ParserState::ParserState(QScxmlCompilerPrivate::ParserSta {} QT_END_NAMESPACE + +#ifndef BUILD_QSCXMLC +#include "qscxmlcompiler.moc" +#endif diff --git a/src/scxml/qscxmlinvokableservice.cpp b/src/scxml/qscxmlinvokableservice.cpp index b135e05..9dfda21 100644 --- a/src/scxml/qscxmlinvokableservice.cpp +++ b/src/scxml/qscxmlinvokableservice.cpp @@ -59,9 +59,18 @@ QScxmlInvokableServiceFactoryPrivate::QScxmlInvokableServiceFactoryPrivate( , parameters(parameters) {} +QScxmlStaticScxmlServiceFactoryPrivate::QScxmlStaticScxmlServiceFactoryPrivate( + const QMetaObject *metaObject, + const QScxmlExecutableContent::InvokeInfo &invokeInfo, + const QVector &names, + const QVector ¶meters) + : QScxmlInvokableServiceFactoryPrivate(invokeInfo, names, parameters), metaObject(metaObject) +{ +} + QScxmlInvokableService::QScxmlInvokableService(QScxmlStateMachine *parentStateMachine, - QObject *parent) : - QObject(*(new QScxmlInvokableServicePrivate(parentStateMachine)), parent) + QScxmlInvokableServiceFactory *factory) : + QObject(*(new QScxmlInvokableServicePrivate(parentStateMachine)), factory) { } @@ -71,58 +80,43 @@ QScxmlStateMachine *QScxmlInvokableService::parentStateMachine() const return d->parentStateMachine; } -void QScxmlInvokableService::finalize(QScxmlExecutableContent::ContainerId finalize) -{ - if (finalize != QScxmlExecutableContent::NoInstruction) { - auto psm = parentStateMachine(); - qCDebug(qscxmlLog) << psm << "running finalize on event"; - auto smp = QScxmlStateMachinePrivate::get(psm); - smp->m_executionEngine->execute(finalize); - } -} - -QScxmlInvokableService::QScxmlInvokableService(QScxmlInvokableServicePrivate &dd, QObject *parent) : - QObject(dd, parent) -{ -} - QScxmlInvokableServiceFactory::QScxmlInvokableServiceFactory( const QScxmlExecutableContent::InvokeInfo &invokeInfo, const QVector &names, - const QVector ¶meters) - : d(new QScxmlInvokableServiceFactoryPrivate(invokeInfo, names, parameters)) + const QVector ¶meters, + QObject *parent) + : QObject(*(new QScxmlInvokableServiceFactoryPrivate(invokeInfo, names, parameters)), parent) {} -QScxmlInvokableServiceFactory::~QScxmlInvokableServiceFactory() -{ - delete d; -} - -QScxmlExecutableContent::InvokeInfo QScxmlInvokableServiceFactory::invokeInfo() const +const QScxmlExecutableContent::InvokeInfo &QScxmlInvokableServiceFactory::invokeInfo() const { + Q_D(const QScxmlInvokableServiceFactory); return d->invokeInfo; } -QVector QScxmlInvokableServiceFactory::parameters() const +const QVector & +QScxmlInvokableServiceFactory::parameters() const { + Q_D(const QScxmlInvokableServiceFactory); return d->parameters; } -QVector QScxmlInvokableServiceFactory::names() const +const QVector &QScxmlInvokableServiceFactory::names() const { + Q_D(const QScxmlInvokableServiceFactory); return d->names; } -QString QScxmlInvokableServiceFactoryPrivate::calculateSrcexpr(QScxmlStateMachine *parent, - bool *ok) const +QString calculateSrcexpr(QScxmlStateMachine *parent, QScxmlExecutableContent::EvaluatorId srcexpr, + bool *ok) { Q_ASSERT(ok); *ok = true; auto dataModel = parent->dataModel(); - if (invokeInfo.expr != QScxmlExecutableContent::NoEvaluator) { + if (srcexpr != QScxmlExecutableContent::NoEvaluator) { *ok = false; - auto v = dataModel->evaluateToString(invokeInfo.expr, ok); + auto v = dataModel->evaluateToString(srcexpr, ok); if (!*ok) return QString(); return v; @@ -217,29 +211,27 @@ QVariantMap QScxmlInvokableServicePrivate::calculateData( return result; } -QScxmlScxmlServicePrivate::QScxmlScxmlServicePrivate(QScxmlStateMachine *stateMachine, - QScxmlStateMachine *parentStateMachine) : - QScxmlInvokableServicePrivate(parentStateMachine), stateMachine(stateMachine) -{} - -QScxmlScxmlServicePrivate::~QScxmlScxmlServicePrivate() +QScxmlScxmlService::~QScxmlScxmlService() { delete stateMachine; } QScxmlScxmlService::QScxmlScxmlService(QScxmlStateMachine *stateMachine, QScxmlStateMachine *parentStateMachine, - QObject *parent) - : QScxmlInvokableService(*(new QScxmlScxmlServicePrivate(stateMachine, parentStateMachine)), - parent) + QScxmlInvokableServiceFactory *factory) + : QScxmlInvokableService(parentStateMachine, factory), stateMachine(stateMachine) { QScxmlStateMachinePrivate::get(stateMachine)->m_parentStateMachine = parentStateMachine; } -bool QScxmlScxmlService::start(const QScxmlInvokableServiceFactory *factory) +bool QScxmlScxmlService::start() { - Q_D(QScxmlScxmlService); - qCDebug(qscxmlLog) << parentStateMachine() << "preparing to start" << d->stateMachine; + Q_D(QScxmlInvokableService); + qCDebug(qscxmlLog) << parentStateMachine() << "preparing to start" << stateMachine; + + const QScxmlInvokableServiceFactory *factory + = qobject_cast(parent()); + Q_ASSERT(factory); bool ok = false; auto id = d->calculateId(parentStateMachine(), factory->invokeInfo(), &ok); @@ -250,72 +242,83 @@ bool QScxmlScxmlService::start(const QScxmlInvokableServiceFactory *factory) if (!ok) return false; - QScxmlStateMachinePrivate::get(d->stateMachine)->m_sessionId = id; - d->stateMachine->setInitialValues(data); - if (d->stateMachine->init()) { - qCDebug(qscxmlLog) << parentStateMachine() << "starting" << d->stateMachine; - d->stateMachine->start(); + QScxmlStateMachinePrivate::get(stateMachine)->m_sessionId = id; + stateMachine->setInitialValues(data); + if (stateMachine->init()) { + qCDebug(qscxmlLog) << parentStateMachine() << "starting" << stateMachine; + stateMachine->start(); return true; } - qCDebug(qscxmlLog) << parentStateMachine() << "failed to start" << d->stateMachine; + qCDebug(qscxmlLog) << parentStateMachine() << "failed to start" << stateMachine; return false; } QString QScxmlScxmlService::id() const { - Q_D(const QScxmlScxmlService); - return d->stateMachine->sessionId(); + return stateMachine->sessionId(); } QString QScxmlScxmlService::name() const { - Q_D(const QScxmlScxmlService); - return d->stateMachine->name(); + return stateMachine->name(); } void QScxmlScxmlService::postEvent(QScxmlEvent *event) { - Q_D(QScxmlScxmlService); - QScxmlStateMachinePrivate::get(d->stateMachine)->postEvent(event); -} - -QScxmlStateMachine *QScxmlScxmlService::stateMachine() const -{ - Q_D(const QScxmlScxmlService); - return d->stateMachine; -} - -QScxmlScxmlServiceFactory::QScxmlScxmlServiceFactory( - const QScxmlExecutableContent::InvokeInfo &invokeInfo, - const QVector &names, - const QVector ¶meters) - : QScxmlInvokableServiceFactory(invokeInfo, names, parameters) -{} - -QScxmlScxmlService *QScxmlScxmlServiceFactory::invokeStatic(QScxmlStateMachine *childStateMachine, - QScxmlStateMachine *parentStateMachine) -{ - QScxmlStateMachinePrivate::get(childStateMachine)->setIsInvoked(true); - return new QScxmlScxmlService(childStateMachine, parentStateMachine); + QScxmlStateMachinePrivate::get(stateMachine)->postEvent(event); } QScxmlDynamicScxmlServiceFactory::QScxmlDynamicScxmlServiceFactory( const QScxmlExecutableContent::InvokeInfo &invokeInfo, const QVector &names, - const QVector ¶meters) - : QScxmlScxmlServiceFactory(invokeInfo, names, parameters) + const QVector ¶meters, + QObject *parent) + : QScxmlInvokableServiceFactory(invokeInfo, names, parameters, parent) {} QScxmlInvokableService *QScxmlDynamicScxmlServiceFactory::invoke( QScxmlStateMachine *parentStateMachine) { bool ok = true; - auto srcexpr = d->calculateSrcexpr(parentStateMachine, &ok); + auto srcexpr = calculateSrcexpr(parentStateMachine, invokeInfo().expr, &ok); if (!ok) return Q_NULLPTR; - return invokeDynamic(parentStateMachine, srcexpr); + return invokeDynamicScxmlService(srcexpr, parentStateMachine, this); +} + +QScxmlStaticScxmlServiceFactory::QScxmlStaticScxmlServiceFactory( + const QMetaObject *metaObject, + const QScxmlExecutableContent::InvokeInfo &invokeInfo, + const QVector &nameList, + const QVector ¶meters, + QObject *parent) + : QScxmlInvokableServiceFactory(*(new QScxmlStaticScxmlServiceFactoryPrivate( + metaObject, invokeInfo, nameList, parameters)), parent) +{ +} + +QScxmlInvokableService *QScxmlStaticScxmlServiceFactory::invoke( + QScxmlStateMachine *parentStateMachine) +{ + Q_D(const QScxmlStaticScxmlServiceFactory); + QScxmlStateMachine *instance = qobject_cast( + d->metaObject->newInstance(Q_ARG(QObject *, this))); + return instance ? invokeStaticScxmlService(instance, parentStateMachine, this) : nullptr; +} + +QScxmlInvokableServiceFactory::QScxmlInvokableServiceFactory( + QScxmlInvokableServiceFactoryPrivate &dd, QObject *parent) + : QObject(dd, parent) +{} + +QScxmlScxmlService *invokeStaticScxmlService(QScxmlStateMachine *childStateMachine, + QScxmlStateMachine *parentStateMachine, + QScxmlInvokableServiceFactory *factory) +{ + QScxmlStateMachinePrivate::get(childStateMachine)->setIsInvoked(true); + return new QScxmlScxmlService(childStateMachine, parentStateMachine, factory); } QT_END_NAMESPACE diff --git a/src/scxml/qscxmlinvokableservice.h b/src/scxml/qscxmlinvokableservice.h index 9e317cc..63b9ec3 100644 --- a/src/scxml/qscxmlinvokableservice.h +++ b/src/scxml/qscxmlinvokableservice.h @@ -60,97 +60,66 @@ class Q_SCXML_EXPORT QScxmlInvokableService : public QObject public: QScxmlInvokableService(QScxmlStateMachine *parentStateMachine, - QObject *parent = nullptr); + QScxmlInvokableServiceFactory *parent); QScxmlStateMachine *parentStateMachine() const; - virtual bool start(const QScxmlInvokableServiceFactory *factory) = 0; + virtual bool start() = 0; virtual QString id() const = 0; virtual QString name() const = 0; virtual void postEvent(QScxmlEvent *event) = 0; - - void finalize(QScxmlExecutableContent::ContainerId finalize); - -protected: - QScxmlInvokableService(QScxmlInvokableServicePrivate &dd, QObject *parent = nullptr); }; class QScxmlInvokableServiceFactoryPrivate; -class Q_SCXML_EXPORT QScxmlInvokableServiceFactory +class Q_SCXML_EXPORT QScxmlInvokableServiceFactory : public QObject { + Q_OBJECT + Q_DECLARE_PRIVATE(QScxmlInvokableServiceFactory) + Q_PROPERTY(QScxmlExecutableContent::InvokeInfo invokeInfo READ invokeInfo CONSTANT) + Q_PROPERTY(QVector parameters READ parameters CONSTANT) + Q_PROPERTY(QVector names READ names CONSTANT) + public: QScxmlInvokableServiceFactory( const QScxmlExecutableContent::InvokeInfo &invokeInfo, const QVector &names, - const QVector ¶meters); - virtual ~QScxmlInvokableServiceFactory(); + const QVector ¶meters, + QObject *parent = nullptr); virtual QScxmlInvokableService *invoke(QScxmlStateMachine *parentStateMachine) = 0; - QScxmlExecutableContent::InvokeInfo invokeInfo() const; - QVector parameters() const; - QVector names() const; + const QScxmlExecutableContent::InvokeInfo &invokeInfo() const; + const QVector ¶meters() const; + const QVector &names() const; protected: - QScxmlInvokableServiceFactoryPrivate *d; + QScxmlInvokableServiceFactory(QScxmlInvokableServiceFactoryPrivate &dd, QObject *parent); }; -class QScxmlScxmlServicePrivate; -class Q_SCXML_EXPORT QScxmlScxmlService: public QScxmlInvokableService +class QScxmlStaticScxmlServiceFactoryPrivate; +class Q_SCXML_EXPORT QScxmlStaticScxmlServiceFactory: public QScxmlInvokableServiceFactory { Q_OBJECT - Q_DECLARE_PRIVATE(QScxmlScxmlService) - Q_PROPERTY(QScxmlStateMachine *stateMachine READ stateMachine CONSTANT) -public: - QScxmlScxmlService(QScxmlStateMachine *stateMachine, - QScxmlStateMachine *parentStateMachine, - QObject *parent = nullptr); - - bool start(const QScxmlInvokableServiceFactory *factory) Q_DECL_OVERRIDE; - QString id() const Q_DECL_OVERRIDE; - QString name() const Q_DECL_OVERRIDE; - void postEvent(QScxmlEvent *event) Q_DECL_OVERRIDE; - - QScxmlStateMachine *stateMachine() const; -}; - -class Q_SCXML_EXPORT QScxmlScxmlServiceFactory: public QScxmlInvokableServiceFactory -{ -public: - QScxmlScxmlServiceFactory(const QScxmlExecutableContent::InvokeInfo &invokeInfo, - const QVector &names, - const QVector ¶meters); - -protected: - QScxmlScxmlService *invokeDynamic(QScxmlStateMachine *parentStateMachine, - const QString &sourceUrl); - QScxmlScxmlService *invokeStatic(QScxmlStateMachine *childStateMachine, - QScxmlStateMachine *parentStateMachine); -}; - -template -class QScxmlStaticScxmlServiceFactory: public QScxmlScxmlServiceFactory -{ + Q_DECLARE_PRIVATE(QScxmlStaticScxmlServiceFactory) public: QScxmlStaticScxmlServiceFactory( - const QScxmlExecutableContent::InvokeInfo &newInvokeInfo, - const QVector &newNameList, - const QVector &newParameters) - : QScxmlScxmlServiceFactory(newInvokeInfo, newNameList, newParameters) - {} - - QScxmlInvokableService *invoke(QScxmlStateMachine *parentStateMachine) Q_DECL_OVERRIDE - { - return invokeStatic(new T, parentStateMachine); - } + const QMetaObject *metaObject, + const QScxmlExecutableContent::InvokeInfo &invokeInfo, + const QVector &nameList, + const QVector ¶meters, + QObject *parent = nullptr); + + QScxmlInvokableService *invoke(QScxmlStateMachine *parentStateMachine) Q_DECL_OVERRIDE; }; -class Q_SCXML_EXPORT QScxmlDynamicScxmlServiceFactory: public QScxmlScxmlServiceFactory +class Q_SCXML_EXPORT QScxmlDynamicScxmlServiceFactory: public QScxmlInvokableServiceFactory { + Q_OBJECT public: QScxmlDynamicScxmlServiceFactory( const QScxmlExecutableContent::InvokeInfo &invokeInfo, const QVector &names, - const QVector ¶meters); + const QVector ¶meters, + QObject *parent = nullptr); QScxmlInvokableService *invoke(QScxmlStateMachine *parentStateMachine) Q_DECL_OVERRIDE; }; diff --git a/src/scxml/qscxmlinvokableservice_p.h b/src/scxml/qscxmlinvokableservice_p.h index 52bd6d0..e2a9e7b 100644 --- a/src/scxml/qscxmlinvokableservice_p.h +++ b/src/scxml/qscxmlinvokableservice_p.h @@ -71,7 +71,7 @@ public: QScxmlStateMachine *parentStateMachine; }; -class QScxmlInvokableServiceFactoryPrivate +class QScxmlInvokableServiceFactoryPrivate : public QObjectPrivate { public: QScxmlInvokableServiceFactoryPrivate( @@ -79,23 +79,50 @@ public: const QVector &names, const QVector ¶meters); - QString calculateSrcexpr(QScxmlStateMachine *parent, bool *ok) const; - QScxmlExecutableContent::InvokeInfo invokeInfo; QVector names; QVector parameters; }; -class QScxmlScxmlServicePrivate : public QScxmlInvokableServicePrivate +class Q_SCXML_EXPORT QScxmlScxmlService: public QScxmlInvokableService { + Q_OBJECT + Q_DECLARE_PRIVATE(QScxmlInvokableService) public: - QScxmlScxmlServicePrivate(QScxmlStateMachine *stateMachine, - QScxmlStateMachine *parentStateMachine); - ~QScxmlScxmlServicePrivate(); + QScxmlScxmlService(QScxmlStateMachine *stateMachine, + QScxmlStateMachine *parentStateMachine, + QScxmlInvokableServiceFactory *parent); + ~QScxmlScxmlService(); + + bool start() Q_DECL_OVERRIDE; + QString id() const Q_DECL_OVERRIDE; + QString name() const Q_DECL_OVERRIDE; + void postEvent(QScxmlEvent *event) Q_DECL_OVERRIDE; QScxmlStateMachine *stateMachine; }; +class QScxmlStaticScxmlServiceFactoryPrivate : public QScxmlInvokableServiceFactoryPrivate +{ +public: + QScxmlStaticScxmlServiceFactoryPrivate( + const QMetaObject *metaObject, + const QScxmlExecutableContent::InvokeInfo &invokeInfo, + const QVector &names, + const QVector ¶meters); + + const QMetaObject *metaObject; +}; + +QScxmlScxmlService *invokeDynamicScxmlService(const QString &sourceUrl, + QScxmlStateMachine *parentStateMachine, + QScxmlInvokableServiceFactory *factory); +QScxmlScxmlService *invokeStaticScxmlService(QScxmlStateMachine *childStateMachine, + QScxmlStateMachine *parentStateMachine, + QScxmlInvokableServiceFactory *factory); +QString calculateSrcexpr(QScxmlStateMachine *parent, QScxmlExecutableContent::EvaluatorId srcexpr, + bool *ok); + QT_END_NAMESPACE #endif // QSCXMLINVOKABLESERVICE_P_H diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp index cfa37de..1397b71 100644 --- a/src/scxml/qscxmlstatemachine.cpp +++ b/src/scxml/qscxmlstatemachine.cpp @@ -449,7 +449,7 @@ void QScxmlStateMachinePrivate::addService(int invokingState) continue; // service failed to start const QString serviceName = service->name(); m_invokedServices[size_t(id)] = { invokingState, service, serviceName }; - service->start(factory); + service->start(); } emitInvokedServicesChanged(); } @@ -533,7 +533,16 @@ void QScxmlStateMachinePrivate::postEvent(QScxmlEvent *event) auto factory = serviceFactory(id); if (event->invokeId() == service->id()) { setEvent(event); - service->finalize(factory->invokeInfo().finalize); + + const QScxmlExecutableContent::ContainerId finalize + = factory->invokeInfo().finalize; + if (finalize != QScxmlExecutableContent::NoContainer) { + auto psm = service->parentStateMachine(); + qCDebug(qscxmlLog) << psm << "running finalize on event"; + auto smp = QScxmlStateMachinePrivate::get(psm); + smp->m_executionEngine->execute(finalize); + } + resetEvent(); } if (factory->invokeInfo().autoforward) { diff --git a/tools/qscxmlc/decl.t b/tools/qscxmlc/decl.t index 7c27f1d..09d6f72 100644 --- a/tools/qscxmlc/decl.t +++ b/tools/qscxmlc/decl.t @@ -6,7 +6,7 @@ public: ${properties} public: - ${classname}(QObject *parent = 0); + Q_INVOKABLE ${classname}(QObject *parent = 0); ~${classname}(); private: diff --git a/tools/qscxmlc/scxmlcppdumper.cpp b/tools/qscxmlc/scxmlcppdumper.cpp index 53988cf..aa207bb 100644 --- a/tools/qscxmlc/scxmlcppdumper.cpp +++ b/tools/qscxmlc/scxmlcppdumper.cpp @@ -387,7 +387,7 @@ int createFactoryId(QStringList &factories, const QString &className, QString line = QStringLiteral("case %1: return new ").arg(QString::number(idx)); if (invokeInfo.expr == QScxmlExecutableContent::NoInstruction) { - line += QStringLiteral("QScxmlStaticScxmlServiceFactory< %1::%2 >(") + line += QStringLiteral("QScxmlStaticScxmlServiceFactory(&%1::%2::staticMetaObject,") .arg(namespacePrefix, className); } else { line += QStringLiteral("QScxmlDynamicScxmlServiceFactory("); @@ -729,6 +729,20 @@ QString CppDumper::generateMetaObject(const QString &className, classDef.qualified = classDef.classname; classDef.superclassList << qMakePair(QByteArray("QScxmlStateMachine"), FunctionDef::Public); classDef.hasQObject = true; + FunctionDef constructor; + constructor.name = className.toUtf8(); + constructor.access = FunctionDef::Public; + constructor.isInvokable = true; + constructor.isConstructor = true; + + ArgumentDef arg; + arg.type.name = "QObject *"; + arg.type.rawName = arg.type.name; + arg.normalizedType = arg.type.name; + arg.name = "parent"; + arg.typeNameForCast = arg.type.name + "*"; + constructor.arguments.append(arg); + classDef.constructorList.append(constructor); // stateNames: int stateIdx = 0; -- cgit v1.2.3 From 20f1f1b1a027dfe5dcdd91d25590095e99eb2bf3 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 29 Nov 2016 10:11:23 +0100 Subject: Drop some empty destructors We don't need to expose explicit destructors when inheriting from QObject. Change-Id: I2c9e7b075cab9b8b44be10045aeddd3c1cfb89b7 Reviewed-by: Erik Verbruggen --- src/scxml/qscxmlcppdatamodel.cpp | 5 ----- src/scxml/qscxmlcppdatamodel.h | 1 - src/scxml/qscxmldatamodel.cpp | 5 ----- src/scxml/qscxmldatamodel.h | 1 - 4 files changed, 12 deletions(-) diff --git a/src/scxml/qscxmlcppdatamodel.cpp b/src/scxml/qscxmlcppdatamodel.cpp index 0c20381..69f0fbd 100644 --- a/src/scxml/qscxmlcppdatamodel.cpp +++ b/src/scxml/qscxmlcppdatamodel.cpp @@ -134,11 +134,6 @@ QScxmlCppDataModel::QScxmlCppDataModel(QObject *parent) : QScxmlDataModel(*(new QScxmlCppDataModelPrivate), parent) {} -/*! \internal */ -QScxmlCppDataModel::~QScxmlCppDataModel() -{ -} - /*! * Called during state machine initialization to set up a state machine using the initial values * for data model variables specified by their keys, \a initialDataValues. These diff --git a/src/scxml/qscxmlcppdatamodel.h b/src/scxml/qscxmlcppdatamodel.h index 97ca636..04607f2 100644 --- a/src/scxml/qscxmlcppdatamodel.h +++ b/src/scxml/qscxmlcppdatamodel.h @@ -59,7 +59,6 @@ class Q_SCXML_EXPORT QScxmlCppDataModel: public QScxmlDataModel Q_DECLARE_PRIVATE(QScxmlCppDataModel) public: explicit QScxmlCppDataModel(QObject *parent = nullptr); - ~QScxmlCppDataModel(); Q_INVOKABLE bool setup(const QVariantMap &initialDataValues) Q_DECL_OVERRIDE; diff --git a/src/scxml/qscxmldatamodel.cpp b/src/scxml/qscxmldatamodel.cpp index 9762e92..6e6d62b 100644 --- a/src/scxml/qscxmldatamodel.cpp +++ b/src/scxml/qscxmldatamodel.cpp @@ -96,11 +96,6 @@ QScxmlDataModel::QScxmlDataModel(QScxmlDataModelPrivate &dd, QObject *parent) : { } -/*! \internal */ -QScxmlDataModel::~QScxmlDataModel() -{ -} - /*! * Sets the state machine this model belongs to to \a stateMachine. There is a * 1:1 relation between state machines and models. After setting the state diff --git a/src/scxml/qscxmldatamodel.h b/src/scxml/qscxmldatamodel.h index 9f2b921..e1a575a 100644 --- a/src/scxml/qscxmldatamodel.h +++ b/src/scxml/qscxmldatamodel.h @@ -69,7 +69,6 @@ public: public: explicit QScxmlDataModel(QObject *parent = nullptr); - ~QScxmlDataModel(); void setStateMachine(QScxmlStateMachine *stateMachine); QScxmlStateMachine *stateMachine() const; -- cgit v1.2.3 From fd91566ac98e300725a161de40a4feba427e1fa8 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 29 Nov 2016 11:46:30 +0100 Subject: Fix header guards They should reflect the file name. Change-Id: I4f1ba1b98b673cfcb9ccacc8d83a42e06b1f2a3d Reviewed-by: Jarek Kobus --- src/scxml/qscxmlcppdatamodel.h | 6 +++--- src/scxml/qscxmlcppdatamodel_p.h | 6 +++--- src/scxml/qscxmldatamodel.h | 6 +++--- src/scxml/qscxmlecmascriptdatamodel.h | 6 +++--- src/scxml/qscxmlecmascriptplatformproperties_p.h | 6 +++--- src/scxml/qscxmlevent.h | 6 +++--- src/scxml/qscxmlevent_p.h | 6 +++--- src/scxml/qscxmlexecutablecontent.h | 6 +++--- src/scxml/qscxmlexecutablecontent_p.h | 6 +++--- src/scxml/qscxmlglobals.h | 6 +++--- src/scxml/qscxmlglobals_p.h | 6 +++--- src/scxml/qscxmlnulldatamodel.h | 6 +++--- src/scxml/qscxmlstatemachine.h | 6 +++--- src/scxml/qscxmlstatemachine_p.h | 6 +++--- tools/qscxmlc/scxmlcppdumper.h | 6 +++--- 15 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/scxml/qscxmlcppdatamodel.h b/src/scxml/qscxmlcppdatamodel.h index 04607f2..5de8f14 100644 --- a/src/scxml/qscxmlcppdatamodel.h +++ b/src/scxml/qscxmlcppdatamodel.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef CPPDATAMODEL_H -#define CPPDATAMODEL_H +#ifndef QSCXMLCPPDATAMODEL_H +#define QSCXMLCPPDATAMODEL_H #include @@ -80,4 +80,4 @@ public: QT_END_NAMESPACE -#endif // CPPDATAMODEL_H +#endif // QSCXMLCPPDATAMODEL_H diff --git a/src/scxml/qscxmlcppdatamodel_p.h b/src/scxml/qscxmlcppdatamodel_p.h index 1712a73..b342e39 100644 --- a/src/scxml/qscxmlcppdatamodel_p.h +++ b/src/scxml/qscxmlcppdatamodel_p.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef CPPDATAMODEL_P_H -#define CPPDATAMODEL_P_H +#ifndef QSCXMLCPPDATAMODEL_P_H +#define QSCXMLCPPDATAMODEL_P_H // // W A R N I N G @@ -65,4 +65,4 @@ public: QT_END_NAMESPACE -#endif // CPPDATAMODEL_P_H +#endif // QSCXMLCPPDATAMODEL_P_H diff --git a/src/scxml/qscxmldatamodel.h b/src/scxml/qscxmldatamodel.h index e1a575a..3d19685 100644 --- a/src/scxml/qscxmldatamodel.h +++ b/src/scxml/qscxmldatamodel.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef DATAMODEL_H -#define DATAMODEL_H +#ifndef QSCXMLDATAMODEL_H +#define QSCXMLDATAMODEL_H #include @@ -103,4 +103,4 @@ protected: QT_END_NAMESPACE -#endif // DATAMODEL_H +#endif // QSCXMLDATAMODEL_H diff --git a/src/scxml/qscxmlecmascriptdatamodel.h b/src/scxml/qscxmlecmascriptdatamodel.h index 808830a..19b96dd 100644 --- a/src/scxml/qscxmlecmascriptdatamodel.h +++ b/src/scxml/qscxmlecmascriptdatamodel.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef ECMASCRIPTDATAMODEL_H -#define ECMASCRIPTDATAMODEL_H +#ifndef QSCXMLECMASCRIPTDATAMODEL_H +#define QSCXMLECMASCRIPTDATAMODEL_H #include @@ -75,4 +75,4 @@ public: QT_END_NAMESPACE -#endif // ECMASCRIPTDATAMODEL_H +#endif // QSCXMLECMASCRIPTDATAMODEL_H diff --git a/src/scxml/qscxmlecmascriptplatformproperties_p.h b/src/scxml/qscxmlecmascriptplatformproperties_p.h index fef53ea..cf1c4a9 100644 --- a/src/scxml/qscxmlecmascriptplatformproperties_p.h +++ b/src/scxml/qscxmlecmascriptplatformproperties_p.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef ECMASCRIPTPLATFORMPROPERTIES_P_H -#define ECMASCRIPTPLATFORMPROPERTIES_P_H +#ifndef QSCXMLECMASCRIPTPLATFORMPROPERTIES_P_H +#define QSCXMLECMASCRIPTPLATFORMPROPERTIES_P_H // // W A R N I N G @@ -86,4 +86,4 @@ private: QT_END_NAMESPACE -#endif // ECMASCRIPTPLATFORMPROPERTIES_P_H +#endif // QSCXMLECMASCRIPTPLATFORMPROPERTIES_P_H diff --git a/src/scxml/qscxmlevent.h b/src/scxml/qscxmlevent.h index c4f517f..267f5ec 100644 --- a/src/scxml/qscxmlevent.h +++ b/src/scxml/qscxmlevent.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef SCXMLEVENT_H -#define SCXMLEVENT_H +#ifndef QSCXMLEVENT_H +#define QSCXMLEVENT_H #include @@ -119,4 +119,4 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QScxmlEvent) -#endif // SCXMLEVENT_H +#endif // QSCXMLEVENT_H diff --git a/src/scxml/qscxmlevent_p.h b/src/scxml/qscxmlevent_p.h index aef14d1..15bd6fa 100644 --- a/src/scxml/qscxmlevent_p.h +++ b/src/scxml/qscxmlevent_p.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef SCXMLEVENT_P_H -#define SCXMLEVENT_P_H +#ifndef QSCXMLEVENT_P_H +#define QSCXMLEVENT_P_H // // W A R N I N G @@ -177,5 +177,5 @@ public: QT_END_NAMESPACE -#endif // SCXMLEVENT_P_H +#endif // QSCXMLEVENT_P_H diff --git a/src/scxml/qscxmlexecutablecontent.h b/src/scxml/qscxmlexecutablecontent.h index cdf6b2b..8d2ef13 100644 --- a/src/scxml/qscxmlexecutablecontent.h +++ b/src/scxml/qscxmlexecutablecontent.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef EXECUTABLECONTENT_H -#define EXECUTABLECONTENT_H +#ifndef QSCXMLEXECUTABLECONTENT_H +#define QSCXMLEXECUTABLECONTENT_H #include @@ -99,4 +99,4 @@ struct InvokeInfo { QT_END_NAMESPACE -#endif // EXECUTABLECONTENT_H +#endif // QSCXMLEXECUTABLECONTENT_H diff --git a/src/scxml/qscxmlexecutablecontent_p.h b/src/scxml/qscxmlexecutablecontent_p.h index 4429686..98461fe 100644 --- a/src/scxml/qscxmlexecutablecontent_p.h +++ b/src/scxml/qscxmlexecutablecontent_p.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef EXECUTABLECONTENT_P_H -#define EXECUTABLECONTENT_P_H +#ifndef QSCXMLEXECUTABLECONTENT_P_H +#define QSCXMLEXECUTABLECONTENT_P_H // // W A R N I N G @@ -510,4 +510,4 @@ private: QT_END_NAMESPACE -#endif // EXECUTABLECONTENT_P_H +#endif // QSCXMLEXECUTABLECONTENT_P_H diff --git a/src/scxml/qscxmlglobals.h b/src/scxml/qscxmlglobals.h index d9bf7b5..8672aa1 100644 --- a/src/scxml/qscxmlglobals.h +++ b/src/scxml/qscxmlglobals.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef SCXMLGLOBALS_H -#define SCXMLGLOBALS_H +#ifndef QSCXMLGLOBALS_H +#define QSCXMLGLOBALS_H #include QT_BEGIN_NAMESPACE @@ -55,5 +55,5 @@ QT_BEGIN_NAMESPACE QT_END_NAMESPACE -#endif // SCXMLGLOBALS_H +#endif // QSCXMLGLOBALS_H diff --git a/src/scxml/qscxmlglobals_p.h b/src/scxml/qscxmlglobals_p.h index 48b3d73..559636b 100644 --- a/src/scxml/qscxmlglobals_p.h +++ b/src/scxml/qscxmlglobals_p.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef SCXMLGLOBALS_P_H -#define SCXMLGLOBALS_P_H +#ifndef QSCXMLGLOBALS_P_H +#define QSCXMLGLOBALS_P_H // // W A R N I N G @@ -62,4 +62,4 @@ Q_DECLARE_LOGGING_CATEGORY(scxmlLog) QT_END_NAMESPACE -#endif // SCXMLGLOBALS_P_H +#endif // QSCXMLGLOBALS_P_H diff --git a/src/scxml/qscxmlnulldatamodel.h b/src/scxml/qscxmlnulldatamodel.h index f5aeb26..098adcf 100644 --- a/src/scxml/qscxmlnulldatamodel.h +++ b/src/scxml/qscxmlnulldatamodel.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef NULLDATAMODEL_H -#define NULLDATAMODEL_H +#ifndef QSCXMLNULLDATAMODEL_H +#define QSCXMLNULLDATAMODEL_H #include @@ -74,4 +74,4 @@ public: QT_END_NAMESPACE -#endif // NULLDATAMODEL_H +#endif // QSCXMLNULLDATAMODEL_H diff --git a/src/scxml/qscxmlstatemachine.h b/src/scxml/qscxmlstatemachine.h index 2dea079..b5837db 100644 --- a/src/scxml/qscxmlstatemachine.h +++ b/src/scxml/qscxmlstatemachine.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef SCXMLSTATEMACHINE_H -#define SCXMLSTATEMACHINE_H +#ifndef QSCXMLSTATEMACHINE_H +#define QSCXMLSTATEMACHINE_H #include #include @@ -356,4 +356,4 @@ private: QT_END_NAMESPACE -#endif // SCXMLSTATEMACHINE_H +#endif // QSCXMLSTATEMACHINE_H diff --git a/src/scxml/qscxmlstatemachine_p.h b/src/scxml/qscxmlstatemachine_p.h index 69f3be4..bfa7bc1 100644 --- a/src/scxml/qscxmlstatemachine_p.h +++ b/src/scxml/qscxmlstatemachine_p.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef SCXMLSTATEMACHINE_P_H -#define SCXMLSTATEMACHINE_P_H +#ifndef QSCXMLSTATEMACHINE_P_H +#define QSCXMLSTATEMACHINE_P_H // // W A R N I N G @@ -383,5 +383,5 @@ private: QT_END_NAMESPACE -#endif // SCXMLSTATEMACHINE_P_H +#endif // QSCXMLSTATEMACHINE_P_H diff --git a/tools/qscxmlc/scxmlcppdumper.h b/tools/qscxmlc/scxmlcppdumper.h index 95fa48a..bd49cea 100644 --- a/tools/qscxmlc/scxmlcppdumper.h +++ b/tools/qscxmlc/scxmlcppdumper.h @@ -26,8 +26,8 @@ ** ****************************************************************************/ -#ifndef CPPDUMPER_H -#define CPPDUMPER_H +#ifndef SCXMLCPPDUMPER_H +#define SCXMLCPPDUMPER_H #include "qscxmlglobals.h" @@ -95,4 +95,4 @@ private: QT_END_NAMESPACE -#endif // CPPDUMPER_H +#endif // SCXMLCPPDUMPER_H -- cgit v1.2.3 From b4995157af050061e0d537cf393fcc1f14e5f3ef Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 29 Nov 2016 11:49:20 +0100 Subject: Drop empty QScxmlEcmaScriptDataModel destructor Change-Id: I6d7f4ef2215e8fe0b0547b71130a684139d55c0b Reviewed-by: Erik Verbruggen --- src/scxml/qscxmlecmascriptdatamodel.cpp | 5 ----- src/scxml/qscxmlecmascriptdatamodel.h | 1 - 2 files changed, 6 deletions(-) diff --git a/src/scxml/qscxmlecmascriptdatamodel.cpp b/src/scxml/qscxmlecmascriptdatamodel.cpp index 4b0329e..5532a9b 100644 --- a/src/scxml/qscxmlecmascriptdatamodel.cpp +++ b/src/scxml/qscxmlecmascriptdatamodel.cpp @@ -370,11 +370,6 @@ QScxmlEcmaScriptDataModel::QScxmlEcmaScriptDataModel(QObject *parent) : QScxmlDataModel(*(new QScxmlEcmaScriptDataModelPrivate), parent) {} -/*! \internal */ -QScxmlEcmaScriptDataModel::~QScxmlEcmaScriptDataModel() -{ -} - /*! \reimp */ diff --git a/src/scxml/qscxmlecmascriptdatamodel.h b/src/scxml/qscxmlecmascriptdatamodel.h index 19b96dd..81041c7 100644 --- a/src/scxml/qscxmlecmascriptdatamodel.h +++ b/src/scxml/qscxmlecmascriptdatamodel.h @@ -52,7 +52,6 @@ class Q_SCXML_EXPORT QScxmlEcmaScriptDataModel: public QScxmlDataModel Q_DECLARE_PRIVATE(QScxmlEcmaScriptDataModel) public: explicit QScxmlEcmaScriptDataModel(QObject *parent = nullptr); - ~QScxmlEcmaScriptDataModel(); Q_INVOKABLE bool setup(const QVariantMap &initialDataValues) Q_DECL_OVERRIDE; -- cgit v1.2.3 From b0a54c19641d14c0cb0b2f8eae4190bc7b27fa7c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 29 Nov 2016 10:12:44 +0100 Subject: Drop Q_UNREACHABLE() from C++ data model methods It's not illegal to do e.g. in your SCXML document without implementing the assign operation in your data model. The assignment will fail, setting the ok parameter to false. That should be enough. Q_UNREACHABLE() is unreliable anyway as it only triggers in debug builds. Change-Id: Ib29a20682d2c9256fcf59d29e32383c1df675eba Reviewed-by: Erik Verbruggen --- src/scxml/qscxmlcppdatamodel.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/scxml/qscxmlcppdatamodel.cpp b/src/scxml/qscxmlcppdatamodel.cpp index 69f0fbd..060c220 100644 --- a/src/scxml/qscxmlcppdatamodel.cpp +++ b/src/scxml/qscxmlcppdatamodel.cpp @@ -152,14 +152,12 @@ void QScxmlCppDataModel::evaluateAssignment(EvaluatorId id, bool *ok) { Q_UNUSED(id); *ok = false; - Q_UNREACHABLE(); } void QScxmlCppDataModel::evaluateInitialization(EvaluatorId id, bool *ok) { Q_UNUSED(id); *ok = false; - Q_UNREACHABLE(); } void QScxmlCppDataModel::evaluateForeach(EvaluatorId id, bool *ok, ForeachLoopBody *body) @@ -167,7 +165,6 @@ void QScxmlCppDataModel::evaluateForeach(EvaluatorId id, bool *ok, ForeachLoopBo Q_UNUSED(id); Q_UNUSED(body); *ok = false; - Q_UNREACHABLE(); } /*! @@ -225,7 +222,6 @@ bool QScxmlCppDataModel::setScxmlProperty(const QString &name, const QVariant &v Q_UNUSED(name); Q_UNUSED(value); Q_UNUSED(context); - Q_UNREACHABLE(); return false; } -- cgit v1.2.3 From a878c9714c8f51b4464ac9eb98165e47d20fd2f1 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 29 Nov 2016 11:47:03 +0100 Subject: Drop the final from methods of QScxmlCppDataModel There is no reason to prohibit the implementation of , and initialization. That will just make people resort to the base class instead of using the facilities offered by the C++ data model. Change-Id: Ic2c8d679a2c8f1c592cb3075c0b70c7cff80cd9c Reviewed-by: Erik Verbruggen --- src/scxml/qscxmlcppdatamodel.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/scxml/qscxmlcppdatamodel.h b/src/scxml/qscxmlcppdatamodel.h index 5de8f14..a491326 100644 --- a/src/scxml/qscxmlcppdatamodel.h +++ b/src/scxml/qscxmlcppdatamodel.h @@ -63,11 +63,10 @@ public: Q_INVOKABLE bool setup(const QVariantMap &initialDataValues) Q_DECL_OVERRIDE; #ifndef Q_QDOC - void evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; - void evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE Q_DECL_FINAL; - void evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) Q_DECL_OVERRIDE Q_DECL_FINAL; + void evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE; + void evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok) Q_DECL_OVERRIDE; + void evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body) Q_DECL_OVERRIDE; #endif // Q_QDOC - void setScxmlEvent(const QScxmlEvent &scxmlEvent) Q_DECL_OVERRIDE Q_DECL_FINAL; const QScxmlEvent &scxmlEvent() const; -- cgit v1.2.3 From 7cb37856848f4ead8030d3aa660c1c244ccecdaa Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 29 Nov 2016 10:16:58 +0100 Subject: Drop indirect access to tableData from various data models As we need to access it from everywhere, we can as well make it a public property of the state machine. This saves us the tableData() method on QScxmlDataModel and some back and forth between d and q pointers. We can also drop the indirection for accessing the state machine in most cases, as that is just a public member of QScxmlDataModelPrivate. Change-Id: I4aa0cec7d4664aec7b1581de531cdb1554ca5342 Reviewed-by: Erik Verbruggen --- src/scxml/qscxmldatamodel.cpp | 5 --- src/scxml/qscxmldatamodel.h | 3 -- src/scxml/qscxmlecmascriptdatamodel.cpp | 38 +++++++++----------- src/scxml/qscxmlnulldatamodel.cpp | 6 ++-- src/scxml/qscxmlstatemachine.cpp | 61 +++++++++++++++++---------------- src/scxml/qscxmlstatemachine.h | 7 ++-- 6 files changed, 55 insertions(+), 65 deletions(-) diff --git a/src/scxml/qscxmldatamodel.cpp b/src/scxml/qscxmldatamodel.cpp index 6e6d62b..570289d 100644 --- a/src/scxml/qscxmldatamodel.cpp +++ b/src/scxml/qscxmldatamodel.cpp @@ -123,11 +123,6 @@ QScxmlStateMachine *QScxmlDataModel::stateMachine() const return d->m_stateMachine; } -QScxmlTableData *QScxmlDataModel::tableData() const -{ - return stateMachine()->tableData(); -} - QScxmlDataModel *QScxmlDataModelPrivate::instantiateDataModel(DocumentModel::Scxml::DataModelType type) { QScxmlDataModel *dataModel = Q_NULLPTR; diff --git a/src/scxml/qscxmldatamodel.h b/src/scxml/qscxmldatamodel.h index 3d19685..e16f2f7 100644 --- a/src/scxml/qscxmldatamodel.h +++ b/src/scxml/qscxmldatamodel.h @@ -96,9 +96,6 @@ Q_SIGNALS: protected: explicit QScxmlDataModel(QScxmlDataModelPrivate &dd, QObject *parent = nullptr); -#ifndef Q_QDOC - QScxmlTableData *tableData() const; -#endif // Q_QDOC }; QT_END_NAMESPACE diff --git a/src/scxml/qscxmlecmascriptdatamodel.cpp b/src/scxml/qscxmlecmascriptdatamodel.cpp index 5532a9b..869afec 100644 --- a/src/scxml/qscxmlecmascriptdatamodel.cpp +++ b/src/scxml/qscxmlecmascriptdatamodel.cpp @@ -121,25 +121,26 @@ public: QJSEngine *engine = assertEngine(); dataModel = engine->globalObject(); - qCDebug(qscxmlLog) << stateMachine() << "initializing the datamodel"; + qCDebug(qscxmlLog) << m_stateMachine << "initializing the datamodel"; setupSystemVariables(); } void setupSystemVariables() { setReadonlyProperty(&dataModel, QStringLiteral("_sessionid"), - stateMachine()->sessionId()); + m_stateMachine->sessionId()); - setReadonlyProperty(&dataModel, QStringLiteral("_name"), stateMachine()->name()); + setReadonlyProperty(&dataModel, QStringLiteral("_name"), m_stateMachine->name()); QJSEngine *engine = assertEngine(); auto scxml = engine->newObject(); - scxml.setProperty(QStringLiteral("location"), QStringLiteral("#_scxml_%1").arg(stateMachine()->sessionId())); + scxml.setProperty(QStringLiteral("location"), QStringLiteral("#_scxml_%1") + .arg(m_stateMachine->sessionId())); auto ioProcs = engine->newObject(); setReadonlyProperty(&ioProcs, QStringLiteral("scxml"), scxml); setReadonlyProperty(&dataModel, QStringLiteral("_ioprocessors"), ioProcs); - auto platformVars = QScxmlPlatformProperties::create(engine, stateMachine()); + auto platformVars = QScxmlPlatformProperties::create(engine, m_stateMachine); dataModel.setProperty(QStringLiteral("_x"), platformVars->jsValue()); dataModel.setProperty(QStringLiteral("In"), engine->evaluate( @@ -204,12 +205,6 @@ public: return engine->toScriptValue(data); } - QScxmlStateMachine *stateMachine() const - { - Q_Q(const QScxmlEcmaScriptDataModel); - return q->stateMachine(); - } - QJSEngine *assertEngine() { if (!jsEngine) { @@ -230,8 +225,7 @@ public: QString string(StringId id) const { - Q_Q(const QScxmlEcmaScriptDataModel); - return q->tableData()->string(id); + return m_stateMachine->tableData()->string(id); } bool hasProperty(const QString &name) const @@ -265,7 +259,7 @@ public: void submitError(const QString &type, const QString &msg, const QString &sendid = QString()) { - QScxmlStateMachinePrivate::get(stateMachine())->submitError(type, msg, sendid); + QScxmlStateMachinePrivate::get(m_stateMachine)->submitError(type, msg, sendid); } public: @@ -381,7 +375,7 @@ bool QScxmlEcmaScriptDataModel::setup(const QVariantMap &initialDataValues) bool ok = true; QJSValue undefined(QJSValue::UndefinedValue); // See B.2.1, and test456. int count; - StringId *names = tableData()->dataNames(&count); + StringId *names = d->m_stateMachine->tableData()->dataNames(&count); for (int i = 0; i < count; ++i) { auto name = d->string(names[i]); QJSValue v = undefined; @@ -402,7 +396,7 @@ bool QScxmlEcmaScriptDataModel::setup(const QVariantMap &initialDataValues) QString QScxmlEcmaScriptDataModel::evaluateToString(EvaluatorId id, bool *ok) { Q_D(QScxmlEcmaScriptDataModel); - const EvaluatorInfo &info = tableData()->evaluatorInfo(id); + const EvaluatorInfo &info = d->m_stateMachine->tableData()->evaluatorInfo(id); return d->evalStr(d->string(info.expr), d->string(info.context), ok); } @@ -410,7 +404,7 @@ QString QScxmlEcmaScriptDataModel::evaluateToString(EvaluatorId id, bool *ok) bool QScxmlEcmaScriptDataModel::evaluateToBool(EvaluatorId id, bool *ok) { Q_D(QScxmlEcmaScriptDataModel); - const EvaluatorInfo &info = tableData()->evaluatorInfo(id); + const EvaluatorInfo &info = d->m_stateMachine->tableData()->evaluatorInfo(id); return d->evalBool(d->string(info.expr), d->string(info.context), ok); } @@ -418,7 +412,7 @@ bool QScxmlEcmaScriptDataModel::evaluateToBool(EvaluatorId id, bool *ok) QVariant QScxmlEcmaScriptDataModel::evaluateToVariant(EvaluatorId id, bool *ok) { Q_D(QScxmlEcmaScriptDataModel); - const EvaluatorInfo &info = tableData()->evaluatorInfo(id); + const EvaluatorInfo &info = d->m_stateMachine->tableData()->evaluatorInfo(id); return d->evalJSValue(d->string(info.expr), d->string(info.context), ok).toVariant(); } @@ -426,7 +420,7 @@ QVariant QScxmlEcmaScriptDataModel::evaluateToVariant(EvaluatorId id, bool *ok) void QScxmlEcmaScriptDataModel::evaluateToVoid(EvaluatorId id, bool *ok) { Q_D(QScxmlEcmaScriptDataModel); - const EvaluatorInfo &info = tableData()->evaluatorInfo(id); + const EvaluatorInfo &info = d->m_stateMachine->tableData()->evaluatorInfo(id); d->eval(d->string(info.expr), d->string(info.context), ok); } @@ -436,7 +430,7 @@ void QScxmlEcmaScriptDataModel::evaluateAssignment(EvaluatorId id, bool *ok) Q_D(QScxmlEcmaScriptDataModel); Q_ASSERT(ok); - const AssignmentInfo &info = tableData()->assignmentInfo(id); + const AssignmentInfo &info = d->m_stateMachine->tableData()->assignmentInfo(id); QString dest = d->string(info.dest); @@ -454,7 +448,7 @@ void QScxmlEcmaScriptDataModel::evaluateAssignment(EvaluatorId id, bool *ok) void QScxmlEcmaScriptDataModel::evaluateInitialization(EvaluatorId id, bool *ok) { Q_D(QScxmlEcmaScriptDataModel); - const AssignmentInfo &info = tableData()->assignmentInfo(id); + const AssignmentInfo &info = d->m_stateMachine->tableData()->assignmentInfo(id); QString dest = d->string(info.dest); if (d->initialDataNames.contains(dest)) { *ok = true; // silently ignore the tag @@ -469,7 +463,7 @@ void QScxmlEcmaScriptDataModel::evaluateForeach(EvaluatorId id, bool *ok, Foreac Q_D(QScxmlEcmaScriptDataModel); Q_ASSERT(ok); Q_ASSERT(body); - const ForeachInfo &info = tableData()->foreachInfo(id); + const ForeachInfo &info = d->m_stateMachine->tableData()->foreachInfo(id); QJSValue jsArray = d->property(d->string(info.array)); if (!jsArray.isArray()) { diff --git a/src/scxml/qscxmlnulldatamodel.cpp b/src/scxml/qscxmlnulldatamodel.cpp index 35f1b91..d7b64d0 100644 --- a/src/scxml/qscxmlnulldatamodel.cpp +++ b/src/scxml/qscxmlnulldatamodel.cpp @@ -84,8 +84,7 @@ public: ResolvedEvaluatorInfo prepare(QScxmlExecutableContent::EvaluatorId id) { - Q_Q(QScxmlNullDataModel); - auto td = q->tableData(); + auto td = m_stateMachine->tableData(); const QScxmlExecutableContent::EvaluatorInfo &info = td->evaluatorInfo(id); QString expr = td->string(info.expr); for (int i = 0; i < expr.size(); ) { @@ -152,10 +151,11 @@ bool QScxmlNullDataModel::setup(const QVariantMap &initialDataValues) QString QScxmlNullDataModel::evaluateToString(QScxmlExecutableContent::EvaluatorId id, bool *ok) { + Q_D(QScxmlNullDataModel); // We do implement this, because is allowed in the Null data model, // and has an expr attribute that needs "evaluation" for it to generate the log message. *ok = true; - auto td = tableData(); + auto td = d->m_stateMachine->tableData(); const QScxmlExecutableContent::EvaluatorInfo &info = td->evaluatorInfo(id); return td->string(info.expr); } diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp index 1397b71..d71755b 100644 --- a/src/scxml/qscxmlstatemachine.cpp +++ b/src/scxml/qscxmlstatemachine.cpp @@ -1541,6 +1541,14 @@ QScxmlStateMachine::QScxmlStateMachine(QScxmlStateMachinePrivate &dd, QObject *p \brief The loader that is currently used to resolve and load URIs for the state machine. */ +/*! + \property QScxmlStateMachine::tableData + + This is used when generating C++ from an SCXML file. The class implementing + the state machine will use this property to assign the generated table + data. The state machine does not assume ownership of the table data. + */ + QString QScxmlStateMachine::sessionId() const { Q_D(const QScxmlStateMachine); @@ -1611,13 +1619,6 @@ QScxmlCompiler::Loader *QScxmlStateMachine::loader() const return d->m_loader; } -/*! - * \internal - * - * This is used internally in order to execute the executable content. - * - * \return the data tables used by the state machine. - */ QScxmlTableData *QScxmlStateMachine::tableData() const { Q_D(const QScxmlStateMachine); @@ -1625,36 +1626,36 @@ QScxmlTableData *QScxmlStateMachine::tableData() const return d->m_tableData; } -/*! - * \internal - * This is used when generating C++ from an SCXML file. The class implementing the - * state machine will use this method to pass in the table data (which is also generated). - * - * \return the data tables used by the state machine. - */ void QScxmlStateMachine::setTableData(QScxmlTableData *tableData) { Q_D(QScxmlStateMachine); - Q_ASSERT(tableData); + + if (d->m_tableData == tableData) + return; d->m_tableData = tableData; - d->m_stateTable = reinterpret_cast( - tableData->stateMachineTable()); - if (objectName().isEmpty()) { - setObjectName(tableData->name()); - } - if (d->m_stateTable->maxServiceId != QScxmlExecutableContent::StateTable::InvalidIndex) { - const size_t serviceCount = size_t(d->m_stateTable->maxServiceId + 1); - d->m_invokedServices.resize(serviceCount, { -1, nullptr, QString() }); - d->m_cachedFactories.resize(serviceCount, nullptr); + if (tableData) { + d->m_stateTable = reinterpret_cast( + tableData->stateMachineTable()); + if (objectName().isEmpty()) { + setObjectName(tableData->name()); + } + if (d->m_stateTable->maxServiceId != QScxmlExecutableContent::StateTable::InvalidIndex) { + const size_t serviceCount = size_t(d->m_stateTable->maxServiceId + 1); + d->m_invokedServices.resize(serviceCount, { -1, nullptr, QString() }); + d->m_cachedFactories.resize(serviceCount, nullptr); + } + + if (d->m_stateTable->version != Q_QSCXMLC_OUTPUT_REVISION) { + qFatal("Cannot mix incompatible state table (version 0x%x) with this library " + "(version 0x%x)", d->m_stateTable->version, Q_QSCXMLC_OUTPUT_REVISION); + } + Q_ASSERT(tableData->stateMachineTable()[d->m_stateTable->arrayOffset + + d->m_stateTable->arraySize] + == QScxmlExecutableContent::StateTable::terminator); } - if (d->m_stateTable->version != Q_QSCXMLC_OUTPUT_REVISION) - qFatal("Cannot mix incompatible state table (version 0x%x) with this library (version 0x%x)", - d->m_stateTable->version, Q_QSCXMLC_OUTPUT_REVISION); - Q_ASSERT(tableData->stateMachineTable()[d->m_stateTable->arrayOffset + - d->m_stateTable->arraySize] - == QScxmlExecutableContent::StateTable::terminator); + emit tableDataChanged(tableData); } /*! diff --git a/src/scxml/qscxmlstatemachine.h b/src/scxml/qscxmlstatemachine.h index b5837db..da8de50 100644 --- a/src/scxml/qscxmlstatemachine.h +++ b/src/scxml/qscxmlstatemachine.h @@ -75,6 +75,7 @@ class Q_SCXML_EXPORT QScxmlStateMachine: public QObject Q_PROPERTY(bool invoked READ isInvoked CONSTANT) Q_PROPERTY(QVector parseErrors READ parseErrors CONSTANT) Q_PROPERTY(QScxmlCompiler::Loader *loader READ loader WRITE setLoader NOTIFY loaderChanged) + Q_PROPERTY(QScxmlTableData *tableData READ tableData WRITE setTableData NOTIFY tableDataChanged) protected: #ifndef Q_QDOC @@ -314,6 +315,9 @@ public: QVector invokedServices() const; + QScxmlTableData *tableData() const; + void setTableData(QScxmlTableData *tableData); + Q_SIGNALS: void runningChanged(bool running); void invokedServicesChanged(const QVector &invokedServices); @@ -324,6 +328,7 @@ Q_SIGNALS: void initialValuesChanged(const QVariantMap &initialValues); void initializedChanged(bool initialized); void loaderChanged(QScxmlCompiler::Loader *loader); + void tableDataChanged(QScxmlTableData *tableData); public Q_SLOTS: void start(); @@ -339,8 +344,6 @@ protected: // methods for friends: #ifndef Q_QDOC // The methods below are used by the compiled state machines. bool isActive(int stateIndex) const; - QScxmlTableData *tableData() const; - void setTableData(QScxmlTableData *tableData); #endif // Q_QDOC private: -- cgit v1.2.3 From 15942fe84483ff6aabf1008f3edc153b9ff31b4d Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 21 Sep 2016 18:36:11 +0200 Subject: Add missing documentation Most of the methods marked as \internal or excluded via "#ifndef Q_QDOC" so far are not actually internal as they are called from compiled state machines. We have to document them. Change-Id: Ib80268ae00f536e9ac2d337b565dcafbbdc31dea Reviewed-by: Erik Verbruggen --- src/scxml/qscxmlcppdatamodel.cpp | 67 ++++++++++--- src/scxml/qscxmlcppdatamodel.h | 3 +- src/scxml/qscxmldatamodel.cpp | 75 +++++++++++++- src/scxml/qscxmldatamodel.h | 2 - src/scxml/qscxmlecmascriptdatamodel.cpp | 42 ++++++-- src/scxml/qscxmlecmascriptdatamodel.h | 2 - src/scxml/qscxmlexecutablecontent.cpp | 169 ++++++++++++++++++++++++++++++++ src/scxml/qscxmlexecutablecontent_p.h | 2 + src/scxml/qscxmlinvokableservice.cpp | 133 +++++++++++++++++++++++++ src/scxml/qscxmlnulldatamodel.cpp | 53 +++++++++- src/scxml/qscxmlnulldatamodel.h | 2 - src/scxml/qscxmlstatemachine.cpp | 25 +++-- src/scxml/qscxmlstatemachine.h | 4 - src/scxml/qscxmltabledata.cpp | 73 ++++++++++++++ 14 files changed, 602 insertions(+), 50 deletions(-) diff --git a/src/scxml/qscxmlcppdatamodel.cpp b/src/scxml/qscxmlcppdatamodel.cpp index 060c220..23a7392 100644 --- a/src/scxml/qscxmlcppdatamodel.cpp +++ b/src/scxml/qscxmlcppdatamodel.cpp @@ -52,7 +52,7 @@ using namespace QScxmlExecutableContent; \sa QScxmlStateMachine QScxmlDataModel - The C++ data model for SCXML that lets you write C++ code for \e expr attributes and \c