diff options
Diffstat (limited to 'src/uscxml')
-rw-r--r-- | src/uscxml/interpreter/BasicContentExecutor.cpp | 42 | ||||
-rw-r--r-- | src/uscxml/interpreter/ContentExecutorImpl.h | 1 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterImpl.h | 4 | ||||
-rw-r--r-- | src/uscxml/messages/Event.h | 8 | ||||
-rw-r--r-- | src/uscxml/plugins/DataModel.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/plugins/DataModel.h | 2 | ||||
-rw-r--r-- | src/uscxml/plugins/DataModelImpl.h | 6 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp | 127 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/lua/LuaDataModel.h | 1 | ||||
-rw-r--r-- | src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h | 1 |
10 files changed, 110 insertions, 86 deletions
diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 7ffda91..932d579 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -67,7 +67,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { sendEvent.name = ATTR(element, kXMLCharEvent); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element eventexpr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element eventexpr", element); } try { @@ -78,7 +78,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { target = ATTR(element, kXMLCharTarget); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element targetexpr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element targetexpr", element); } try { @@ -89,7 +89,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { type = ATTR(element, kXMLCharType); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element typeexpr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element typeexpr", element); } try { @@ -124,7 +124,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { } } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element idlocation", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element idlocation", element); } try { @@ -148,14 +148,14 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { } } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element delayexpr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element delayexpr", element); } try { // namelist processNameLists(sendEvent.namelist, element); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element namelist", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element namelist", element); } @@ -163,7 +163,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { // params processParams(sendEvent.params, element); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element param expr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element param expr", element); } try { @@ -173,7 +173,7 @@ void BasicContentExecutor::processSend(XERCESC_NS::DOMElement* element) { sendEvent.data = elementAsData(contents.front()); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element content", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element content", element); } // if (sendReq->dom) { @@ -431,14 +431,14 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { element->setUserData(kXMLCharInvokeId, (void*)invokeId, NULL); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in invoke element idlocation", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in invoke element idlocation", element); } try { // namelist processNameLists(invokeEvent.namelist, element); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element namelist", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element namelist", element); } @@ -446,7 +446,7 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { // params processParams(invokeEvent.params, element); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in send element param expr", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in send element param expr", element); } try { @@ -467,7 +467,7 @@ void BasicContentExecutor::invoke(XERCESC_NS::DOMElement* element) { #endif } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in invoke element content", element); + ERROR_EXECUTION_THROW3(e,"Syntax error in invoke element content", element); } // autoforward @@ -513,7 +513,7 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC // namelist processNameLists(doneEvent.namelist, doneData); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in donedata element namelist", doneData); + ERROR_EXECUTION_THROW3(e,"Syntax error in donedata element namelist", doneData); } @@ -521,7 +521,7 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC // params processParams(doneEvent.params, doneData); } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in donedata element param expr", doneData); + ERROR_EXECUTION_THROW3(e,"Syntax error in donedata element param expr", doneData); } try { @@ -531,7 +531,7 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC doneEvent.data = elementAsData(contents.front()); } } catch (Event e) { - ERROR_EXECUTION_THROW2("Syntax error in donedata element content", doneData); + ERROR_EXECUTION_THROW3(e,"Syntax error in donedata element content", doneData); } } catch (ErrorEvent exc) { @@ -691,9 +691,19 @@ Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element, bool a contentSS << X((*textIter)->getNodeValue()); } + // this must be handled in getAsData // test294, test562 if (LOCALNAME(element) == "content") { - return Data(spaceNormalize(contentSS.str()), Data::VERBATIM); + // need first try getAsData because how to pass 179 ? + try { + // test153, we need to throw for test150 in promela + Data d = _callbacks->getAsData(contentSS.str()); + if (!d.empty()) + return d; + } + catch (ErrorEvent &) { + return Data(spaceNormalize(contentSS.str()), Data::VERBATIM); + } } if (asExpression) // not actually used, but likely expected diff --git a/src/uscxml/interpreter/ContentExecutorImpl.h b/src/uscxml/interpreter/ContentExecutorImpl.h index 5f0acfe..fd6be89 100644 --- a/src/uscxml/interpreter/ContentExecutorImpl.h +++ b/src/uscxml/interpreter/ContentExecutorImpl.h @@ -59,6 +59,7 @@ public: uint32_t iteration) = 0; virtual Data evalAsData(const std::string& expr) = 0; + virtual void eval(const std::string& content) { evalAsData(expr); } virtual Data getAsData(const std::string& expr) = 0; virtual void assign(const std::string& location, const Data& data, const std::map<std::string, std::string>& attrs) = 0; diff --git a/src/uscxml/interpreter/InterpreterImpl.h b/src/uscxml/interpreter/InterpreterImpl.h index a68298b..fd6d393 100644 --- a/src/uscxml/interpreter/InterpreterImpl.h +++ b/src/uscxml/interpreter/InterpreterImpl.h @@ -187,6 +187,10 @@ public: return _dataModel.evalAsData(expr); } + virtual void eval(const std::string& content) { + _dataModel.eval(content); + } + virtual Data getAsData(const std::string& expr) { return _dataModel.getAsData(expr); } diff --git a/src/uscxml/messages/Event.h b/src/uscxml/messages/Event.h index b774f8a..fd9dd42 100644 --- a/src/uscxml/messages/Event.h +++ b/src/uscxml/messages/Event.h @@ -77,6 +77,14 @@ throw exc;\ } +#define ERROR_EXECUTION_THROW3(evt,caption,node) \ +{\ + auto it = evt.data.compound.find("cause"); \ + ERROR_EXECUTION2(exc,it!=evt.data.compound.end() ? it->second.atom : "",node); \ + exc.data.compound["caption"] = uscxml::Data(caption, uscxml::Data::VERBATIM); \ + throw exc;\ +} + #define ERROR_COMMUNICATION_THROW(cause) \ {\ ERROR_COMMUNICATION(exc, cause); \ diff --git a/src/uscxml/plugins/DataModel.cpp b/src/uscxml/plugins/DataModel.cpp index 07fd4b4..cf4dda2 100644 --- a/src/uscxml/plugins/DataModel.cpp +++ b/src/uscxml/plugins/DataModel.cpp @@ -42,6 +42,10 @@ Data DataModel::evalAsData(const std::string& content) { return _impl->evalAsData(content); } +void DataModel::eval(const std::string& content) { + _impl->eval(content); +} + bool DataModel::evalAsBool(const std::string& expr) { return _impl->evalAsBool(expr); } diff --git a/src/uscxml/plugins/DataModel.h b/src/uscxml/plugins/DataModel.h index 9185cc8..484f1cc 100644 --- a/src/uscxml/plugins/DataModel.h +++ b/src/uscxml/plugins/DataModel.h @@ -54,6 +54,8 @@ public: virtual Data getAsData(const std::string& content); /// @copydoc DataModelImpl::evalAsData() virtual Data evalAsData(const std::string& content); + /// @copydoc DataModelImpl::eval() + virtual void eval(const std::string& content); /// @copydoc DataModelImpl::evalAsBool() virtual bool evalAsBool(const std::string& expr); diff --git a/src/uscxml/plugins/DataModelImpl.h b/src/uscxml/plugins/DataModelImpl.h index a804ea3..62453a8 100644 --- a/src/uscxml/plugins/DataModelImpl.h +++ b/src/uscxml/plugins/DataModelImpl.h @@ -173,6 +173,12 @@ public: virtual Data evalAsData(const std::string& content) = 0; /** + * evaluating script content without return + * @param mostly used in script content. + */ + virtual void eval(const std::string& content) { evalAsData(content); } + + /** * Evaluate a given expression as a boolean. * This function is a subset of evalAsData() but saves on creating and copying a Data object. * @param expr An expression in the data-model's language. diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index 94d2467..ea90e8c 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -79,9 +79,12 @@ static int luaEval(lua_State* luaState, const std::string& expr) { static Data getLuaAsData(lua_State* _luaState, const luabridge::LuaRef& lua) { Data data; if (lua.isFunction()) { - // TODO: this might lead to a stack-overflow - luabridge::LuaRef luaEvald = lua(); - return getLuaAsData(_luaState, luaEvald); + // we are creating __tmpFunc + // then it will be assigned to data variable + luabridge::setGlobal(_luaState, lua, "__tmpFunc"); + + data.atom = "__tmpFunc"; + data.type = Data::INTERPRETED; } else if(lua.isLightUserdata() || lua.isUserdata()) { // not sure what to do } else if(lua.isThread()) { @@ -208,17 +211,24 @@ int LuaDataModel::luaInFunction(lua_State * l) { std::shared_ptr<DataModelImpl> LuaDataModel::create(DataModelCallbacks* callbacks) { std::shared_ptr<LuaDataModel> dm(new LuaDataModel()); - dm->_callbacks = callbacks; - dm->setup(); + + dm->doCreate(callbacks); + return dm; } -void LuaDataModel::setup() { - _luaState = luaL_newstate(); - luaL_openlibs(_luaState); +LuaDataModel::~LuaDataModel() { + if (_luaState != NULL) + lua_close(_luaState); +} + +void LuaDataModel::doCreate(DataModelCallbacks* callbacks) { + this->_callbacks = callbacks; + this->_luaState = luaL_newstate(); + luaL_openlibs(this->_luaState); try { - const luabridge::LuaRef& requireFunc = luabridge::getGlobal(_luaState, "require"); + const luabridge::LuaRef& requireFunc = luabridge::getGlobal(this->_luaState, "require"); if (requireFunc.isFunction()) { const luabridge::LuaRef& resultLxp = requireFunc("lxp"); const luabridge::LuaRef& resultLxpLOM = requireFunc("lxp.lom"); @@ -226,47 +236,42 @@ void LuaDataModel::setup() { // MSVC compiler bug with implicit cast operators, see comments in LuaRef class if ((bool)resultLxp && (bool)resultLxpLOM) { _luaHasXMLParser = true; - luabridge::setGlobal(_luaState, resultLxp, "lxp"); - luabridge::setGlobal(_luaState, resultLxpLOM, "lxp.lom"); + luabridge::setGlobal(this->_luaState, resultLxp, "lxp"); + luabridge::setGlobal(this->_luaState, resultLxpLOM, "lxp.lom"); } } - } catch (luabridge::LuaException e) { - LOG(_callbacks->getLogger(), USCXML_INFO) << e.what() << std::endl; + } + catch (luabridge::LuaException e) { + LOG(this->_callbacks->getLogger(), USCXML_INFO) << e.what() << std::endl; } - luabridge::getGlobalNamespace(_luaState).beginClass<LuaDataModel>("DataModel").endClass(); - luabridge::setGlobal(_luaState, this, "__datamodel"); + luabridge::getGlobalNamespace(this->_luaState).beginClass<LuaDataModel>("DataModel").endClass(); + luabridge::setGlobal(this->_luaState, this, "__datamodel"); - luabridge::getGlobalNamespace(_luaState).addCFunction("In", luaInFunction); + luabridge::getGlobalNamespace(this->_luaState).addCFunction("In", luaInFunction); - luabridge::LuaRef ioProcTable = luabridge::newTable(_luaState); - std::map<std::string, IOProcessor> ioProcs = _callbacks->getIOProcessors(); + luabridge::LuaRef ioProcTable = luabridge::newTable(this->_luaState); + std::map<std::string, IOProcessor> ioProcs = this->_callbacks->getIOProcessors(); std::map<std::string, IOProcessor>::const_iterator ioProcIter = ioProcs.begin(); - while(ioProcIter != ioProcs.end()) { + while (ioProcIter != ioProcs.end()) { Data ioProcData = ioProcIter->second.getDataModelVariables(); - ioProcTable[ioProcIter->first] = getDataAsLua(_luaState, ioProcData); + ioProcTable[ioProcIter->first] = getDataAsLua(this->_luaState, ioProcData); ioProcIter++; } - luabridge::setGlobal(_luaState, ioProcTable, "_ioprocessors"); + luabridge::setGlobal(this->_luaState, ioProcTable, "_ioprocessors"); - luabridge::LuaRef invTable = luabridge::newTable(_luaState); - std::map<std::string, Invoker> invokers = _callbacks->getInvokers(); + luabridge::LuaRef invTable = luabridge::newTable(this->_luaState); + std::map<std::string, Invoker> invokers = this->_callbacks->getInvokers(); std::map<std::string, Invoker>::const_iterator invIter = invokers.begin(); - while(invIter != invokers.end()) { + while (invIter != invokers.end()) { Data invData = invIter->second.getDataModelVariables(); - invTable[invIter->first] = getDataAsLua(_luaState, invData); + invTable[invIter->first] = getDataAsLua(this->_luaState, invData); invIter++; } - luabridge::setGlobal(_luaState, invTable, "_invokers"); - - luabridge::setGlobal(_luaState, _callbacks->getName(), "_name"); - luabridge::setGlobal(_luaState, _callbacks->getSessionId(), "_sessionid"); - -} + luabridge::setGlobal(this->_luaState, invTable, "_invokers"); -LuaDataModel::~LuaDataModel() { - if (_luaState != NULL) - lua_close(_luaState); + luabridge::setGlobal(this->_luaState, this->_callbacks->getName(), "_name"); + luabridge::setGlobal(this->_luaState, this->_callbacks->getSessionId(), "_sessionid"); } void LuaDataModel::addExtension(DataModelExtension* ext) { @@ -353,49 +358,25 @@ void LuaDataModel::setEvent(const Event& event) { Data LuaDataModel::evalAsData(const std::string& content) { Data data; - ErrorEvent originalError; std::string trimmedExpr = boost::trim_copy(content); - try { - int retVals = luaEval(_luaState, "return(" + trimmedExpr + ")"); - if (retVals == 1) { - data = getLuaAsData(_luaState, luabridge::LuaRef::fromStack(_luaState, -1)); - } - lua_pop(_luaState, retVals); - return data; - } catch (ErrorEvent e) { - originalError = e; - } - - int retVals = 0; - try { - // evaluate again without the return() - retVals = luaEval(_luaState, trimmedExpr); - } catch (ErrorEvent e) { - throw originalError; // we will assume syntax error and throw - } - -#if 1 - // Note: Empty result is not an error test302, but how to do test488? - if (retVals == 0 && !isValidSyntax(trimmedExpr)) { - throw originalError; // we will assume syntax error and throw + int retVals = luaEval(_luaState, "return(" + trimmedExpr + ")"); + if (retVals == 1) { + data = getLuaAsData(_luaState, luabridge::LuaRef::fromStack(_luaState, -1)); } -#endif + lua_pop(_luaState, retVals); + return data; +} - try { - if (retVals == 1) { - data = getLuaAsData(_luaState, luabridge::LuaRef::fromStack(_luaState, -1)); - } - lua_pop(_luaState, retVals); - return data; +void LuaDataModel::evalAsScript(const std::string& content) { + Data data; - } catch (ErrorEvent e) { - throw e; // we will assume syntax error and throw - } + std::string trimmedExpr = boost::trim_copy(content); + int retVals = luaEval(_luaState, trimmedExpr); - return data; + lua_pop(_luaState, retVals); } bool LuaDataModel::isValidSyntax(const std::string& expr) { @@ -508,6 +489,7 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s // JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(location.c_str()), getNodeAsValue(data.node), 0, &exception); } else { +#if 0 // trigger error.execution for undefined locations, test286 test311 int retVals = luaEval(_luaState, location + " = " + location); lua_pop(_luaState, retVals); @@ -528,9 +510,14 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s if (idPath.size() == 0) return; +#endif luabridge::LuaRef lua = getDataAsLua(_luaState, data); + luabridge::setGlobal(_luaState, lua, "__tmpAssign"); + evalAsScript(location + "= __tmpAssign"); + +#if 0 if (idPath.size() == 1) { // trivial case where we reference a simple toplevel identifier luabridge::setGlobal(_luaState, lua, location.c_str()); @@ -583,7 +570,7 @@ void LuaDataModel::assign(const std::string& location, const Data& data, const s } } - +#endif // std::cout << Data::toJSON(evalAsData(location)) << std::endl; } } diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index a43b959..93379fc 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -74,6 +74,7 @@ public: virtual bool evalAsBool(const std::string& expr); virtual Data evalAsData(const std::string& expr); + virtual void eval(const std::string& content); virtual Data getAsData(const std::string& content); virtual bool isDeclared(const std::string& expr); diff --git a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h index 61931c6..b030d8b 100644 --- a/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h +++ b/src/uscxml/plugins/invoker/scxml/USCXMLInvoker.h @@ -23,6 +23,7 @@ #include "uscxml/config.h" #include "uscxml/interpreter/InterpreterImpl.h" #include "uscxml/interpreter/BasicEventQueue.h" +#include "uscxml/interpreter/LoggingImpl.h" #include "uscxml/plugins/InvokerImpl.h" |