From: hama Date: Sat, 6 Sep 2014 23:20:33 +0000 (+0200) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=e61b7e33dc0c01c6b6292a37df7cd231a67a068d;p=reqt dayly work --- diff --git a/rpldoc.zip b/rpldoc.zip index 4958194..3144ac1 100644 Binary files a/rpldoc.zip and b/rpldoc.zip differ diff --git a/rplexpr/rplastree.cpp b/rplexpr/rplastree.cpp index d49087c..30eb2ad 100644 --- a/rplexpr/rplastree.cpp +++ b/rplexpr/rplastree.cpp @@ -45,6 +45,14 @@ enum { LOC_CONV_TRY_1, LOC_ITEM_FORCE_ERROR_1, LOC_UNARY_CHECK_4, // 11025 + LOC_IF_CHECK_1, + LOC_IF_CHECK_2, + LOC_FORC_CHECK_1, + LOC_FORC_CHECK_2, + LOC_FORC_CHECK_3, // 11030 + LOC_ITEM_AS_INT_1, + LOC_ITEM_AS_INT_2, + LOC_METHOD_CALL_CHECK_1, LOC_COUNT }; @@ -498,6 +506,34 @@ RplASItem::~RplASItem() { } +/** + * @brief Checks a calculable node for correctness. + * + * @param description description of the meaning, e.g. "start value" + * @param expectedClass the node must have this type + * @param parser for error processing + * @return true: instance and children are correct
+ * false: otherwise + */ +bool RplASItem::checkAsCalculable(const char* description, + RplASClass* expectedClass, RplParser& parser) +{ + bool rc = true; + if (! check(parser)) + rc = false; + if (rc){ + RplASCalculable* expr = dynamic_cast(this); + if (expr == NULL) + rc = error(LOC_ITEM_AS_INT_1, parser, "%s not calculable: %s", + description, nameOfItemType()); + else if (expr->clazz() != RplASInteger::m_instance) + rc = error(LOC_ITEM_AS_INT_2, parser, + "%s: wrong type %s instead of integer", + description, expr->clazz()->name().constData()); + } + return rc; +} + /** * @brief Returns the position of the item in the source code. * @@ -572,6 +608,37 @@ void RplASItem::reset() { m_nextId = 1; } +/** + * @brief Calculates an integer value. + * + * @param expr a calculable node + * @param thread the execution unit + * @return the value described by the node expr + */ +int RplASItem::calcAsInteger(RplASItem* expr, RplVMThread& thread) +{ + RplASCalculable* expr2 = dynamic_cast(expr); + expr2->calc(thread); + RplASVariant& value = thread.popValue(); + int rc = value.asInt(); + return rc; +} + +/** + * @brief Calculates an boolean value. + * + * @param expr a calculable node + * @param thread the execution unit + * @return the value described by the node expr + */ +bool RplASItem::calcAsBoolean(RplASItem* expr, RplVMThread& thread) +{ + RplASCalculable* expr2 = dynamic_cast(expr); + expr2->calc(thread); + RplASVariant& value = thread.popValue(); + bool rc = value.asBool(); + return rc; +} /** * @brief Checks the correctness of a statement list. * @@ -586,14 +653,18 @@ bool RplASItem::checkStatementList(RplASItem* list, RplParser& parser) while(list != NULL){ if (! list->check(parser)) - rc = false; + rc = false; + if (dynamic_cast(list) == NULL) + rc = list->error(LOC_ITEM_STATEM_LIST_1, parser, "not a statement: %s", + list->nameOfItemType()); 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 + } else { list = node->child(); + } } return rc; } @@ -1036,9 +1107,9 @@ RplASMapOfVariants* RplASMapConstant::map() /** * @brief Constructor. * - * @param dataType the data type (class) - * @param name the name of the variable + * @param clazz the data type (class) * @param space the current symbol space + * @param name the name of the variable * @param attributes the attributes of the variable */ RplASNamedValue::RplASNamedValue(RplASClass* clazz,RplSymbolSpace* space, @@ -1362,7 +1433,7 @@ bool RplASIndexedValue::check(RplParser& parser) if (rc && converter != NULL) m_child = converter; if (rc){ - //@ToDo: dynamic subclass of list + //@ToDo: dynamic subclass of list / map m_class = RplASString::m_instance; rc = m_class != NULL && m_class == RplASInteger::m_instance; } @@ -1584,6 +1655,9 @@ int RplASExprStatement::execute(RplVMThread& thread) RplASCalculable* expr = dynamic_cast (m_child2); expr->calc(thread); RplASVariant& value = thread.popValue(); + if (thread.tracing()) + thread.vm()->traceWriter()->format("expr: %s", + value.toString().constData()); value.destroyValue(); return 0; } @@ -2100,91 +2174,6 @@ int RplASStatement::executeStatementList(RplASItem* list, RplVMThread& thread) return rc; } -/** @class RplASCondition rplastree.hpp "rplexpr/rplastree.hpp" - * - * @brief Implements a condition. - * - * The condition is a statement and a RplASExpr and will be used in other - * statements like for and while. - * - */ -/** - * @brief Constructor. - */ -RplASCondition::RplASCondition() : - RplASNode1(AST_CONDITION), - RplASCalculable() -{ -} - -/** - * @brief Calculates the value of the condition - * - * @param thread IN/OUT: the bool value of the condition - */ -void RplASCondition::calc(RplVMThread& thread) -{ - RplASCalculable* expr = dynamic_cast(m_child); - expr->calc(thread); - if (thread.tracing()) - thread.vm()->traceWriter()->format("condition: %s", - thread.topOfValues().toString().constData()); -} - -/** - * @brief Checks the correctness of the instance. - * - * @param parser for error processing - * @return true: node is correct
- * false: otherwise - */ -bool RplASCondition::check(RplParser& parser) -{ - RplASCalculable* expr = dynamic_cast(m_child); - if (expr == NULL) - throw RplASException(m_position, "child of condition is not calculable"); - return false; -} -/** - * @brief Calculates the boolean value and returns it. - */ -bool RplASCondition::calcAsBool(RplVMThread& thread) -{ - bool rc = false; - calc(thread); - RplASVariant& value = thread.topOfValues(); - switch(value.m_variantType){ - case RplASVariant::VT_FLOAT: - rc = value.m_value.m_float == 0; - break; - case RplASVariant::VT_BOOL: - rc = value.m_value.m_bool; - break; - case RplASVariant::VT_OBJECT: - rc = value.m_class->boolValueOf(value.m_value.m_object); - break; - default: - rc = false; - break; - } - return rc; -} - -/** - * @brief Writes the internals into a file. - * - * @param writer writes to output - * @param indent nesting level - */ -void RplASCondition::dump(RplWriter& writer, int indent) -{ - char buffer[256]; - writer.formatIndented(indent, "Condition %d Child: %d %s", m_id, - m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); - if (m_child != NULL) - m_child->dump(writer, indent); -} /** @class RplASIf rplastree.hpp "rplexpr/rplastree.hpp" * @@ -2215,9 +2204,16 @@ RplASIf::RplASIf() : */ bool RplASIf::check(RplParser& parser) { - bool rc = m_child2 != NULL && m_child2->check(parser) - && (m_child3 == NULL || checkStatementList(m_child3, parser)) - && (m_child4 == NULL || checkStatementList(m_child4, parser)); + bool rc = true; + if (m_child2 == NULL) + rc = ensureError(parser, "'if' misses condition"); + else if (m_child2->checkAsCalculable("condition", RplASBoolean::m_instance, + parser)) + rc = false; + if (m_child3 != NULL && ! checkStatementList(m_child3, parser)) + rc = false; + if (m_child4 != NULL && ! checkStatementList(m_child4, parser)) + rc = false; return rc; } @@ -2231,30 +2227,18 @@ bool RplASIf::check(RplParser& parser) 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"); - } - if ( (rc = executeStatementList(list, thread)) != 0){ - if (rc < 0) - rc--; - else if (rc > 0) - rc++; + bool condition = calcAsBoolean(m_child2, thread); + if (thread.tracing()) + thread.vm()->traceWriter()->format("if %s", condition ? "true" : "false"); + + RplASItem* list = condition ? m_child3 : m_child4; + if (list != NULL){ + if ( (rc = executeStatementList(list, thread)) != 0){ + if (rc < 0) + rc--; + else if (rc > 0) + rc++; + } } return rc; } @@ -2400,7 +2384,29 @@ RplASForCounted::RplASForCounted(RplASVarDefinition* variable) : */ bool RplASForCounted::check(RplParser& parser) { - return false; + bool rc = true; + RplASNamedValue* var = NULL; + if (m_child3 != NULL){ + var = dynamic_cast(m_child3); + if (! m_child3->check(parser)) + rc = false; + if (var == NULL) + rc = error(LOC_FORC_CHECK_1, parser, "not a variable: %s", + m_child3->nameOfItemType()); + } + RplASCalculable* expr; + if (m_child4 != NULL && ! m_child4->checkAsCalculable("start value", + RplASInteger::m_instance, parser)) + rc = false; + if (m_child5 != NULL && ! m_child5->checkAsCalculable("end value", + RplASInteger::m_instance, parser)) + rc = false; + if (m_child6 != NULL && ! m_child6->checkAsCalculable("step value", + RplASInteger::m_instance, parser)) + rc = false; + if (m_child2 != NULL && ! checkStatementList(m_child2, parser)) + rc = false; + return rc; } /** @@ -2417,15 +2423,32 @@ int RplASForCounted::execute(RplVMThread& thread) if (body == NULL) throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), "forc statement: body is not a statement"); - int start = 1; - int step = 1; - int end = 0; - RplASNamedValue* var = NULL; - if (m_child3 != NULL){ - var = dynamic_cast(m_child3); - } + int start = m_child4 == NULL ? 1 : calcAsInteger(m_child4, thread); + int end = m_child5 == NULL ? 0 : calcAsInteger(m_child5, thread); + int step = m_child6 == NULL ? 1 : calcAsInteger(m_child6, thread); + RplASNamedValue* var = m_child3 == NULL + ? NULL : dynamic_cast(m_child3); + if (thread.tracing()) + thread.vm()->traceWriter()->format("for %s from %d to %d step %d", + var == NULL ? "?" : var->name().constData(), + start, end, step); + for(int ii = start; ii <= end; ii += step){ - body->execute(thread); + //@ToDo: assign to the variable + int rc2 = body->execute(thread); + if (rc2 != 0){ + if (rc2 > 0){ + // rc comes from "break"; + rc = rc2 - 1; + } else { + // rc comes from "continue"; + if (rc2 == -1) + continue; + else + rc = rc2 + 1; + } + break; + } } return rc; } @@ -2487,7 +2510,15 @@ RplASWhile::RplASWhile() : */ bool RplASWhile::check(RplParser& parser) { - return false; + bool rc = true; + if (m_child2 == NULL) + ensureError(parser, "missing condition for 'while''"); + else + rc = m_child2->checkAsCalculable("condition", RplASBoolean::m_instance, + parser); + if (m_child3 != NULL && ! checkStatementList(m_child3, parser)) + rc = false; + return rc; } /** @@ -2501,15 +2532,23 @@ 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(), - "while statement: body is not a statement"); - RplASCondition* condition = dynamic_cast(m_child2); - if (condition == NULL) - throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), - "for statement: not a condition"); - while(condition->calcAsBool(thread)){ - body->execute(thread); + if (thread.tracing()) + thread.vm()->traceWriter()->write("while"); + while(calcAsBoolean(m_child2, thread)){ + int rc2 = body->execute(thread); + if (rc2 != 0){ + if (rc2 > 0){ + // rc comes from "break"; + rc = rc2 - 1; + } else { + // rc comes from "continue"; + if (rc2 == -1) + continue; + else + rc = rc2 + 1; + } + break; + } } return rc; } @@ -2563,7 +2602,15 @@ RplASRepeat::RplASRepeat() : */ bool RplASRepeat::check(RplParser& parser) { - return false; + bool rc = true; + if (m_child3 != NULL && ! checkStatementList(m_child3, parser)) + rc = false; + if (m_child2 == NULL) + ensureError(parser, "missing condition for 'repeat''"); + else if (! m_child2->checkAsCalculable("condition", RplASBoolean::m_instance, + parser)) + rc = false; + return rc; } /** @@ -2577,16 +2624,24 @@ 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(), - "repeat statement: body is not a statement"); - RplASCondition* condition = dynamic_cast(m_child2); - if (condition == NULL) - throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), - "repeat statement: not a condition"); + if (thread.tracing()) + thread.vm()->traceWriter()->write("repeat"); do { - body->execute(thread); - } while(condition->calcAsBool(thread)); + int rc2 = body->execute(thread); + if (rc2 != 0){ + if (rc2 > 0){ + // rc comes from "break"; + rc = rc2 - 1; + } else { + // rc comes from "continue"; + if (rc2 == -1) + continue; + else + rc = rc2 + 1; + } + break; + } + } while(! calcAsBoolean(m_child2, thread)); return rc; } @@ -2918,7 +2973,23 @@ RplASMethodCall::RplASMethodCall(const QByteArray& name, RplASItem* parent) : */ bool RplASMethodCall::check(RplParser& parser) { - return false; + bool rc = true; + RplASExprStatement* args = dynamic_cast(m_child2); + int argCount = 0; + RplASMethod* method = m_method; + RplASExprStatement* params = dynamic_cast(method->child2()); + while (args != NULL && params != NULL){ + argCount++; + RplASCalculable* argExpr = dynamic_cast(args->child2()); + if (argExpr == NULL) + rc = error(LOC_METHOD_CALL_CHECK_1, parser, + "argument %d misses expr", argCount); + else { + + } + } + + return rc; } @@ -2950,7 +3021,9 @@ void RplASMethodCall::dump(RplWriter& writer, int indent) */ int RplASMethodCall::execute(RplVMThread& thread) { - return 0; + int rc = 0; + + return rc; } RplASMethod* RplASMethodCall::method() const @@ -2972,9 +3045,9 @@ void RplASMethodCall::setMethod(RplASMethod* method) * * @return the first element of an argument list */ -RplASArgument* RplASMethodCall::arg1() const +RplASExprStatement* RplASMethodCall::arg1() const { - return dynamic_cast(m_child2); + return dynamic_cast(m_child2); } /** @class RplASException rplastree.hpp "rplexpr/rplastree.hpp" @@ -3546,64 +3619,6 @@ void RplASMethod::setSibling(RplASMethod* sibling) m_sibling = sibling; } -/** @class RplASArgument rplastree.hpp "rplexpr/rplastree.hpp" - * - * @brief Implements an argument of a method for the Abstract Syntax Tree. - * - * m_child: next argument
- * m_child2: expression - */ -/** - * @brief constructor - */ -RplASArgument::RplASArgument() : - RplASNode2(AST_ARGUMENT) -{ -} - -/** - * @brief Checks the correctness of the instance. - * - * @param parser for error processing - * @return true: node is correct
- * false: otherwise - */ -bool RplASArgument::check(RplParser& parser) -{ - return false; -} - -/** - * @brief Writes the internals of the instance into a file. - * - * @param writer writes to output - * @param no current number of the argument: 1..N - * @param indent nesting level - */ -void RplASArgument::dumpOne(RplWriter& writer, int no, int indent) -{ - int succ = m_child == NULL ? 0 : m_child->id(); - writer.formatIndented(indent, "arg %d id: %d expr: %d succ: %d", no, m_id, - child2()->id(), succ); - m_child2->dump(writer, indent + 1); -} - -/** - * @brief Writes the internals of the instance into a file. - * - * @param writer writes to output - * @param indent nesting level - */ -void RplASArgument::dump(RplWriter& writer, int indent) -{ - - RplASArgument* current = this; - int no = 0; - do { - current->dumpOne(writer, ++no, indent); - current = static_cast(current->child()); - } while (current != NULL); -} /** @class RplASField rplastree.hpp "rplexpr/rplastree.hpp" * diff --git a/rplexpr/rplastree.hpp b/rplexpr/rplastree.hpp index c7bcab9..899dfa4 100644 --- a/rplexpr/rplastree.hpp +++ b/rplexpr/rplastree.hpp @@ -112,6 +112,8 @@ private: class RplASTree; class RplParser; +class RplVMThread; + class RplASItem { public: @@ -134,6 +136,8 @@ public: public: virtual bool check(RplParser& parser) = 0; public: + bool checkAsCalculable(const char* description, RplASClass* expectedClass, + RplParser& parser); const RplSourcePosition* position() const; void setPosition(const RplSourcePosition* position); unsigned int id() const; @@ -150,6 +154,8 @@ public: public: static void reset(); static bool checkStatementList(RplASItem* list, RplParser& parser); + static int calcAsInteger(RplASItem* expr, RplVMThread& thread); + static bool calcAsBoolean(RplASItem* expr, RplVMThread& thread); public: RplASItemType nodeType() const; const char* nameOfItemType() const; @@ -171,7 +177,6 @@ private: }; class RplASNode1; -class RplVMThread; class RplASCalculable { public: @@ -515,23 +520,12 @@ public: void dump(RplWriter& writer, int indent); private: void assign(RplVMThread& thread); +public: static const char* nameOfOp(BinOperator op); private: BinOperator m_operator; }; -class RplASCondition : public RplASNode1, public RplASCalculable -{ -public: - RplASCondition(); -public: - virtual void calc(RplVMThread& thread); - virtual bool check(RplParser& parser); -public: - bool calcAsBool(RplVMThread& thread); - void dump(RplWriter& writer, int indent); -}; - class RplASIf : public RplASNode4, public RplASStatement { public: @@ -582,18 +576,6 @@ public: virtual void dump(RplWriter& writer, int indent); }; -class RplASArgument : public RplASNode2 -{ -public: - RplASArgument(); -public: - virtual bool check(RplParser& parser); -public: - void dump(RplWriter& writer, int indent); -protected: - void dumpOne(RplWriter& writer, int no, int indent); -}; - class RplASMethod; class RplASMethodCall : public RplASNode3, public RplASStatement { @@ -609,7 +591,7 @@ public: RplASMethod* method() const; void setMethod(RplASMethod* method); - RplASArgument*arg1() const; + RplASExprStatement* arg1() const; private: QByteArray m_name; RplASMethod* m_method; diff --git a/rplexpr/rplmfparser.cpp b/rplexpr/rplmfparser.cpp index 0a7aa99..9f3f5ec 100644 --- a/rplexpr/rplmfparser.cpp +++ b/rplexpr/rplmfparser.cpp @@ -252,8 +252,10 @@ RplASItem* RplMFParser::parseFor() * @pre first token of the definition is read * @post token behind the definition is read: ';', ',', ')' * @param attribute attribute of the variable: A_PARAM... + * @return a variable/parameter definition */ -RplASItem* RplMFParser::parseVarDefinition(RplASNamedValue::Attributes attribute) +RplASVarDefinition* RplMFParser::parseVarDefinition( + RplASNamedValue::Attributes attribute) { int attributes = attribute; RplToken* token = m_lexer.currentToken(); @@ -688,7 +690,7 @@ RplASItem* RplMFParser::parseOperand(int level, RplASItem* parent) token = m_lexer.nextNonSpaceToken(); if (! token->isOperator(O_RPARENTH)){ m_lexer.undoLastToken(); - RplASArgument* args = parseArguments(); + RplASExprStatement* args = parseArguments(); call->setChild2(args); readNext = false; } @@ -940,6 +942,11 @@ RplASItem* RplMFParser::parseExprStatement(bool eatSemicolon) return statement; } +/** + * @brief Parses a local variable. + * + * @return the variable definition + */ RplASItem* RplMFParser::parseLocalVar(){ RplASItem* rc = parseVarDefinition(RplASNamedValue::A_NONE); return rc; @@ -1095,17 +1102,15 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, * @post token behind ')' is read * @return */ -RplASExprStatement* RplMFParser::parseParameterList(){ - RplASExprStatement* rc = NULL; - RplASExprStatement* last = NULL; +RplASVarDefinition* RplMFParser::parseParameterList(){ + RplASVarDefinition* rc = NULL; + RplASVarDefinition* last = NULL; const RplSourcePosition* startPos = m_lexer.currentPosition(); RplASItem* definition = NULL; do { if (definition != NULL) m_lexer.nextNonSpaceToken(); - definition = parseVarDefinition(RplASNamedValue::A_PARAM); - RplASExprStatement *current = new RplASExprStatement(); - current->setChild2(definition); + RplASVarDefinition* current = parseVarDefinition(RplASNamedValue::A_PARAM); if (rc == NULL){ rc = current; } else { @@ -1150,7 +1155,7 @@ void RplMFParser::parseMethod() if (! token->isOperator(O_LPARENTH, O_COLON)) syntaxError(L_PARSE_METH_NO_LPARENTH, "'(' or ':' expected"); - RplASExprStatement* parameterList = NULL; + RplASVarDefinition* parameterList = NULL; method = new RplASMethod(name, m_tree); method->setPosition(startPos); RplSymbolSpace* symbols = m_tree.currentSpace(); @@ -1254,17 +1259,17 @@ void RplMFParser::parse() * @post the token behind the ')' is read * @return the first element of the argument list */ -RplASArgument* RplMFParser::parseArguments() +RplASExprStatement* RplMFParser::parseArguments() { - RplASArgument* first = NULL; - RplASArgument* last = NULL; + RplASExprStatement* first = NULL; + RplASExprStatement* last = NULL; bool again = false; do { RplASItem* expr = parseExpr(0); if (! m_lexer.currentToken()->isOperator(O_COMMA, O_RPARENTH)) syntaxError(L_PARSE_ARGS_NO_COMMA_OR_PARENT, "',' or ')' expected"); again = m_lexer.currentToken()->isOperator(O_COMMA); - RplASArgument* current = new RplASArgument(); + RplASExprStatement* current = new RplASExprStatement(); current->setPosition(expr->position()); current->setChild2(expr); if (first == NULL) diff --git a/rplexpr/rplmfparser.hpp b/rplexpr/rplmfparser.hpp index 900cc60..d1d9d61 100644 --- a/rplexpr/rplmfparser.hpp +++ b/rplexpr/rplmfparser.hpp @@ -71,7 +71,7 @@ public: RplASItem* parseWhile(); RplASItem* parseRepeat(); RplASItem* parseFor(); - RplASItem* parseVarDefinition(RplASNamedValue::Attributes attribute); + RplASVarDefinition* parseVarDefinition(RplASNamedValue::Attributes attribute); RplASItem* parseExpr(int depth); RplASItem* parseBody(Keyword keywordStop, Keyword keywordStop2 = K_UNDEF, int builtinVars = 0); @@ -84,7 +84,7 @@ public: RplASItem*parseList(); RplASItem*parseMap(); protected: - RplASArgument* parseArguments(); + RplASExprStatement* parseArguments(); RplASItem* parseOperand(int level, RplASItem* parent = NULL); RplASVariant* tokenToVariant(RplToken* token, bool endsWithComma, RplASNode1* parent); @@ -92,7 +92,7 @@ protected: RplASItem* buildVarOrField(const QByteArray& name, const RplSourcePosition* position, RplASItem* parent); - RplASExprStatement*parseParameterList(); + RplASVarDefinition* parseParameterList(); RplASItem* parseLocalVar(); RplASVarDefinition* buildVarDef(RplASNamedValue* var); protected: diff --git a/test/mfparser/meth2.txt b/test/mfparser/meth2.txt index bd20165..cd21833 100644 --- a/test/mfparser/meth2.txt +++ b/test/mfparser/meth2.txt @@ -3,35 +3,34 @@ Int rc; if rc <= 1 then rc = 1 else rc = n*fac(n-1) fi rc endf = (module) parent: $global == Methods: -Method fac() id: 1 parent: args: 4 body: 6 :0:55 - Expr id: 4 expr: 3 succ: 0 - varDef Int n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 - namedValue n id: 2 attr: 0x22 :1:23 - varDef Int rc id: 6 namedValue: 5 value: 0 succ: 7 :2:4 - namedValue rc id: 5 attr: 0x0 :2:4 - If id: 7 condition: 9 then: 14 else: 24 succ: 26:2:8 - BinOp id: 9 op: <= (34) left: 8 right: 10 :2:14 - namedValue rc id: 8 attr: 0x0 :2:14 - const id: 10 value: 1 :2:17 - Expr id: 14 expr: 12 succ: 0 :2:27 - BinOp id: 12 op: = (1) left: 11 right: 13 :2:27 - namedValue rc id: 11 attr: 0x0 :2:27 - const id: 13 value: 1 :2:29 - Expr id: 24 expr: 16 succ: 0 :2:39 - BinOp id: 16 op: = (1) left: 15 right: 18 :2:39 - namedValue rc id: 15 attr: 0x0 :2:39 - BinOp id: 18 op: * (19) left: 17 right: 19 :2:42 - namedValue n id: 17 attr: 0x0 :2:42 - call fac Id: 19 args: 23 parent: 0 succ: 0 :2:46 - arg 1 id: 23 expr: 21 succ: 0 - BinOp id: 21 op: - (18) left: 20 right: 22 :2:48 - namedValue n id: 20 attr: 0x0 :2:48 - const id: 22 value: 1 :2:49 - Expr id: 26 expr: 25 succ: 0 :3:3 - namedValue rc id: 25 attr: 0x0 :3:3 +Method fac() id: 1 parent: args: 3 body: 5 :0:55 + varDef Int n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + namedValue n id: 2 attr: 0x22 :1:23 + varDef Int rc id: 5 namedValue: 4 value: 0 succ: 6 :2:4 + namedValue rc id: 4 attr: 0x0 :2:4 + If id: 6 condition: 8 then: 13 else: 23 succ: 25:2:8 + BinOp id: 8 op: <= (34) left: 7 right: 9 :2:14 + namedValue rc id: 7 attr: 0x0 :2:14 + const id: 9 value: 1 :2:17 + Expr id: 13 expr: 11 succ: 0 :2:27 + BinOp id: 11 op: = (1) left: 10 right: 12 :2:27 + namedValue rc id: 10 attr: 0x0 :2:27 + const id: 12 value: 1 :2:29 + Expr id: 23 expr: 15 succ: 0 :2:39 + BinOp id: 15 op: = (1) left: 14 right: 17 :2:39 + namedValue rc id: 14 attr: 0x0 :2:39 + BinOp id: 17 op: * (19) left: 16 right: 18 :2:42 + namedValue n id: 16 attr: 0x0 :2:42 + call fac Id: 18 args: 22 parent: 0 succ: 0 :2:46 + Expr id: 22 expr: 20 succ: 0 :2:48 + BinOp id: 20 op: - (18) left: 19 right: 21 :2:48 + namedValue n id: 19 attr: 0x0 :2:48 + const id: 21 value: 1 :2:49 + Expr id: 25 expr: 24 succ: 0 :3:3 + namedValue rc id: 24 attr: 0x0 :3:3 = .fac (method) parent: == Variables: varDef Int n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 namedValue n id: 2 attr: 0x22 :1:23 - varDef Int rc id: 6 namedValue: 5 value: 0 succ: 7 :2:4 - namedValue rc id: 5 attr: 0x0 :2:4 + varDef Int rc id: 5 namedValue: 4 value: 0 succ: 6 :2:4 + namedValue rc id: 4 attr: 0x0 :2:4 diff --git a/unittests/rplastree_test.cpp b/unittests/rplastree_test.cpp index 614a333..7ace6e3 100644 --- a/unittests/rplastree_test.cpp +++ b/unittests/rplastree_test.cpp @@ -84,18 +84,7 @@ public: RplASNamedValue::A_GLOBAL); checkE("gugo", value.name()); } - void testRplASCondition(){ - RplASCondition cond; - RplASConstant* constant = new RplASConstant(); - constant->value().setString("True"); - cond.setChild(constant); - //checkT(cond.calcAsBool()); - constant->value().setInt(0); - //checkF(cond.calcAsBool()); - } - virtual void doIt() { - testRplASCondition(); testRplASNamedValue(); testRplASConstant(); testRplASException();