diff options
author | Stefan Radomski <sradomski@mintwerk.de> | 2016-02-14 14:14:28 (GMT) |
---|---|---|
committer | Stefan Radomski <sradomski@mintwerk.de> | 2016-02-14 14:14:28 (GMT) |
commit | 8e62f3801b98bf4b7f7f85b848b2fe6339c99162 (patch) | |
tree | a6c593bc3e59a864ddb69b6160e3db610fe995d6 /test | |
parent | 7b428e5435f83a7e7db37094a9197afa2dd09bf5 (diff) | |
download | uscxml-8e62f3801b98bf4b7f7f85b848b2fe6339c99162.zip uscxml-8e62f3801b98bf4b7f7f85b848b2fe6339c99162.tar.gz uscxml-8e62f3801b98bf4b7f7f85b848b2fe6339c99162.tar.bz2 |
More work on ANSI C transformation
Diffstat (limited to 'test')
-rw-r--r-- | test/src/test-c-machine.cpp | 125 | ||||
-rw-r--r-- | test/src/test-c-machine.scxml.c | 29 |
2 files changed, 86 insertions, 68 deletions
diff --git a/test/src/test-c-machine.cpp b/test/src/test-c-machine.cpp index 2879ef9..b4864e2 100644 --- a/test/src/test-c-machine.cpp +++ b/test/src/test-c-machine.cpp @@ -66,6 +66,7 @@ public: // register callbacks with scxml context ctx.is_enabled = &isEnabled; + ctx.is_matched = &isMatched; ctx.is_true = &isTrue; ctx.raise_done_event = &raiseDoneEvent; ctx.invoke = &invoke; @@ -250,31 +251,15 @@ public: // callbacks for scxml context - static int isEnabled(const uscxml_ctx* ctx, const uscxml_transition* t, const void* e) { + static int isMatched(const uscxml_ctx* ctx, const uscxml_transition* t, const void* e) { Event* event = (Event*)e; - if (event == NULL) { - if (t->event == NULL) { - // spontaneous transition, null event - if (t->condition != NULL) - return isTrue(ctx, t->condition); - return true; - } else { - // spontaneous transition, but real event - return false; - } - } - - // real event but spontaneous transition - if (t->event == NULL) - return false; + return (nameMatch(t->event, event->name.c_str())); + } - // real transition, real event - if (nameMatch(t->event, event->name.c_str())) { - if (t->condition != NULL) - return isTrue(ctx, t->condition); - return true; - } - return false; + static int isEnabled(const uscxml_ctx* ctx, const uscxml_transition* t) { + if (t->condition != NULL) + return isTrue(ctx, t->condition); + return 1; } static int isTrue(const uscxml_ctx* ctx, const char* expr) { @@ -318,7 +303,7 @@ public: } else if (invocation->idlocation != NULL) { // test224 invokedMachine->invokeId = (invocation->sourcename != NULL ? std::string(invocation->sourcename) + "." : "") + UUID::getUUID(); - ctx->exec_content_assign(ctx, invocation->idlocation, std::string("\"" + invokedMachine->invokeId + "\"").c_str()); + USER_DATA(ctx)->dataModel.assign(invocation->idlocation, Data(invokedMachine->invokeId, Data::VERBATIM)); } else { delete invokedMachine; return USCXML_ERR_UNSUPPORTED; @@ -374,6 +359,19 @@ public: static int execContentSend(const uscxml_ctx* ctx, const uscxml_elem_send* send) { SendRequest* e = new SendRequest(); + std::string sendid; + if (send->id != NULL) { + sendid = send->id; + } else { + sendid = UUID::getUUID(); + if (send->idlocation != NULL) { + USER_DATA(ctx)->dataModel.assign(send->idlocation, Data(sendid, Data::VERBATIM)); + } else { + e->hideSendId = true; + } + } + e->sendid = sendid; + std::string target; if (send->target != NULL) { e->target = send->target; @@ -384,8 +382,8 @@ public: } if (e->target.size() > 0 && (e->target[0] != '#' || e->target[1] != '_')) { - delete e; - execContentRaise(ctx, "error.execution"); + e->name = "error.execution"; + execContentRaise(ctx, e); return USCXML_ERR_INVALID_TARGET; } @@ -401,15 +399,15 @@ public: e->type = "http://www.w3.org/TR/scxml/#SCXMLEventProcessor"; } } catch (Event exc) { - execContentRaise(ctx, exc.name.c_str()); - delete e; + e->name = "error.execution"; + execContentRaise(ctx, e); return USCXML_ERR_EXEC_CONTENT; } // only one somewhat supported if (e->type != "http://www.w3.org/TR/scxml/#SCXMLEventProcessor") { - delete e; - execContentRaise(ctx, "error.execution"); + e->name = "error.execution"; + execContentRaise(ctx, e); return USCXML_ERR_INVALID_TARGET; } @@ -469,19 +467,6 @@ public: } } - std::string sendid; - if (send->id != NULL) { - sendid = send->id; - e->sendid = sendid; - } else { - sendid = UUID::getUUID(); - if (send->idlocation != NULL) { - USER_DATA(ctx)->dataModel.assign(send->idlocation, Data(sendid, Data::VERBATIM)); - } else { - e->hideSendId = true; - } - } - size_t delayMs = 0; std::string delay; if (send->delayexpr != NULL) { @@ -518,10 +503,7 @@ public: return USCXML_ERR_OK; } - static int execContentRaise(const uscxml_ctx* ctx, const char* event) { - Event* e = new Event(); - e->name = event; - + static int execContentRaise(const uscxml_ctx* ctx, Event* e) { if (boost::starts_with(e->name, "error.")) { e->eventType = Event::PLATFORM; } else { @@ -531,6 +513,12 @@ public: return USCXML_ERR_OK; } + static int execContentRaise(const uscxml_ctx* ctx, const char* event) { + Event* e = new Event(); + e->name = event; + return execContentRaise(ctx, e); + } + static int execContentCancel(const uscxml_ctx* ctx, const char* sendid, const char* sendidexpr) { std::string eventId; if (sendid != NULL) { @@ -567,16 +555,22 @@ public: return USCXML_ERR_OK; } - static int execContentAssign(const uscxml_ctx* ctx, const char* location, const char* expr) { - std::string key = location; + static int execContentAssign(const uscxml_ctx* ctx, const uscxml_elem_assign* assign) { + std::string key = assign->location; if (key == "_sessionid" || key == "_name" || key == "_ioprocessors" || key == "_invokers" || key == "_event") { execContentRaise(ctx, "error.execution"); return USCXML_ERR_EXEC_CONTENT; } try { - Data d = USER_DATA(ctx)->dataModel.getStringAsData(expr); - USER_DATA(ctx)->dataModel.assign(key, d); +// Data d = USER_DATA(ctx)->dataModel.getStringAsData(expr); + if (assign->expr != NULL) { + Data d = Data(assign->expr, Data::INTERPRETED); + USER_DATA(ctx)->dataModel.assign(key, d); + } else if (assign->content != NULL) { + Data d = Data(assign->content, Data::INTERPRETED); + USER_DATA(ctx)->dataModel.assign(key, d); + } } catch (Event e) { execContentRaise(ctx, e.name.c_str()); return USCXML_ERR_EXEC_CONTENT; @@ -639,27 +633,32 @@ public: try { if (data->expr != NULL) { -// d = USER_DATA(ctx)->dataModel.getStringAsData(data->expr); d = Data(data->expr, Data::INTERPRETED); - } else if (data->content != NULL) { - content << data->content; - d = USER_DATA(ctx)->dataModel.getStringAsData(content.str()); - // d = Data(content.str(), Data::INTERPRETED); - } else if (data->src != NULL) { - URL sourceURL(data->src); - if (USER_DATA(ctx)->baseURL.size() > 0) { - sourceURL.toAbsolute(USER_DATA(ctx)->baseURL); + + } else if (data->content != NULL || data->src != NULL) { + if (data->content) { + content << data->content; } else { - sourceURL.toAbsoluteCwd(); + URL sourceURL(data->src); + if (USER_DATA(ctx)->baseURL.size() > 0) { + sourceURL.toAbsolute(USER_DATA(ctx)->baseURL); + } else { + sourceURL.toAbsoluteCwd(); + } + content << sourceURL; } - content << sourceURL; - // d = Data(content.str(), Data::INTERPRETED); + /** + * first attempt to parse as structured data, we will try + * as space normalized string literals if this fails below + */ d = USER_DATA(ctx)->dataModel.getStringAsData(content.str()); + } else { d = Data("undefined", Data::INTERPRETED); } // this might fail with an unquoted string literal in content USER_DATA(ctx)->dataModel.init(data->id, d); + } catch (Event e) { if (content.str().size() > 0) { try { diff --git a/test/src/test-c-machine.scxml.c b/test/src/test-c-machine.scxml.c index cbbfbfe..6378096 100644 --- a/test/src/test-c-machine.scxml.c +++ b/test/src/test-c-machine.scxml.c @@ -165,12 +165,14 @@ typedef struct uscxml_elem_invoke uscxml_elem_invoke; typedef struct uscxml_elem_send uscxml_elem_send; typedef struct uscxml_elem_param uscxml_elem_param; typedef struct uscxml_elem_data uscxml_elem_data; +typedef struct uscxml_elem_assign uscxml_elem_assign; typedef struct uscxml_elem_donedata uscxml_elem_donedata; typedef struct uscxml_elem_foreach uscxml_elem_foreach; typedef void* (*dequeue_internal_t)(const uscxml_ctx* ctx); typedef void* (*dequeue_external_t)(const uscxml_ctx* ctx); -typedef int (*is_enabled_t)(const uscxml_ctx* ctx, const uscxml_transition* transition, const void* event); +typedef int (*is_enabled_t)(const uscxml_ctx* ctx, const uscxml_transition* transition); +typedef int (*is_matched_t)(const uscxml_ctx* ctx, const uscxml_transition* transition, const void* event); typedef int (*is_true_t)(const uscxml_ctx* ctx, const char* expr); typedef int (*exec_content_t)(const uscxml_ctx* ctx, const uscxml_state* state, const void* event); typedef int (*raise_done_event_t)(const uscxml_ctx* ctx, const uscxml_state* state, const uscxml_elem_donedata* donedata); @@ -182,7 +184,7 @@ typedef int (*exec_content_send_t)(const uscxml_ctx* ctx, const uscxml_elem_send typedef int (*exec_content_foreach_init_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); typedef int (*exec_content_foreach_next_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); typedef int (*exec_content_foreach_done_t)(const uscxml_ctx* ctx, const uscxml_elem_foreach* foreach); -typedef int (*exec_content_assign_t)(const uscxml_ctx* ctx, const char* location, const char* expr); +typedef int (*exec_content_assign_t)(const uscxml_ctx* ctx, const uscxml_elem_assign* assign); typedef int (*exec_content_init_t)(const uscxml_ctx* ctx, const uscxml_elem_data* data); typedef int (*exec_content_cancel_t)(const uscxml_ctx* ctx, const char* sendid, const char* sendidexpr); typedef int (*exec_content_finalize_t)(const uscxml_ctx* ctx, const uscxml_elem_invoke* invoker, const void* event); @@ -218,6 +220,15 @@ struct uscxml_elem_data { }; /** + * All information pertaining to an <assign> element. + */ +struct uscxml_elem_assign { + const char* location; + const char* expr; + const char* content; +}; + +/** * All information pertaining to any state element. */ struct uscxml_state { @@ -335,6 +346,7 @@ struct uscxml_ctx { dequeue_internal_t dequeue_internal; dequeue_external_t dequeue_external; is_enabled_t is_enabled; + is_matched_t is_matched; is_true_t is_true; raise_done_event_t raise_done_event; @@ -360,6 +372,12 @@ extern const uscxml_machine _uscxml_EC83C2A5_machine; #ifndef USCXML_NO_ELEM_INFO +static const uscxml_elem_assign _uscxml_EC83C2A5_elem_assigns[2] = { + /* location, expr, content */ + { "_ioprocessors", "'otherName'", NULL }, + { "Var2", "_ioprocessors", NULL }, +}; + static const uscxml_elem_data _uscxml_EC83C2A5_elem_datas[3] = { /* id, src, expr, content */ { "Var1", NULL, "_ioprocessors", NULL }, @@ -383,7 +401,7 @@ static const uscxml_elem_donedata _uscxml_EC83C2A5_elem_donedatas[1] = { static int _uscxml_EC83C2A5_s1_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_assign != NULL) { - if ((ctx->exec_content_assign(ctx, "_ioprocessors", "'otherName'")) != USCXML_ERR_OK) return err; + if ((ctx->exec_content_assign(ctx, &_uscxml_EC83C2A5_elem_assigns[0])) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } @@ -403,7 +421,7 @@ static int _uscxml_EC83C2A5_s1_on_entry(const uscxml_ctx* ctx, const uscxml_stat static int _uscxml_EC83C2A5_s2_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; if likely(ctx->exec_content_assign != NULL) { - if ((ctx->exec_content_assign(ctx, "Var2", "_ioprocessors")) != USCXML_ERR_OK) return err; + if ((ctx->exec_content_assign(ctx, &_uscxml_EC83C2A5_elem_assigns[1])) != USCXML_ERR_OK) return err; } else { return USCXML_ERR_MISSING_CALLBACK; } @@ -836,7 +854,8 @@ SELECT_TRANSITIONS: if ((USCXML_GET_TRANS(i).event == NULL && ctx->event == NULL) || (USCXML_GET_TRANS(i).event != NULL && ctx->event != NULL)) { /* is it enabled? */ - if (ctx->is_enabled(ctx, &USCXML_GET_TRANS(i), ctx->event) > 0) { + if ((ctx->event == NULL || ctx->is_matched(ctx, &USCXML_GET_TRANS(i), ctx->event) > 0) && + (USCXML_GET_TRANS(i).condition == NULL || ctx->is_enabled(ctx, &USCXML_GET_TRANS(i)) > 0)) { /* remember that we found a transition */ ctx->flags |= USCXML_CTX_TRANSITION_FOUND; |