From: hama Date: Fri, 5 Sep 2014 22:04:29 +0000 (+0200) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=026b42522933c93e6e0bc57ce488c2e6eaa99fb3;p=reqt dayly work --- diff --git a/rplexpr/rplastree.cpp b/rplexpr/rplastree.cpp index 33fb565..d49087c 100644 --- a/rplexpr/rplastree.cpp +++ b/rplexpr/rplastree.cpp @@ -40,7 +40,7 @@ enum { LOC_BINOP_CALC_12, LOC_VARDEF_CHECK_1, LOC_VARDEF_CHECK_2, // 11020 - LOC_FREE_1, + LOC_ITEM_STATEM_LIST_1, LOC_CONV_CHECK_1, LOC_CONV_TRY_1, LOC_ITEM_FORCE_ERROR_1, @@ -572,6 +572,31 @@ void RplASItem::reset() { m_nextId = 1; } +/** + * @brief Checks the correctness of a statement list. + * + * @param list statement list to check + * @param parser for error processing + * @return true: all statements are correct
+ * false: otherwise + */ +bool RplASItem::checkStatementList(RplASItem* list, RplParser& parser) +{ + bool rc = true; + + while(list != NULL){ + if (! list->check(parser)) + rc = false; + RplASNode1* node = dynamic_cast(list); + if (node == NULL){ + list->error(LOC_ITEM_STATEM_LIST_1, parser, "not a node: %s", + list->nameOfItemType()); + list = NULL; + } else + list = node->child(); + } + return rc; +} /** * @brief Returns the node type. * @@ -1491,8 +1516,10 @@ bool RplASVarDefinition::check(RplParser& parser) /** * @brief Executes the statement. + * + * @return 0: continue the current statement list
*/ -void RplASVarDefinition::execute(RplVMThread& thread) +int RplASVarDefinition::execute(RplVMThread& thread) { if (m_child3 != NULL){ // has an initialization: @@ -1509,6 +1536,7 @@ void RplASVarDefinition::execute(RplVMThread& thread) destination.toString().constData()); destination.copyValue(value); } + return 0; } /** @class RplASExprStatement rplastree.hpp "rplexpr/rplastree.hpp" @@ -1548,13 +1576,16 @@ bool RplASExprStatement::check(RplParser& parser) } /** * @brief Executes the statement. + * + * @return 0: continue the current statement list
*/ -void RplASExprStatement::execute(RplVMThread& thread) +int RplASExprStatement::execute(RplVMThread& thread) { RplASCalculable* expr = dynamic_cast (m_child2); expr->calc(thread); RplASVariant& value = thread.popValue(); value.destroyValue(); + return 0; } /** @@ -2050,6 +2081,24 @@ const char*RplASUnaryOp::nameOfOp(RplASUnaryOp::UnaryOp op) RplASStatement::RplASStatement() { } +/** + * @brief Executes the statements of a statement list. + * + * @param list statement list + * @param thread execution unit + * @return 0: continue the current statement list
+ * n > 0: stop the n most inner statement lists (initialized by leave) + * n < 0: stop the -n most inner statement lists (initialized by continue) + */ +int RplASStatement::executeStatementList(RplASItem* list, RplVMThread& thread) +{ + int rc = 0; + while(rc == 0 && list != NULL){ + RplASStatement* statement = dynamic_cast(list); + rc =statement->execute(thread); + } + return rc; +} /** @class RplASCondition rplastree.hpp "rplexpr/rplastree.hpp" * @@ -2166,32 +2215,48 @@ RplASIf::RplASIf() : */ bool RplASIf::check(RplParser& parser) { - return false; + bool rc = m_child2 != NULL && m_child2->check(parser) + && (m_child3 == NULL || checkStatementList(m_child3, parser)) + && (m_child4 == NULL || checkStatementList(m_child4, parser)); + return rc; } /** * @brief Executes the statement. * + * @return 0: continue the current statement list
+ * n > 0: stop the n most inner statement lists (initialized by leave) + * n < 0: stop the -n most inner statement lists (initialized by continue) */ -void RplASIf::execute(RplVMThread& thread) +int RplASIf::execute(RplVMThread& thread) { + int rc = 0; RplASCondition* condition = dynamic_cast(m_child2); if (condition == NULL) throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), "if statement: not a condition"); RplASStatement* body = NULL; + RplASItem* list; if(condition->calcAsBool(thread)){ + list = m_child3; body = dynamic_cast(m_child3); if (body == NULL) throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), "if statement: then-part is not a statement"); } else if (m_child4 != NULL){ + list = m_child4; body = dynamic_cast(m_child4); if (body == NULL) throw RplASException(m_child4->position(), "if statement: else-part is not a statement"); } - body->execute(thread); + if ( (rc = executeStatementList(list, thread)) != 0){ + if (rc < 0) + rc--; + else if (rc > 0) + rc++; + } + return rc; } /** @@ -2262,9 +2327,13 @@ bool RplASForIterated::check(RplParser& parser) /** * @brief Executes the statement. * + * @return 0: continue the current statement list
+ * n > 0: stop the n most inner statement lists (initialized by leave) + * n < 0: stop the -n most inner statement lists (initialized by continue) */ -void RplASForIterated::execute(RplVMThread& thread) +int RplASForIterated::execute(RplVMThread& thread) { + return 0; } /** @@ -2337,9 +2406,13 @@ bool RplASForCounted::check(RplParser& parser) /** * @brief Executes the statement. * + * @return 0: continue the current statement list
+ * n > 0: stop the n most inner statement lists (initialized by leave) + * n < 0: stop the -n most inner statement lists (initialized by continue) */ -void RplASForCounted::execute(RplVMThread& thread) +int RplASForCounted::execute(RplVMThread& thread) { + int rc = 0; RplASStatement* body = dynamic_cast(m_child2); if (body == NULL) throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), @@ -2354,6 +2427,7 @@ void RplASForCounted::execute(RplVMThread& thread) for(int ii = start; ii <= end; ii += step){ body->execute(thread); } + return rc; } /** @@ -2419,10 +2493,13 @@ bool RplASWhile::check(RplParser& parser) /** * @brief Executes the statement. * - * Meaning of the childs: + * @return 0: continue the current statement list
+ * n > 0: stop the n most inner statement lists (initialized by leave) + * n < 0: stop the -n most inner statement lists (initialized by continue) */ -void RplASWhile::execute(RplVMThread& thread) +int RplASWhile::execute(RplVMThread& thread) { + int rc = 0; RplASStatement* body = dynamic_cast(m_child3); if (body == NULL) throw RplASException(m_child3 == NULL ? m_position : m_child3->position(), @@ -2434,6 +2511,7 @@ void RplASWhile::execute(RplVMThread& thread) while(condition->calcAsBool(thread)){ body->execute(thread); } + return rc; } /** @@ -2495,8 +2573,9 @@ bool RplASRepeat::check(RplParser& parser) * m_child: body * m_child2: condition */ -void RplASRepeat::execute(RplVMThread& thread) +int RplASRepeat::execute(RplVMThread& thread) { + int rc = 0; RplASStatement* body = dynamic_cast(m_child3); if (body == NULL) throw RplASException(m_child3 == NULL ? m_position : m_child3->position(), @@ -2508,6 +2587,7 @@ void RplASRepeat::execute(RplVMThread& thread) do { body->execute(thread); } while(condition->calcAsBool(thread)); + return rc; } /** @@ -2864,10 +2944,13 @@ void RplASMethodCall::dump(RplWriter& writer, int indent) } /** - * @brief Executes the statement. + * @brief Executes the method call. + * + * @return 0: continue the current statement list */ -void RplASMethodCall::execute(RplVMThread& thread) +int RplASMethodCall::execute(RplVMThread& thread) { + return 0; } RplASMethod* RplASMethodCall::method() const @@ -3360,8 +3443,9 @@ bool RplASMethod::check(RplParser& parser) * * This method will be never called. Must exit: Otherwise the class is abstract. */ -void RplASMethod::execute(RplVMThread& thread) +int RplASMethod::execute(RplVMThread& thread) { + return 0; } diff --git a/rplexpr/rplastree.hpp b/rplexpr/rplastree.hpp index 942b253..c7bcab9 100644 --- a/rplexpr/rplastree.hpp +++ b/rplexpr/rplastree.hpp @@ -149,6 +149,8 @@ public: virtual void dump(RplWriter& writer,int indent) = 0; public: static void reset(); + static bool checkStatementList(RplASItem* list, RplParser& parser); +public: RplASItemType nodeType() const; const char* nameOfItemType() const; @@ -390,7 +392,9 @@ class RplASStatement public: RplASStatement(); public: - virtual void execute(RplVMThread& thread) = 0; + virtual int execute(RplVMThread& thread) = 0; +public: + static int executeStatementList(RplASItem* list, RplVMThread& thread); }; @@ -400,7 +404,7 @@ public: RplASVarDefinition(); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); public: void dump(RplWriter& writer, int indent); const QByteArray& name() const; @@ -420,7 +424,7 @@ public: RplASExprStatement(); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); public: void dump(RplWriter& writer, int indent); }; @@ -534,7 +538,7 @@ public: RplASIf(); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -544,7 +548,7 @@ public: RplASForIterated(RplASVarDefinition* variable); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -554,7 +558,7 @@ public: RplASForCounted(RplASVarDefinition* variable); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -564,7 +568,7 @@ public: RplASWhile(); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -574,7 +578,7 @@ public: RplASRepeat(); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -597,7 +601,7 @@ public: RplASMethodCall(const QByteArray& name, RplASItem* parent); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); public: void dump(RplWriter& writer, int indent); @@ -642,7 +646,7 @@ public: RplASMethod(const QByteArray& name, RplASTree& tree); public: virtual bool check(RplParser& parser); - virtual void execute(RplVMThread& thread); + virtual int execute(RplVMThread& thread); public: void dump(RplWriter& writer, int indent); RplSymbolSpace* symbols() const;