diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel')
4 files changed, 166 insertions, 106 deletions
diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp index 9edd505..679177a 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp @@ -329,6 +329,7 @@ void PromelaDataModel::evaluateStmnt(const std::string& expr) { void PromelaDataModel::evaluateDecl(void* ast) { PromelaParserNode* node = (PromelaParserNode*)ast; +// node->dump(); if (false) { } else if (node->type == PML_DECL) { std::list<PromelaParserNode*>::iterator opIter = node->operands.begin(); @@ -398,6 +399,7 @@ void PromelaDataModel::evaluateDecl(void* ast) { evaluateDecl(*declIter); } } else { + node->dump(); ERROR_EXECUTION_THROW("Declaring variables via " + PromelaParserNode::typeToDesc(node->type) + " not implemented"); } } @@ -446,8 +448,9 @@ Data PromelaDataModel::evaluateExpr(void* ast) { case PML_CMPND: return getVariable(node); case PML_STRING: { - std::string stripped = node->value.substr(1, node->value.size() - 2); - return Data(stripped, Data::VERBATIM); +// std::string stripped = node->value.substr(1, node->value.size() - 2); +// return Data(stripped, Data::VERBATIM); + return Data(node->value, Data::INTERPRETED); } case PML_PLUS: return dataToInt(evaluateExpr(*opIter++)) + dataToInt(evaluateExpr(*opIter++)); @@ -549,29 +552,33 @@ void PromelaDataModel::evaluateStmnt(void* ast) { } } -void PromelaDataModel::setVariable(void* ast, Data value) { + +void PromelaDataModel::setVariable(void* ast, const Data& value) { PromelaParserNode* node = (PromelaParserNode*)ast; - std::list<PromelaParserNode*>::iterator opIter = node->operands.begin(); + if (INVALID_ASSIGNMENT(node->value)) { + ERROR_EXECUTION_THROW("Cannot assign to " + node->value); + } + +// if (_variables.compound.find(name->value) == _variables.compound.end()) { +// // declare implicitly / convenience +// evaluateDecl(ast); +// } + switch (node->type) { case PML_VAR_ARRAY: { + std::list<PromelaParserNode*>::iterator opIter = node->operands.begin(); + PromelaParserNode* name = *opIter++; PromelaParserNode* expr = *opIter++; - if (INVALID_ASSIGNMENT(name->value)) { - ERROR_EXECUTION_THROW("Cannot assign to " + name->value); - } - - int index = dataToInt(evaluateExpr(expr)); - - if (_variables.compound.find(name->value) == _variables.compound.end()) { - ERROR_EXECUTION_THROW("No variable " + name->value + " was declared"); - } - + // is the location an array? if (!_variables[name->value].hasKey("size")) { ERROR_EXECUTION_THROW("Variable " + name->value + " is no array"); } + // is the array large enough? + int index = dataToInt(evaluateExpr(expr)); if (strTo<int>(_variables[name->value]["size"].atom) <= index) { ERROR_EXECUTION_THROW("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds"); } @@ -580,19 +587,51 @@ void PromelaDataModel::setVariable(void* ast, Data value) { break; } - case PML_NAME: - if (INVALID_ASSIGNMENT(node->value)) { - ERROR_EXECUTION_THROW("Cannot assign to " + node->value); + case PML_NAME: { + // location is an array, but no array was passed + if (_variables[node->value].hasKey("size")) { + if (value.compound.size() > 0 || value.atom.size() > 0) + ERROR_EXECUTION_THROW("Variable " + node->value + " is an array"); + + if (_variables[node->value].compound["size"] < value.array.size()) + ERROR_EXECUTION_THROW("Array assigned to " + node->value + " is too large"); } + _variables.compound[node->value].compound["value"] = value; break; + } + case PML_CMPND: { + std::list<PromelaParserNode*>::iterator opIter = node->operands.begin(); + PromelaParserNode* name = *opIter++; + + // location is no array + if (_variables[name->value].hasKey("size")) { + ERROR_EXECUTION_THROW("Variable " + name->value + " is an array"); + } + +// std::cout << Data::toJSON(_variables) << std::endl;; + + Data* var = &_variables[name->value].compound["value"]; + var->compound["type"] = Data("compound", Data::VERBATIM); + var->compound["vis"] = Data("", Data::VERBATIM); + + while(opIter != node->operands.end()) { + name = *opIter; opIter++; + var = &(var->compound[name->value]); + } + *var = value; + + break; + } default: + node->dump(); + ERROR_EXECUTION_THROW("No support for " + PromelaParserNode::typeToDesc(node->type) + " variables implemented"); break; } // std::cout << Data::toJSON(_variables) << std::endl; } - + Data PromelaDataModel::getVariable(void* ast) { PromelaParserNode* node = (PromelaParserNode*)ast; // node->dump(); @@ -628,7 +667,6 @@ Data PromelaDataModel::getVariable(void* ast) { case PML_CMPND: { // node->dump(); // std::cout << Data::toJSON(_variables["_event"]); - std::stringstream idPath; PromelaParserNode* name = *opIter++; @@ -711,7 +749,7 @@ void PromelaDataModel::init(const Element<std::string>& dataElem, // from <datamodel> if (HAS_ATTR(dataElem, "id")) { std::string identifier = ATTR(dataElem, "id"); - std::string type = (HAS_ATTR(dataElem, "type") ? ATTR(dataElem, "type") : "int"); + std::string type = (HAS_ATTR(dataElem, "type") ? ATTR(dataElem, "type") : "auto"); std::string arrSize; size_t bracketPos = type.find("["); @@ -719,7 +757,7 @@ void PromelaDataModel::init(const Element<std::string>& dataElem, arrSize = type.substr(bracketPos, type.length() - bracketPos); type = type.substr(0, bracketPos); } - + std::string expr = type + " " + identifier + arrSize; PromelaParser parser(expr, 1, PromelaParser::PROMELA_DECL); evaluateDecl(parser.ast); @@ -733,9 +771,29 @@ void PromelaDataModel::init(const std::string& location, const Data& data) { bool PromelaDataModel::isDeclared(const std::string& expr) { PromelaParser parser(expr); +// parser.dump(); if (parser.ast->type == PML_VAR_ARRAY) return _variables.compound.find(parser.ast->operands.front()->value) != _variables.compound.end(); + if (parser.ast->type == PML_CMPND) { + // JSON declaration + std::list<PromelaParserNode*>::iterator opIter = parser.ast->operands.begin(); + Data* var = &_variables; + + while(opIter != parser.ast->operands.end()) { + std::string name = (*opIter)->value; opIter++; + if (var->compound.find(name) != var->compound.end()) { + var = &(var->compound.at(name)); + } else if (var->compound.find("value") != var->compound.end() && var->compound.at("value").compound.find(name) != var->compound.at("value").compound.end()) { + var = &(var->compound.at("value").compound.at(name)); + } else { + return false; + } + } + return true; + + } + return _variables.compound.find(expr) != _variables.compound.end(); } diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h index b286f4b..581c761 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h @@ -93,7 +93,7 @@ protected: Data evaluateExpr(const std::string& expr); void evaluateStmnt(const std::string& expr); - void setVariable(void* ast, Data value); + void setVariable(void* ast, const Data& value); Data getVariable(void* ast); void adaptType(Data& data); diff --git a/src/uscxml/plugins/datamodel/promela/parser/promela.l b/src/uscxml/plugins/datamodel/promela/parser/promela.l index d247d74..1edc625 100644 --- a/src/uscxml/plugins/datamodel/promela/parser/promela.l +++ b/src/uscxml/plugins/datamodel/promela/parser/promela.l @@ -43,7 +43,7 @@ L [a-zA-Z_] \/\*([^*]|\*[^/])*\*+\/ /* multiline comments */ -bit|bool|byte|int|mtype|short|unsigned|string { +bit|bool|byte|int|mtype|short|unsigned|string|auto { yylval->value = strdup(yytext); return PML_TYPE; } diff --git a/src/uscxml/plugins/datamodel/promela/parser/promela.lex.yy.cpp b/src/uscxml/plugins/datamodel/promela/parser/promela.lex.yy.cpp index 842efe6..2cd66f2 100644 --- a/src/uscxml/plugins/datamodel/promela/parser/promela.lex.yy.cpp +++ b/src/uscxml/plugins/datamodel/promela/parser/promela.lex.yy.cpp @@ -456,7 +456,7 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[124] = +static yyconst flex_int16_t yy_accept[126] = { 0, 0, 0, 47, 45, 44, 44, 8, 45, 14, 25, 45, 33, 34, 12, 15, 31, 16, 30, 13, 42, @@ -465,13 +465,13 @@ static yyconst flex_int16_t yy_accept[124] = 27, 38, 9, 44, 23, 0, 40, 0, 28, 0, 41, 0, 10, 11, 0, 42, 17, 19, 24, 20, 18, 43, 0, 0, 43, 43, 43, 43, 43, 43, - 43, 43, 43, 43, 43, 43, 43, 43, 43, 29, - 0, 41, 0, 0, 0, 43, 2, 43, 43, 43, - 3, 43, 43, 43, 43, 43, 43, 43, 43, 0, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, + 29, 0, 41, 0, 0, 0, 43, 43, 2, 43, + 43, 43, 3, 43, 43, 43, 43, 43, 43, 43, - 1, 43, 43, 43, 43, 43, 4, 43, 43, 43, - 1, 43, 43, 43, 43, 43, 7, 5, 43, 43, - 6, 43, 0 + 43, 0, 1, 43, 43, 43, 43, 43, 4, 43, + 43, 43, 1, 43, 43, 43, 43, 43, 7, 5, + 43, 43, 6, 43, 0 } ; static yyconst flex_int32_t yy_ec[256] = @@ -515,43 +515,43 @@ static yyconst flex_int32_t yy_meta[51] = 2, 2, 2, 2, 2, 2, 1, 1, 1, 1 } ; -static yyconst flex_int16_t yy_base[129] = +static yyconst flex_int16_t yy_base[131] = { 0, - 0, 0, 169, 170, 49, 51, 148, 50, 170, 160, - 48, 170, 170, 170, 154, 170, 151, 170, 153, 146, - 170, 38, 142, 39, 0, 56, 170, 170, 170, 118, - 28, 132, 120, 127, 113, 114, 33, 20, 116, 170, - 106, 170, 170, 68, 170, 60, 170, 150, 170, 64, - 170, 73, 170, 170, 141, 134, 170, 170, 170, 170, - 170, 0, 74, 70, 107, 105, 108, 103, 109, 101, - 105, 97, 107, 101, 105, 97, 93, 96, 93, 170, - 72, 75, 79, 124, 75, 103, 0, 96, 101, 88, - 0, 89, 90, 86, 86, 91, 94, 93, 88, 77, - - 170, 80, 90, 89, 75, 74, 0, 78, 86, 82, - 103, 69, 71, 69, 70, 57, 0, 0, 62, 61, - 0, 60, 170, 104, 106, 82, 108, 110 + 0, 0, 172, 173, 49, 51, 151, 50, 173, 163, + 48, 173, 173, 173, 157, 173, 154, 173, 156, 149, + 173, 38, 145, 39, 0, 56, 173, 173, 173, 20, + 31, 136, 124, 131, 117, 118, 34, 30, 120, 173, + 110, 173, 173, 77, 173, 57, 173, 154, 173, 59, + 173, 66, 173, 173, 145, 138, 173, 173, 173, 173, + 173, 0, 76, 75, 111, 109, 108, 111, 106, 112, + 104, 108, 100, 110, 104, 108, 100, 96, 99, 96, + 173, 77, 78, 84, 127, 77, 106, 96, 0, 98, + 103, 90, 0, 91, 92, 88, 88, 93, 96, 95, + + 90, 78, 173, 82, 92, 91, 77, 76, 0, 80, + 88, 75, 96, 62, 73, 71, 68, 59, 0, 0, + 65, 65, 0, 65, 173, 109, 111, 88, 113, 115 } ; -static yyconst flex_int16_t yy_def[129] = +static yyconst flex_int16_t yy_def[131] = { 0, - 123, 1, 123, 123, 123, 123, 123, 124, 123, 123, - 125, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 126, 126, 123, 123, 123, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 123, - 123, 123, 123, 123, 123, 124, 123, 124, 123, 125, - 123, 127, 123, 123, 128, 123, 123, 123, 123, 123, - 123, 126, 124, 125, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 123, - 125, 125, 127, 128, 128, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 128, - - 123, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 128, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 0, 123, 123, 123, 123, 123 + 125, 1, 125, 125, 125, 125, 125, 126, 125, 125, + 127, 125, 125, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125, 125, 128, 128, 125, 125, 125, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 125, + 125, 125, 125, 125, 125, 126, 125, 126, 125, 127, + 125, 129, 125, 125, 130, 125, 125, 125, 125, 125, + 125, 128, 126, 127, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 125, 127, 127, 129, 130, 130, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + + 128, 130, 125, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 130, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 0, 125, 125, 125, 125, 125 } ; -static yyconst flex_int16_t yy_nxt[221] = +static yyconst flex_int16_t yy_nxt[224] = { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, @@ -559,27 +559,28 @@ static yyconst flex_int16_t yy_nxt[221] = 25, 32, 25, 25, 33, 25, 34, 35, 25, 25, 36, 25, 37, 38, 39, 25, 40, 41, 42, 43, 44, 44, 44, 44, 47, 51, 57, 58, 60, 61, - 63, 77, 66, 64, 47, 78, 74, 67, 75, 44, - 44, 51, 52, 68, 48, 50, 76, 51, 47, 51, - 82, 50, 51, 62, 48, 100, 82, 85, 52, 87, - 101, 122, 111, 121, 52, 120, 52, 83, 48, 52, - - 119, 87, 118, 83, 46, 46, 50, 50, 81, 81, - 84, 84, 117, 85, 116, 115, 114, 87, 113, 87, - 107, 112, 110, 109, 107, 108, 107, 106, 105, 104, - 103, 87, 87, 102, 85, 99, 98, 97, 96, 95, - 94, 93, 92, 91, 87, 90, 89, 88, 87, 86, - 56, 85, 123, 80, 79, 73, 72, 71, 70, 69, - 65, 59, 56, 55, 54, 53, 49, 45, 123, 3, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123 + 63, 47, 65, 64, 66, 67, 51, 75, 50, 76, + 68, 78, 52, 83, 48, 79, 69, 77, 44, 44, + 47, 48, 51, 52, 51, 51, 50, 102, 86, 62, + 84, 83, 103, 113, 89, 124, 123, 122, 121, 52, + + 48, 52, 52, 89, 120, 119, 86, 118, 84, 46, + 46, 50, 50, 82, 82, 85, 85, 117, 116, 89, + 115, 89, 109, 114, 112, 111, 109, 110, 109, 108, + 107, 106, 105, 89, 89, 89, 104, 86, 101, 100, + 99, 98, 97, 96, 95, 94, 93, 89, 92, 91, + 90, 89, 88, 87, 56, 86, 125, 81, 80, 74, + 73, 72, 71, 70, 59, 56, 55, 54, 53, 49, + 45, 125, 3, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, + + 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125 } ; -static yyconst flex_int16_t yy_chk[221] = +static yyconst flex_int16_t yy_chk[224] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -587,24 +588,25 @@ static yyconst flex_int16_t yy_chk[221] = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 6, 6, 8, 11, 22, 22, 24, 24, - 26, 38, 31, 26, 46, 38, 37, 31, 37, 44, - 44, 50, 11, 31, 8, 52, 37, 64, 63, 81, - 52, 83, 82, 126, 46, 85, 83, 100, 50, 122, - 85, 120, 100, 119, 64, 116, 81, 52, 63, 82, - - 115, 114, 113, 83, 124, 124, 125, 125, 127, 127, - 128, 128, 112, 111, 110, 109, 108, 106, 105, 104, - 103, 102, 99, 98, 97, 96, 95, 94, 93, 92, - 90, 89, 88, 86, 84, 79, 78, 77, 76, 75, - 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, - 56, 55, 48, 41, 39, 36, 35, 34, 33, 32, - 30, 23, 20, 19, 17, 15, 10, 7, 3, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123 + 26, 46, 30, 26, 30, 31, 50, 37, 52, 37, + 31, 38, 11, 52, 8, 38, 31, 37, 44, 44, + 63, 46, 64, 50, 82, 83, 84, 86, 102, 128, + 52, 84, 86, 102, 124, 122, 121, 118, 117, 64, + + 63, 82, 83, 116, 115, 114, 113, 112, 84, 126, + 126, 127, 127, 129, 129, 130, 130, 111, 110, 108, + 107, 106, 105, 104, 101, 100, 99, 98, 97, 96, + 95, 94, 92, 91, 90, 88, 87, 85, 80, 79, + 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, + 68, 67, 66, 65, 56, 55, 48, 41, 39, 36, + 35, 34, 33, 32, 23, 20, 19, 17, 15, 10, + 7, 3, 125, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, + + 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, + 125, 125, 125 } ; /* Table of booleans, true if rule could match eol. */ @@ -655,7 +657,7 @@ static yyconst flex_int16_t yy_rule_linenum[46] = yycolumn = yycolumn + yyleng; \ } -#line 659 "promela.lex.yy.cpp" +#line 661 "promela.lex.yy.cpp" #define INITIAL 0 @@ -964,7 +966,7 @@ YY_DECL #line 42 "promela.l" -#line 968 "promela.lex.yy.cpp" +#line 970 "promela.lex.yy.cpp" yylval = yylval_param; @@ -1031,13 +1033,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 124 ) + if ( yy_current_state >= 126 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_current_state != 123 ); + while ( yy_current_state != 125 ); yy_cp = yyg->yy_last_accepting_cpos; yy_current_state = yyg->yy_last_accepting_state; @@ -1330,7 +1332,7 @@ YY_RULE_SETUP #line 118 "promela.l" ECHO; YY_BREAK -#line 1334 "promela.lex.yy.cpp" +#line 1336 "promela.lex.yy.cpp" case YY_STATE_EOF(INITIAL): yyterminate(); @@ -1646,7 +1648,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 124 ) + if ( yy_current_state >= 126 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1680,11 +1682,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 124 ) + if ( yy_current_state >= 126 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 123); + yy_is_jam = (yy_current_state == 125); return yy_is_jam ? 0 : yy_current_state; } |