diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel/promela')
-rw-r--r-- | src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp | 30 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/promela/PromelaParser.cpp | 13 |
2 files changed, 18 insertions, 25 deletions
diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp index 8bfc39d..4300512 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp @@ -100,11 +100,11 @@ bool PromelaDataModel::validate(const std::string& location, const std::string& uint32_t PromelaDataModel::getLength(const std::string& expr) { if (!isDeclared(expr)) { - throwErrorExecution("Variable " + expr + " was not declared"); + ERROR_EXECUTION_THROW("Variable '" + expr + "' was not declared"); } if (!_variables[expr].hasKey("size")) { - throwErrorExecution("Variable " + expr + " is no array"); + ERROR_EXECUTION_THROW("Variable '" + expr + "' is no array"); } return strTo<int>(_variables[expr]["size"].atom); @@ -216,7 +216,7 @@ void PromelaDataModel::evaluateDecl(void* ast) { _variables.compound[name->value] = variable; } else { - throwErrorExecution("Declaring variables via " + PromelaParserNode::typeToDesc((*nameIter)->type) + " not implemented"); + ERROR_EXECUTION_THROW("Declaring variables via " + PromelaParserNode::typeToDesc((*nameIter)->type) + " not implemented"); } } assert(opIter == node->operands.end()); @@ -227,7 +227,7 @@ void PromelaDataModel::evaluateDecl(void* ast) { evaluateDecl(*declIter); } } else { - throwErrorExecution("Declaring variables via " + PromelaParserNode::typeToDesc(node->type) + " not implemented"); + ERROR_EXECUTION_THROW("Declaring variables via " + PromelaParserNode::typeToDesc(node->type) + " not implemented"); } } @@ -269,7 +269,7 @@ int PromelaDataModel::evaluateExpr(void* ast) { case PML_OR: return evaluateExpr(*opIter++) != 0 || evaluateExpr(*opIter++) != 0; default: - throwErrorExecution("Support for " + PromelaParserNode::typeToDesc(node->type) + " expressions not implemented"); + ERROR_EXECUTION_THROW("Support for " + PromelaParserNode::typeToDesc(node->type) + " expressions not implemented"); } return 0; } @@ -291,7 +291,7 @@ void PromelaDataModel::evaluateStmnt(void* ast) { break; } default: - throwErrorExecution("No support for " + PromelaParserNode::typeToDesc(node->type) + " statement implemented"); + ERROR_EXECUTION_THROW("No support for " + PromelaParserNode::typeToDesc(node->type) + " statement implemented"); } } @@ -306,15 +306,15 @@ void PromelaDataModel::setVariable(void* ast, int value) { int index = evaluateExpr(expr); if (_variables.compound.find(name->value) == _variables.compound.end()) { - throwErrorExecution("No variable " + name->value + " was declared"); + ERROR_EXECUTION_THROW("No variable " + name->value + " was declared"); } if (!_variables[name->value].hasKey("size")) { - throwErrorExecution("Variable " + name->value + " is no array"); + ERROR_EXECUTION_THROW("Variable " + name->value + " is no array"); } if (strTo<int>(_variables[name->value]["size"].atom) <= index) { - throwErrorExecution("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds"); + ERROR_EXECUTION_THROW("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds"); } _variables.compound[name->value].compound["value"][index] = Data(value, Data::VERBATIM); @@ -339,10 +339,10 @@ int PromelaDataModel::getVariable(void* ast) { switch(node->type) { case PML_NAME: if (_variables.compound.find(node->value) == _variables.compound.end()) { - throwErrorExecution("No variable " + node->value + " was declared"); + ERROR_EXECUTION_THROW("No variable " + node->value + " was declared"); } if (_variables[node->value].compound.find("size") != _variables[node->value].compound.end()) { - throwErrorExecution("Type error: Variable " + node->value + " is an array"); + ERROR_EXECUTION_THROW("Type error: Variable " + node->value + " is an array"); } return strTo<int>(_variables[node->value]["value"].atom); case PML_VAR_ARRAY: { @@ -351,20 +351,20 @@ int PromelaDataModel::getVariable(void* ast) { int index = evaluateExpr(expr); if (_variables.compound.find(name->value) == _variables.compound.end()) { - throwErrorExecution("No variable " + name->value + " was declared"); + ERROR_EXECUTION_THROW("No variable " + name->value + " was declared"); } if (!_variables[name->value].hasKey("size")) { - throwErrorExecution("Variable " + name->value + " is no array"); + ERROR_EXECUTION_THROW("Variable " + name->value + " is no array"); } if (strTo<int>(_variables[name->value]["size"].atom) <= index) { - throwErrorExecution("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds"); + ERROR_EXECUTION_THROW("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds"); } return strTo<int>(_variables.compound[name->value].compound["value"][index].atom); } default: - throwErrorExecution("Retrieving value of " + PromelaParserNode::typeToDesc(node->type) + " variable not implemented"); + ERROR_EXECUTION_THROW("Retrieving value of " + PromelaParserNode::typeToDesc(node->type) + " variable not implemented"); } return 0; } diff --git a/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp b/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp index cd3bbaf..d12b7fc 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp @@ -19,6 +19,7 @@ #include "PromelaParser.h" #include "parser/promela.tab.hpp" +#include "uscxml/messages/Event.h" #include <iostream> @@ -35,10 +36,7 @@ int promela_lex_destroy (void*); void promela_error (uscxml::PromelaParser* ctx, void* yyscanner, const char* err) { // mark as pending exception as we cannot throw from constructor and have the destructor called - uscxml::Event excEvent; - excEvent.data.compound["exception"] = uscxml::Data(err, uscxml::Data::VERBATIM); - excEvent.name = "error.execution"; - excEvent.eventType = uscxml::Event::PLATFORM; + ERROR_EXECUTION(excEvent, err); ctx->pendingException = excEvent; } @@ -53,12 +51,7 @@ PromelaParser::PromelaParser(const std::string& expr, Type expectedType) { if (type != expectedType) { std::stringstream ss; ss << "Promela syntax type mismatch: Expected " << typeToDesc(expectedType) << " but got " << typeToDesc(type); - - uscxml::Event excEvent; - excEvent.data.compound["exception"] = uscxml::Data(ss.str(), uscxml::Data::VERBATIM); - excEvent.name = "error.execution"; - excEvent.eventType = uscxml::Event::PLATFORM; - throw excEvent; + ERROR_EXECUTION_THROW(ss.str()); } } |