From: hama Date: Wed, 3 Sep 2014 21:32:17 +0000 (+0200) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=e1e67108320bd8cb5f19a488dd30aadfeefbb73c;p=reqt dayly work --- diff --git a/rplexpr/rplastree.cpp b/rplexpr/rplastree.cpp index 3db6a3e..b1d1cda 100644 --- a/rplexpr/rplastree.cpp +++ b/rplexpr/rplastree.cpp @@ -21,23 +21,30 @@ enum { LOC_VARDEF_EXEC_1 = RPL_FIRST_OF(RPL_MODULE_ASTREE), // 11001 - LOC_UNOP_1, - LOC_UNOP_2, - LOC_UNOP_3, - LOC_UNOP_4, // 10005 + LOC_UNOP_CALC_1, + LOC_UNARY_CHECK_1, + LOC_UNARY_CHECK_2, + LOC_UNARY_CHECK_3, // 11005 LOC_BINOP_1, LOC_BINOP_CALC_1, LOC_BINOP_CALC_2, LOC_BINOP_CALC_3, - LOC_BINOP_CALC_4, + LOC_BINOP_CALC_4, // 11010 LOC_BINOP_CALC_5, LOC_BINOP_CALC_6, LOC_BINOP_CALC_7, LOC_BINOP_CALC_8, - LOC_BINOP_CALC_9, + LOC_BINOP_CALC_9, // 11015 LOC_BINOP_CALC_10, LOC_BINOP_CALC_11, LOC_BINOP_CALC_12, + LOC_VARDEF_CHECK_1, + LOC_VARDEF_CHECK_2, // 11020 + LOC_CONV_CHECK_1, + LOC_CONV_CHECK_2, + LOC_CONV_TRY_1, + LOC_ITEM_FORCE_ERROR_1, + LOC_UNARY_CHECK_4, // 11025 LOC_COUNT }; @@ -686,12 +693,86 @@ void RplASItem::setFlags(int flags) m_flags = flags; } +/** + * @brief Tests the compatibility of 2 data types. + * @param class1 1st class to inspect + * @param class2 2nd class to inspect + * @return true: classes are compatible
+ * false: otherwise + */ +bool RplASItem::typeCheck(RplASClass* class1, RplASClass* class2){ + bool rc; + if (class1 == NULL || class2 == NULL) + rc = false; + else + //@ToDo: subclasses + rc = class1 == class2; + return rc; +} + +/** + * @brief Issues an error message. + * + * @param location an error specific id + * @param parser for error processing + * @param format the error message with placeholders (like printf) + * @param ... the values for the placeholders + * @return false (for chaining) + */ +bool RplASItem::error(int location, RplParser& parser, const char* format, ...) +{ + va_list varList; + va_start(varList, format); + parser.addMessage(RplParser::LT_ERROR, location, m_position, format, varList); + va_end(varList); + return false; +} + +/** + * @brief Ensures the occurrence of an error. + * + * When called a previous error should be happend. If not an internal error + * will be issued. + * + * @param parser for error processing + * @return false (for chaining) + */ +bool RplASItem::ensureError(RplParser& parser) +{ + if (parser.errors() == 0) + error(LOC_ITEM_FORCE_ERROR_1, parser, "lost error (internal error)"); + return false; +} /** @class RplASCalculable rplastree.hpp "rplexpr/rplastree.hpp" * * @brief An abstract base class for items which calculates a value. * */ +/** + * @brief Constructor. + */ +RplASCalculable::RplASCalculable() : + m_class(NULL) +{ +} +/** + * @brief Returns the class of the node + * @return the class + */ + +RplASClass* RplASCalculable::clazz() const +{ + return m_class; +} +/** + * @brief Sets the class of the node. + * @param clazz the new class + */ +void RplASCalculable::setClass(RplASClass* clazz) +{ + m_class = clazz; +} /** @class RplASStorable rplastree.hpp "rplexpr/rplastree.hpp" * @@ -726,6 +807,17 @@ void RplASConstant::calc(RplVMThread& thread) value.copyValue(m_value); } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: a constant is always correct + */ +bool RplASConstant::check(RplParser& parser) +{ + return true; +} + /** * @brief Writes the internals into a file. * @@ -793,6 +885,17 @@ void RplASListConstant::calc(RplVMThread& thread) value.copyValue(m_value); } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: a constant is always correct + */ +bool RplASListConstant::check(RplParser& parser) +{ + return true; +} + /** * @brief Writes the internals into a file. * @@ -850,6 +953,17 @@ void RplASMapConstant::calc(RplVMThread& thread) RplASVariant& value = thread.reserveValue(); value.copyValue(m_value); } + +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: a constant is always correct + */ +bool RplASMapConstant::check(RplParser& parser) +{ + return true; +} /** * @brief Writes the internals into a file. * @@ -908,7 +1022,6 @@ RplASNamedValue::RplASNamedValue(RplASClass* dataType,RplSymbolSpace* space, RplASNode1(AST_NAMED_VALUE), m_name(name), m_attributes(attributes), - m_dataType(dataType), m_symbolSpace(space), m_variableNo(-1) { @@ -943,6 +1056,18 @@ void RplASNamedValue::calc(RplVMThread& thread) { thread.valueToTop(m_symbolSpace, m_variableNo); } + +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASNamedValue::check(RplParser& parser) +{ + return true; +} /** * @brief Writes the internals into a file. * @@ -956,25 +1081,6 @@ void RplASNamedValue::dump(RplWriter& writer, int indent) m_name.constData(), m_id, m_attributes, positionStr(buffer, sizeof buffer)); } -/** - * @brief Returns the data type (class) of the instance. - * - * @return the data type - */ -RplASClass* RplASNamedValue::dataType() const -{ - return m_dataType; -} - -/** - * @brief Assigns the top of stack of the thread to the instance. - * - * @param thread the execution unit, a virtual machine thread - */ -void RplASNamedValue::assign(RplVMThread& thread) -{ - -} /** * @brief Returns the symbol space of the variable. @@ -1007,11 +1113,170 @@ int RplASNamedValue::variableNo() const return m_variableNo; } +/** @class RplASConversion rplastree.hpp "rplexpr/rplastree.hpp" + * + * @brief Implements a data type conversion. + * + * m_child: the expression which will be converted + */ +/** + * @brief Constructor. + * @param expression the expression to convert + */ +RplASConversion::RplASConversion(RplASItem* expression) : + RplASNode1(AST_CONVERSION), + m_conversion(C_UNDEF) +{ + m_child = expression; + m_position = expression->position(); +} + +/** + * @brief Convert an expression to another data type. + * + * Possible conversions: @see RplASConversion::Conversion + * + * @param thread execution value + */ +void RplASConversion::calc(RplVMThread& thread) +{ + RplASCalculable* expr = dynamic_cast(m_child); + expr->calc(thread); + RplASVariant& value = thread.topOfValues(); + switch(m_conversion){ + case C_INT_TO_FLOAT: + value.setFloat((qreal) value.asInt()); + break; + case C_FLOAT_TO_INT: + value.setInt((int) value.asFloat()); + break; + case C_BOOL_TO_INT: + value.setInt((int) value.asBool()); + break; + case C_BOOL_TO_FLOAT: + value.setFloat((qreal) value.asBool()); + break; + default: + break; + } +} + +/** + * @brief Returns the conversion type of two classes. + * + * @param from class to convert + * @param to result class of the conversion + * + * @return C_UNDEF: not convertable
+ * otherwise: the conversion type + */ +RplASConversion::Conversion RplASConversion::findConversion(RplASClass* from, + RplASClass* to) +{ + Conversion rc = C_UNDEF; + if (from == RplASFloat::m_instance){ + if (to == RplASInteger::m_instance) + rc = C_FLOAT_TO_INT; + } else if (from == RplASInteger::m_instance){ + if (to == RplASFloat::m_instance) + rc = C_INT_TO_FLOAT; + } else if (from == RplASBoolean::m_instance){ + if (to == RplASInteger::m_instance) + rc = C_BOOL_TO_INT; + else if (to == RplASInteger::m_instance) + rc = C_BOOL_TO_INT; + else if (to == RplASFloat::m_instance) + rc = C_BOOL_TO_FLOAT; + } + return rc; +} + +/** + * @brief Checks the node. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASConversion::check(RplParser& parser) +{ + bool rc = false; + RplASCalculable* expr = dynamic_cast(m_child); + if (expr == NULL){ + parser.error(LOC_CONV_CHECK_1, "missing expr"); + } else { + RplASClass* from = expr->clazz(); + rc = m_child->check(parser); + if (rc){ + m_conversion = findConversion(from, m_class); + if (m_conversion != C_UNDEF) + rc = true; + else + parser.error(LOC_CONV_CHECK_2, + "invalid data type conversion: %s -> %s", + from->name().constData(), + m_class->name().constData()); + } + } + return rc; +} + +/** + * @brief Writes the internals into a file. + * + * @param writer writes to output + * @param indent nesting level + */ +void RplASConversion::dump(RplWriter& writer, int indent) +{ + char buffer[256]; + writer.formatIndented(indent, "conversion %s id: %d expr: %d %s", + m_class->name().constData(), m_id, m_child->id(), + positionStr(buffer, sizeof buffer)); +} + +/** + * @brief Tries to find a conversion to a given type. + * + * Checks if an expression has a given type. If not it will be tried to find + * a conversion. If this is not possible an error occurres. Otherwise the + * converter will be returned. + * + * @param expected the expected data type + * @param expr the expression to convert + * @param parser for error processing + * + * @return NULL: no conversion necessary
+ * otherwise: a converter to the given type + */ +RplASConversion* RplASConversion::tryConversion(RplASClass* expected, + RplASItem* expr, RplParser& parser) +{ + RplASConversion* rc = NULL; + if (expr->check(parser)){ + RplASCalculable* expr2 = dynamic_cast(expr); + if (expr2 != NULL){ + Conversion type = findConversion(expr2->clazz(), expected); + if (type == C_UNDEF){ + parser.error(LOC_CONV_TRY_1, + "invalid data type conversion: %s -> %s", + expr2->clazz()->name().constData(), + expected->name().constData()); + } else if (expr2->clazz() != expected){ + rc = new RplASConversion(expr); + rc->m_conversion = type; + rc->setClass(expected); + } + } + } + return rc; +} + /** @class RplASIndexedValue rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an indexed values (member of a list) * - * m_child: the parent: a list expression + * m_child: the parent: a list/map expression * m_child2: the index expression */ RplASIndexedValue::RplASIndexedValue() : @@ -1019,6 +1284,32 @@ RplASIndexedValue::RplASIndexedValue() : { } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASIndexedValue::check(RplParser& parser) +{ + bool rc = false; + RplASCalculable* list = dynamic_cast(m_child); + if (list == NULL) + throw RplASException(m_position, "indexed value: empty list"); + m_child->check(parser); + RplASConversion* converter = RplASConversion::tryConversion( + RplASInteger::m_instance, m_child, parser); + if (converter == NULL){ + RplASClass* clazz = list->clazz(); + rc = clazz != NULL && clazz == RplASInteger::m_instance; + } else { + m_child = converter; + rc = true; + } + return rc; +} + /** * @brief Writes the internals into an output media. * @@ -1070,9 +1361,9 @@ void RplASVarDefinition::dump(RplWriter& writer, int indent) if (m_endOfScope > 0) qsnprintf(endOfScope, sizeof endOfScope, "-%d:0", m_endOfScope); char buffer[256]; - writer.formatIndented(indent, "varDef %s %s id: %d namedValue: %d value: %d succ: %d %s%s", - namedValue == NULL || namedValue->dataType() == NULL - ? "?" : namedValue->dataType()->name().constData(), + writer.formatIndented(indent, + "varDef %s %s id: %d namedValue: %d value: %d succ: %d %s%s", + clazz() == NULL ? "?" : clazz()->name().constData(), name.constData(), m_id, m_child2 == NULL ? 0 : m_child2->id(), m_child3 == NULL ? 0 : m_child3->id(), @@ -1101,10 +1392,10 @@ const QByteArray& RplASVarDefinition::name() const * * @return the data type */ -RplASClass* RplASVarDefinition::datatype() const +RplASClass* RplASVarDefinition::clazz() const { RplASNamedValue* namedValue = dynamic_cast(m_child2); - RplASClass* rc = namedValue->dataType(); + RplASClass* rc = namedValue == NULL ? NULL : namedValue->clazz(); return rc; } /** @@ -1131,28 +1422,58 @@ void RplASVarDefinition::setEndOfScope(int endOfScope) /** - * @brief Executes the statement. + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise */ -void RplASVarDefinition::execute(RplVMThread& thread) +bool RplASVarDefinition::check(RplParser& parser) { + bool rc = false; if (m_child3 != NULL){ RplASNamedValue* var = dynamic_cast(m_child2); if (var == NULL) - error(thread.logger(), LOC_VARDEF_EXEC_1, - "Not a named value: id: %d", + error(LOC_VARDEF_CHECK_1, parser, "Not a named value: id: %d", m_child2 == NULL ? 0 : m_child2->id()); else{ - RplASCalculable* expr = dynamic_cast(m_child3); - if (expr == NULL) - error(thread.logger(), LOC_VARDEF_EXEC_1, - "not calculable: id: %d", - m_child3 == NULL ? 0 : m_child2->id()); + if (m_child3 == NULL) + // no initialization: + rc = true; else { - expr->calc(thread); - var->assign(thread); + rc = m_child3->check(parser); + if (rc){ + RplASCalculable* expr = dynamic_cast(m_child3); + if (! typeCheck(var->clazz(), expr->clazz())) + rc = error(LOC_VARDEF_CHECK_2, parser, + "data types are not compatible: %s/%s", + var->clazz()->name().constData(), + expr->clazz() == NULL ? "?" + : expr->clazz()->name().constData()); + } } } } + return rc; +} + +/** + * @brief Executes the statement. + */ +void RplASVarDefinition::execute(RplVMThread& thread) +{ + RplASNamedValue* var = dynamic_cast(m_child2); + RplASCalculable* expr = dynamic_cast(m_child3); + expr->calc(thread); + RplASVariant& value = thread.popValue(); + RplASVariant& destination = thread.valueOfVariable( + var->m_symbolSpace, var->m_variableNo); + if (thread.tracing()) + thread.vm()->traceWriter()->format("%s = %.80s [%.80s]", + var->m_name.constData(), + value.toString().constData(), + destination.toString().constData()); + destination.copyValue(value); } /** @class RplASExprStatement rplastree.hpp "rplexpr/rplastree.hpp" @@ -1173,12 +1494,30 @@ RplASExprStatement::RplASExprStatement() : m_flags |= NF_STATEMENT; } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASExprStatement::check(RplParser& parser) +{ + bool rc = m_child2->check(parser); + RplASCalculable* expr = dynamic_cast (m_child2); + if (expr == NULL) + rc = false; + return rc; +} /** * @brief Executes the statement. */ void RplASExprStatement::execute(RplVMThread& thread) { - + RplASCalculable* expr = dynamic_cast (m_child2); + expr->calc(thread); + RplASVariant& value = thread.popValue(); + value.destroyValue(); } /** @@ -1240,6 +1579,8 @@ RplASItem* RplASNode1::child() const */ void RplASNode1::setChild(RplASItem* child) { + if (child->id() == 2) + m_child = child; m_child = child; } @@ -1486,7 +1827,9 @@ void RplASNode6::setChild6(RplASItem* child6) * * @brief Implements an unary operation. * - * This is an operation with one operand, e.g. the boolean not operation. + * This is an operation with one operand, e.g. the boolean 'not' operation. + * + * m_child: operand */ /** @@ -1512,60 +1855,83 @@ void RplASUnaryOp::calc(RplVMThread& thread) switch(m_operator){ case UOP_PLUS: break; - case UOP_MINUS: - switch (value.variantType()){ - case RplASVariant::VT_FLOAT: - value.setFloat(- value.asFloat()); - break; - case RplASVariant::VT_INTEGER: - value.setInt(- value.asInt()); - break; - case RplASVariant::VT_BOOL: - case RplASVariant::VT_OBJECT: - default: - error(thread.logger(), LOC_UNOP_1, "wrong type %s for '-'", - value.nameOfType()); - break; - } + case UOP_MINUS_INT: + value.setInt(- value.asInt()); break; - case UOP_LOGICAL_NOT: - switch (value.variantType()){ - case RplASVariant::VT_FLOAT: - value.setBool(value.asFloat() != 0.0); - break; - case RplASVariant::VT_INTEGER: - value.setBool(value.asInt() != 0); - break; - case RplASVariant::VT_BOOL: - value.setBool(! value.asBool()); - break; - case RplASVariant::VT_OBJECT: - default: - error(thread.logger(), LOC_UNOP_2, "wrong type %s for '!'", - value.nameOfType()); - break; - } + case UOP_MINUS_FLOAT: + value.setFloat(- value.asFloat()); break; - case UOP_BIT_NOT: - switch (value.variantType()){ - case RplASVariant::VT_INTEGER: - value.setInt(~value.asInt()); - break; - case RplASVariant::VT_FLOAT: - case RplASVariant::VT_BOOL: - case RplASVariant::VT_OBJECT: - default: - error(thread.logger(), LOC_UNOP_3, "wrong type %s for '~'", - value.nameOfType()); - break; - } + case UOP_NOT_BOOL: + value.setBool(! value.asBool()); + break; + case UOP_NOT_INT: + value.setInt(~value.asInt()); break; + case UOP_DEC: + case UOP_INC: default: - error(thread.logger(), LOC_UNOP_4, "unknown operator: %d", m_operator); + error(thread.logger(), LOC_UNOP_CALC_1, "unknown operator: %d", m_operator); break; } } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASUnaryOp::check(RplParser& parser) +{ + bool rc = m_child->check(parser); + if (rc){ + RplASCalculable* expr = dynamic_cast(m_child); + RplASClass* clazz = expr == NULL ? NULL : expr->clazz(); + if (clazz == NULL){ + rc = ensureError(parser); + } else { + switch(m_operator){ + case UOP_PLUS: + if (clazz != RplASInteger::m_instance + && clazz != RplASFloat::m_instance) + rc = error(LOC_UNARY_CHECK_1, parser, + "wrong data type for unary operator '+': %s", + clazz->name().constData()); + break; + case UOP_MINUS_INT: + if (clazz != RplASFloat::m_instance) + m_operator = UOP_MINUS_FLOAT; + else if (clazz != RplASInteger::m_instance) + rc = error(LOC_UNARY_CHECK_2, parser, + "wrong data type for unary operator '-': %s", + clazz->name().constData()); + break; + case UOP_NOT_BOOL: + if (clazz != RplASBoolean::m_instance) + rc = error(LOC_UNARY_CHECK_3, parser, + "wrong data type for unary operator '!': %s", + clazz->name().constData()); + break; + case UOP_NOT_INT: + if (clazz != RplASInteger::m_instance) + rc = error(LOC_UNARY_CHECK_4, parser, + "wrong data type for unary operator '!': %s", + clazz->name().constData()); + break; + case UOP_DEC: + break; + case UOP_INC: + break; + default: + throw RplASException(position(), "unknown operator: %d", m_operator); + break; + } + } + } + return rc; +} + /** * @brief Returns the operator of the unary operation. * @@ -1597,7 +1963,7 @@ void RplASUnaryOp::dump(RplWriter& writer, int indent) /** * @brief Returns the name (a string) of an unary operator. * - * @param op the op to convert + * @param op the operand to convert * @return the name of the operator */ const char*RplASUnaryOp::nameOfOp(RplASUnaryOp::UnaryOp op) @@ -1607,13 +1973,14 @@ const char*RplASUnaryOp::nameOfOp(RplASUnaryOp::UnaryOp op) case UOP_PLUS: rc="+"; break; - case UOP_MINUS: + case UOP_MINUS_INT: + case UOP_MINUS_FLOAT: rc="-"; break; - case UOP_LOGICAL_NOT: + case UOP_NOT_BOOL: rc="!"; break; - case UOP_BIT_NOT: + case UOP_NOT_INT: rc="~"; break; case UOP_INC: @@ -1674,6 +2041,18 @@ void RplASCondition::calc(RplVMThread& thread) throw RplASException(m_position, "child of condition is not calculable"); node->calc(thread); } + +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASCondition::check(RplParser& parser) +{ + return false; +} /** * @brief Calculates the boolean value and returns it. */ @@ -1735,6 +2114,18 @@ RplASIf::RplASIf() : m_flags |= NF_STATEMENT; } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASIf::check(RplParser& parser) +{ + return false; +} + /** * @brief Executes the statement. * @@ -1813,6 +2204,18 @@ RplASForIterated::RplASForIterated(RplASVarDefinition* variable) : m_child2 = variable; } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASForIterated::check(RplParser& parser) +{ + return false; +} + /** * @brief Executes the statement. * @@ -1876,6 +2279,18 @@ RplASForCounted::RplASForCounted(RplASVarDefinition* variable) : m_child3 = variable; } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASForCounted::check(RplParser& parser) +{ + return false; +} + /** * @brief Executes the statement. * @@ -1946,6 +2361,18 @@ RplASWhile::RplASWhile() : m_flags |= NF_STATEMENT; } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASWhile::check(RplParser& parser) +{ + return false; +} + /** * @brief Executes the statement. * @@ -2006,6 +2433,18 @@ RplASRepeat::RplASRepeat() : m_flags |= NF_STATEMENT; } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASRepeat::check(RplParser& parser) +{ + return false; +} + /** * @brief Executes the statement. * @@ -2347,6 +2786,18 @@ RplASMethodCall::RplASMethodCall(const QByteArray& name, RplASItem* parent) : m_child3 = parent; } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASMethodCall::check(RplParser& parser) +{ + return false; +} + /** * @brief Writes the internals into a file. @@ -2603,6 +3054,18 @@ void RplASBinaryOp::calc(RplVMThread& thread) } } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASBinaryOp::check(RplParser& parser) +{ + return false; +} + /** * @brief Returns the operator. * @@ -2837,6 +3300,27 @@ RplASMethod::RplASMethod(const QByteArray& name, RplASTree& tree) : { } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASMethod::check(RplParser& parser) +{ + return false; +} + +/** + * @brief Executes the statement. + * + * This method will be never called. Must exit: Otherwise the class is abstract. + */ +void RplASMethod::execute(RplVMThread& thread) +{ +} + /** * @brief Writes the internals of the instance into a file. @@ -2908,7 +3392,7 @@ bool RplASMethod::equalSignature(RplASMethod& other) const else { RplASVarDefinition* def = dynamic_cast(args->child2()); RplASVarDefinition* defOther = dynamic_cast(otherArgs->child2()); - if (def->datatype() != defOther->datatype()) + if (def->clazz() != defOther->clazz()) rc = false; } } @@ -2950,6 +3434,18 @@ RplASArgument::RplASArgument() : { } +/** + * @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. * @@ -3000,6 +3496,18 @@ RplASField::RplASField(const QByteArray& name) : { } +/** + * @brief Checks the correctness of the instance. + * + * @param parser for error processing + * @return true: node is correct
+ * false: otherwise + */ +bool RplASField::check(RplParser& parser) +{ + return false; +} + /** * @brief Writes the internals of the instance into a file. * diff --git a/rplexpr/rplastree.hpp b/rplexpr/rplastree.hpp index 96492a5..a12554e 100644 --- a/rplexpr/rplastree.hpp +++ b/rplexpr/rplastree.hpp @@ -18,6 +18,7 @@ enum RplASItemType { AST_MAP_CONSTANT, AST_MAP_ENTRY, AST_NAMED_VALUE, + AST_CONVERSION, AST_INDEXED_VALUE, AST_FIELD, AST_VAR_DEFINITION, @@ -110,6 +111,7 @@ private: }; class RplASTree; +class RplParser; class RplASItem { public: @@ -129,6 +131,8 @@ public: friend class RplASTree; RplASItem(RplASItemType type); virtual ~RplASItem(); +public: + virtual bool check(RplParser& parser) = 0; public: const RplSourcePosition* position() const; void setPosition(const RplSourcePosition* position); @@ -151,6 +155,9 @@ public: int flags() const; void setFlags(int flags); + bool typeCheck(RplASClass* clazz1, RplASClass* clazz2); + bool error(int location, RplParser& parser, const char* format, ...); + bool ensureError(RplParser& parser); protected: unsigned int m_id:16; RplASItemType m_nodeType:8; @@ -165,12 +172,19 @@ class RplASNode1; class RplVMThread; class RplASCalculable { +public: + RplASCalculable(); public: virtual void calc(RplVMThread& thread) = 0; +public: + RplASClass* clazz() const; + void setClass(RplASClass* clazz); +protected: + RplASClass* m_class; }; class RplStackFrame; -class RplASStorable : RplASCalculable { +class RplASStorable : public RplASCalculable { }; class RplVMThread; class RplASConstant : public RplASItem, public RplASCalculable @@ -179,6 +193,7 @@ public: RplASConstant(); public: virtual void calc(RplVMThread& thread); + virtual bool check(RplParser& parser); public: virtual void dump(RplWriter& writer,int indent); RplASVariant& value(); @@ -272,6 +287,8 @@ public: RplASListConstant(); public: virtual void calc(RplVMThread& thread); + virtual bool check(RplParser& parser); + public: virtual void dump(RplWriter& writer,int indent); RplASVariant& value(); @@ -285,6 +302,7 @@ public: RplASMapConstant(); public: virtual void calc(RplVMThread& thread); + virtual bool check(RplParser& parser); public: virtual void dump(RplWriter& writer,int indent); RplASVariant& value(); @@ -296,6 +314,7 @@ private: class RplSymbolSpace; class RplASNamedValue : public RplASNode1, public RplASStorable { + friend class RplASVarDefinition; public: enum Attributes { A_NONE, @@ -316,27 +335,51 @@ public: public: RplASNamedValue(RplASClass* dataType, RplSymbolSpace* space, const QByteArray& name, int attributes); +public: + virtual void calc(RplVMThread& thread); + virtual bool check(RplParser& parser); public: const QByteArray& name() const; void setSymbolSpace(RplSymbolSpace* space, int variableNo); - virtual void calc(RplVMThread& thread); void dump(RplWriter& writer, int indent); - RplASClass* dataType() const; - void assign(RplVMThread& thread); RplSymbolSpace* symbolSpace() const; int variableNo() const; void setVariableNo(int variableNo); protected: QByteArray m_name; int m_attributes; - RplASClass* m_dataType; RplSymbolSpace* m_symbolSpace; int m_variableNo; }; +class RplASConversion : public RplASNode1, public RplASCalculable { +public: + enum Conversion { + C_UNDEF, + C_INT_TO_FLOAT, + C_FLOAT_TO_INT, + C_BOOL_TO_INT, + C_BOOL_TO_FLOAT + }; + +public: + RplASConversion(RplASItem* expression); +public: + virtual void calc(RplVMThread& thread); + virtual bool check(RplParser& parser); + virtual void dump(RplWriter& writer,int indent); +public: + static RplASConversion* tryConversion(RplASClass* expected, RplASItem* expr, + RplParser& parser); + static Conversion findConversion(RplASClass* from, RplASClass* to); +private: + Conversion m_conversion; +}; class RplASIndexedValue : public RplASNode2 { public: RplASIndexedValue(); +public: + virtual bool check(RplParser& parser); public: void dump(RplWriter& writer, int indent); }; @@ -355,13 +398,14 @@ class RplASVarDefinition : public RplASNode3, public RplASStatement public: RplASVarDefinition(); public: + virtual bool check(RplParser& parser); virtual void execute(RplVMThread& thread); +public: void dump(RplWriter& writer, int indent); const QByteArray& name() const; - RplASClass* datatype() const; int endOfScope() const; void setEndOfScope(int endOfScope); - + RplASClass* clazz() const; private: /// the column of the blockend containing the definition. /// if 0: end is end of method or end of class @@ -374,7 +418,9 @@ class RplASExprStatement : public RplASNode2, public RplASStatement public: RplASExprStatement(); public: + virtual bool check(RplParser& parser); virtual void execute(RplVMThread& thread); +public: void dump(RplWriter& writer, int indent); }; @@ -384,9 +430,10 @@ public: enum UnaryOp { UOP_UNDEF, UOP_PLUS, - UOP_MINUS, - UOP_LOGICAL_NOT, - UOP_BIT_NOT, + UOP_MINUS_INT, + UOP_MINUS_FLOAT, + UOP_NOT_BOOL, + UOP_NOT_INT, UOP_INC, UOP_DEC }; @@ -394,6 +441,8 @@ public: RplASUnaryOp(UnaryOp op, RplASItemType type); public: virtual void calc(RplVMThread& thread); + virtual bool check(RplParser& parser); +public: int getOperator() const; void dump(RplWriter& writer, int indent); public: @@ -453,7 +502,9 @@ private: public: RplASBinaryOp(); public: - void calc(RplVMThread& thread); + virtual void calc(RplVMThread& thread); + virtual bool check(RplParser& parser); +public: BinOperator getOperator() const; void setOperator(BinOperator op); void dump(RplWriter& writer, int indent); @@ -469,7 +520,9 @@ class RplASCondition : public RplASNode1, public RplASCalculable public: RplASCondition(); public: - void calc(RplVMThread& thread); + virtual void calc(RplVMThread& thread); + virtual bool check(RplParser& parser); +public: bool calcAsBool(RplVMThread& thread); void dump(RplWriter& writer, int indent); }; @@ -479,6 +532,7 @@ class RplASIf : public RplASNode4, public RplASStatement public: RplASIf(); public: + virtual bool check(RplParser& parser); virtual void execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -488,6 +542,7 @@ class RplASForIterated : public RplASNode4, public RplASStatement public: RplASForIterated(RplASVarDefinition* variable); public: + virtual bool check(RplParser& parser); virtual void execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -497,6 +552,7 @@ class RplASForCounted : public RplASNode6, public RplASStatement public: RplASForCounted(RplASVarDefinition* variable); public: + virtual bool check(RplParser& parser); virtual void execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -506,6 +562,7 @@ class RplASWhile : public RplASNode3, public RplASStatement public: RplASWhile(); public: + virtual bool check(RplParser& parser); virtual void execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -515,6 +572,7 @@ class RplASRepeat : public RplASNode3, public RplASStatement public: RplASRepeat(); public: + virtual bool check(RplParser& parser); virtual void execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); }; @@ -523,6 +581,8 @@ class RplASArgument : public RplASNode2 { public: RplASArgument(); +public: + virtual bool check(RplParser& parser); public: void dump(RplWriter& writer, int indent); protected: @@ -535,8 +595,10 @@ class RplASMethodCall : public RplASNode3, public RplASStatement public: RplASMethodCall(const QByteArray& name, RplASItem* parent); public: - void dump(RplWriter& writer, int indent); + virtual bool check(RplParser& parser); virtual void execute(RplVMThread& thread); +public: + void dump(RplWriter& writer, int indent); public: RplASMethod* method() const; @@ -562,6 +624,8 @@ class RplASField : public RplASNode1 { public: RplASField(const QByteArray& name); +public: + virtual bool check(RplParser& parser); public: void dump(RplWriter& writer, int indent); private: @@ -576,7 +640,9 @@ class RplASMethod : public RplASNode2 public: RplASMethod(const QByteArray& name, RplASTree& tree); public: - void execute(RplVMThread& thread); + virtual bool check(RplParser& parser); + virtual void execute(RplVMThread& thread); +public: void dump(RplWriter& writer, int indent); RplSymbolSpace* symbols() const; void setSymbols(); @@ -646,6 +712,8 @@ protected: }; #include "rplexpr/rplasclasses.hpp" + +#include "rplparser.hpp" class RplSymbolSpace; class RplASTree { diff --git a/rplexpr/rplmfparser.cpp b/rplexpr/rplmfparser.cpp index 5a2c094..0a7aa99 100644 --- a/rplexpr/rplmfparser.cpp +++ b/rplexpr/rplmfparser.cpp @@ -536,7 +536,7 @@ RplASItem* RplMFParser::buildVarOrField(const QByteArray& name, RplASVarDefinition* var = space->findVariable(name); RplASClass* clazz = NULL; if (var != NULL) - clazz = var->datatype(); + clazz = var->clazz(); RplASNamedValue* var2 = new RplASNamedValue(clazz, space, name, RplASNamedValue::A_NONE); var2->setPosition(position); @@ -564,13 +564,13 @@ RplASUnaryOp::UnaryOp RplMFParser::convertUnaryOp(int op) rc = RplASUnaryOp::UOP_PLUS; break; case O_MINUS: - rc = RplASUnaryOp::UOP_MINUS; + rc = RplASUnaryOp::UOP_MINUS_INT; break; case O_NOT: - rc = RplASUnaryOp::UOP_LOGICAL_NOT; + rc = RplASUnaryOp::UOP_NOT_BOOL; break; case O_BIT_NOT: - rc = RplASUnaryOp::UOP_BIT_NOT; + rc = RplASUnaryOp::UOP_NOT_INT; break; case O_INC: rc = RplASUnaryOp::UOP_INC; @@ -1001,13 +1001,16 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, break; case K_CLASS: parseClass(); + item = NULL; break; case K_FUNCTION: case K_GENERATOR: parseMethod(); + item = NULL; break; case K_IMPORT: parseImport(); + item = NULL; break; case K_CONST: case K_LAZY: diff --git a/rplexpr/rplparser.cpp b/rplexpr/rplparser.cpp index 477d1dc..de01de5 100644 --- a/rplexpr/rplparser.cpp +++ b/rplexpr/rplparser.cpp @@ -98,8 +98,9 @@ RplParser::RplParser(RplLexer& lexer, RplASTree& tree) : * @param location unique id of the error/warning message * @param position position of the error/warning * @param message message with placeholdes like sprintf() + * @return false (for chaining) */ -void RplParser::addSimpleMessage(LevelTag prefix, int location, +bool RplParser::addSimpleMessage(LevelTag prefix, int location, const RplSourcePosition* position, const char* message){ char buffer[2048]; @@ -114,6 +115,7 @@ void RplParser::addSimpleMessage(LevelTag prefix, int location, memcpy(buffer + used, message, length); buffer[used + length] = '\0'; m_messages.append(buffer); + return false; } /** @@ -124,13 +126,14 @@ void RplParser::addSimpleMessage(LevelTag prefix, int location, * @param position position of the error/warning * @param format message with placeholdes like sprintf() * @param varList the variable argument list + * @return false (for chaining) */ -void RplParser::addMessage(LevelTag prefix, int location, +bool RplParser::addMessage(LevelTag prefix, int location, const RplSourcePosition* position, const char* format, va_list varList){ char buffer[2048]; qvsnprintf(buffer, sizeof buffer, format, varList); - addSimpleMessage(prefix, location, position, buffer); + return addSimpleMessage(prefix, location, position, buffer); } /** @@ -186,8 +189,9 @@ void RplParser::syntaxError(int location, const char* message, * @param location unique id of the error/warning message * @param format message with placeholdes like sprintf() * @param ... optional: the variable argument list + * @return false (for chaining) */ -void RplParser::error(int location, const char* format, ...) +bool RplParser::error(int location, const char* format, ...) { va_list ap; va_start(ap, format); @@ -195,6 +199,7 @@ void RplParser::error(int location, const char* format, ...) va_end(ap); if (++m_errors >= m_maxErrors) throw RplParserStop("too many errors"); + return false; } /** * @brief Adds an error message with an additional info message. @@ -206,14 +211,16 @@ void RplParser::error(int location, const char* format, ...) * @param message describes the error * @param message2 the additional message * @param ... optional: the variable argument list + * @return false (for chaining) */ -void RplParser::error(int location, const RplSourcePosition* position, +bool RplParser::error(int location, const RplSourcePosition* position, const char* message, const char* message2) { addSimpleMessage(LT_ERROR, location, m_lexer.currentPosition(), message); addSimpleMessage(LT_INFO, location + 1, position, message2); if (++m_errors >= m_maxErrors) throw RplParserStop("too many errors"); + return false; } /** @@ -234,5 +241,23 @@ void RplParser::warning(int location, const char* format, ...) if (++m_warnings >= m_maxWarnings) throw RplParserStop("too many warnings"); } +/** + * @brief Return the number of errors. + * + * @return the count of errors occurred until now + */ +int RplParser::errors() const +{ + return m_errors; +} +/** + * @brief Return the number of warnings. + * + * @return the count of errors occurred until now + */ +int RplParser::warnings() const +{ + return m_warnings; +} diff --git a/rplexpr/rplparser.hpp b/rplexpr/rplparser.hpp index 69a8c7d..cb21c4c 100644 --- a/rplexpr/rplparser.hpp +++ b/rplexpr/rplparser.hpp @@ -38,20 +38,21 @@ public: public: RplParser(RplLexer& lexer, RplASTree& ast); public: - void addSimpleMessage(LevelTag prefix, int location, + bool addSimpleMessage(LevelTag prefix, int location, const RplSourcePosition* pos, const char* message); - void addMessage(LevelTag prefix, int location, + bool addMessage(LevelTag prefix, int location, const RplSourcePosition* pos, const char* format, va_list varList); void syntaxError(int location, const char* message); void syntaxError(int location, const char* message, const char* symbol, const RplSourcePosition* position); - void error(int location, const char* format, ...); - void error(int location, const RplSourcePosition* position, + bool error(int location, const char* format, ...); + bool error(int location, const RplSourcePosition* position, const char* message, const char* message2); void warning(int location, const char* format, ...); - + int errors() const; + int warnings() const; protected: RplLexer& m_lexer; RplASTree& m_tree; diff --git a/rplexpr/rplvm.cpp b/rplexpr/rplvm.cpp index 828f04b..9598c23 100644 --- a/rplexpr/rplvm.cpp +++ b/rplexpr/rplvm.cpp @@ -127,6 +127,7 @@ RplVMThread::RplVMThread(int maxStack, RplVirtualMachine* vm) : m_id(m_nextId++), m_debugMode(false), m_singleStep(false), + m_tracing(false), m_maxStack(maxStack), m_frameStack(), // the stack is never empty! @@ -300,6 +301,35 @@ RplASVariant& RplVMThread::valueOfVariable(RplSymbolSpace* symbolSpace, return rc; } +/** + * @brief Returns whether each execution step should be dumped. + * @return true: tracing is on
+ * false: otherwise + */ +bool RplVMThread::tracing() const +{ + return m_tracing; +} + +/** + * @brief Sets the tracing flag: if set each execution step is dumped. + * @param tracing true: tracing will be done
+ * false: tracing will not be done + */ +void RplVMThread::setTracing(bool tracing) +{ + m_tracing = tracing; +} + +/** + * @brief Returns the parent, a virtual machine. + * + * @return the virtual machine + */ +RplVirtualMachine* RplVMThread::vm() const +{ + return m_vm; +} /** @class RplVirtualMachine rplvm.hpp "rplexpr/rplvm.hpp" * @@ -403,6 +433,15 @@ void RplVirtualMachine::clearFlag(RplVirtualMachine::VMFlag flag) m_flags &= ~flag; } +/** + * @brief Returns the trace writer. + * @return the trace writer + */ +RplWriter* RplVirtualMachine::traceWriter() const +{ + return m_traceWriter; +} + /** * @brief Sets the trace writer. * diff --git a/rplexpr/rplvm.hpp b/rplexpr/rplvm.hpp index 8109b4f..a22d860 100644 --- a/rplexpr/rplvm.hpp +++ b/rplexpr/rplvm.hpp @@ -52,10 +52,15 @@ public: void valueToTop(RplSymbolSpace* symbolSpace, int variableNo); RplASVariant& lValue(RplASItem* item); RplASVariant& valueOfVariable(RplSymbolSpace* symbolSpace, int variableNo); + bool tracing() const; + void setTracing(bool tracing); + RplVirtualMachine* vm() const; + protected: int m_id; bool m_debugMode; bool m_singleStep; + bool m_tracing; int m_maxStack; StackFrameList m_frameStack; int m_topOfFrames; @@ -89,6 +94,7 @@ public: bool hasFlag(VMFlag flag) const; void setFlag(VMFlag flag); void clearFlag(VMFlag flag); + RplWriter* traceWriter() const; void setTraceWriter(RplWriter* traceWriter); RplASTree& tree() const; diff --git a/test/mfparser/baseTest.txt b/test/mfparser/baseTest.txt new file mode 100644 index 0000000..5577d25 --- /dev/null +++ b/test/mfparser/baseTest.txt @@ -0,0 +1,9 @@ +2+3*4 += (module) parent: $global +== Body: +Expr id: 6 expr: 2 succ: 0 :1:1 + BinOp id: 2 op: + (17) left: 1 right: 4 :1:1 + const id: 1 value: 2 :0:0 + BinOp id: 4 op: * (19) left: 3 right: 5 :1:3 + const id: 3 value: 3 :1:2 + const id: 5 value: 4 :1:4 diff --git a/test/mfparser/field1.txt b/test/mfparser/field1.txt new file mode 100644 index 0000000..b9960df --- /dev/null +++ b/test/mfparser/field1.txt @@ -0,0 +1,22 @@ +file.find('*.c')[0].name; +[1,2,3].join(' '); +3.14.trunc; += (module) parent: $global +== Body: +Expr id: 8 expr: 7 succ: 15 :1:24 + field name id: 7 parent: 5 succ: :1:24 + indexedValue id: 5 index: 6 parent: 2 :1:16 + const id: 6 value: 0 :1:17 + call find Id: 2 args: 4 parent: 1 succ: 0 :1:9 + arg 1 id: 4 expr: 3 succ: 0 + const id: 3 value: '*.c' :1:10 + namedValue file id: 1 attr: 0x0 :1:4 +Expr id: 15 expr: 12 succ: 18 :2:12 + call join Id: 12 args: 14 parent: 9 succ: 0 :2:12 + arg 1 id: 14 expr: 13 succ: 0 + const id: 13 value: ' ' :2:13 + listConst id: 9 :1:26 + [1,2,] +Expr id: 18 expr: 17 succ: 0 :3:10 + field trunc id: 17 parent: 16 succ: :3:10 + const id: 16 value: 3.140000 :2:19 diff --git a/test/mfparser/forC1.txt b/test/mfparser/forC1.txt new file mode 100644 index 0000000..73215c3 --- /dev/null +++ b/test/mfparser/forC1.txt @@ -0,0 +1,23 @@ +Int a; +for b from 10 to 1 step -2 do +a += 1; +od += (module) parent: $global +== Variables: +varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +varDef Int b id: 4 namedValue: 3 value: 0 succ: 0 :2:4-3:0 + namedValue b id: 3 attr: 0x40 :2:4 +== Body: +varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +forC id: 5 var: 3 from: 6 to: 7 step: 8 body: 13 succ: 0 :1:7 + namedValue b id: 3 attr: 0x40 :2:4 + const id: 6 value: 10 :2:11 + const id: 7 value: 1 :2:17 + Unary 8 op: - (2) expr: 9 :2:24 + const id: 9 value: 2 :2:25 + Expr id: 13 expr: 11 succ: 0 :3:2 + BinOp id: 11 op: += (2) left: 10 right: 12 :3:2 + namedValue a id: 10 attr: 0x0 :3:2 + const id: 12 value: 1 :3:5 diff --git a/test/mfparser/forC2.txt b/test/mfparser/forC2.txt new file mode 100644 index 0000000..008df5a --- /dev/null +++ b/test/mfparser/forC2.txt @@ -0,0 +1,17 @@ +Int a; for to 10 do a += 1 od += (module) parent: $global +== Variables: +varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +varDef Int $1_7 id: 4 namedValue: 3 value: 0 succ: 0 :1:7-1:0 + namedValue $1_7 id: 3 attr: 0x40 :1:7 +== Body: +varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +forC id: 5 var: 3 from: 0 to: 6 step: 0 body: 10 succ: 0 :1:7 + namedValue $1_7 id: 3 attr: 0x40 :1:7 + const id: 6 value: 10 :1:14 + Expr id: 10 expr: 8 succ: 0 :1:22 + BinOp id: 8 op: += (2) left: 7 right: 9 :1:22 + namedValue a id: 7 attr: 0x0 :1:22 + const id: 9 value: 1 :1:25 diff --git a/test/mfparser/forIt1.txt b/test/mfparser/forIt1.txt new file mode 100644 index 0000000..297f1c2 --- /dev/null +++ b/test/mfparser/forIt1.txt @@ -0,0 +1,20 @@ +Map a; +for x in a do +a += 1; +od += (module) parent: $global +== Variables: +varDef Map a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +varDef Int x id: 4 namedValue: 3 value: 0 succ: 0 :2:4-3:0 + namedValue x id: 3 attr: 0x40 :2:4 +== Body: +varDef Map a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +forIt id: 5 var: 3 set: 6 body: 10 succ: 0 :1:7 + namedValue x id: 3 attr: 0x40 :2:4 + namedValue a id: 6 attr: 0x0 :2:11 + Expr id: 10 expr: 8 succ: 0 :3:2 + BinOp id: 8 op: += (2) left: 7 right: 9 :3:2 + namedValue a id: 7 attr: 0x0 :3:2 + const id: 9 value: 1 :3:5 diff --git a/test/mfparser/ifTest1.txt b/test/mfparser/ifTest1.txt new file mode 100644 index 0000000..1a01773 --- /dev/null +++ b/test/mfparser/ifTest1.txt @@ -0,0 +1,40 @@ +Int a; +Int b; +a = b = 2; +if 11 < 12 +then a = 13 * 14 +else a = 15 / 16 +fi += (module) parent: $global +== Variables: +varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +varDef b id: 4 namedValue: 3 value: 0 succ: 10 :2:4 + namedValue b id: 3 attr: 0x0 :2:4 +== Body: +varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +varDef b id: 4 namedValue: 3 value: 0 succ: 10 :2:4 + namedValue b id: 3 attr: 0x0 :2:4 +Expr id: 10 expr: 6 succ: 11 :3:2 + BinOp id: 6 op: = (1) left: 5 right: 8 :3:2 + namedValue a id: 5 attr: 0x0 :3:2 + BinOp id: 8 op: = (1) left: 7 right: 9 :3:6 + namedValue b id: 7 attr: 0x0 :3:6 + const id: 9 value: 2 :3:8 +If id: 11 condition: 13 then: 20 else: 26 succ: 0:3:11 + BinOp id: 13 op: < (35) left: 12 right: 14 :4:6 + const id: 12 value: 11 :4:3 + const id: 14 value: 12 :4:8 + Expr id: 20 expr: 16 succ: 0 :5:7 + BinOp id: 16 op: = (1) left: 15 right: 18 :5:7 + namedValue a id: 15 attr: 0x0 :5:7 + BinOp id: 18 op: * (19) left: 17 right: 19 :5:12 + const id: 17 value: 13 :5:9 + const id: 19 value: 14 :5:14 + Expr id: 26 expr: 22 succ: 0 :6:7 + BinOp id: 22 op: = (1) left: 21 right: 24 :6:7 + namedValue a id: 21 attr: 0x0 :6:7 + BinOp id: 24 op: / (20) left: 23 right: 25 :6:12 + const id: 23 value: 15 :6:9 + const id: 25 value: 16 :6:14 diff --git a/test/mfparser/ifTest2.txt b/test/mfparser/ifTest2.txt new file mode 100644 index 0000000..67fa8f9 --- /dev/null +++ b/test/mfparser/ifTest2.txt @@ -0,0 +1,19 @@ +Str x; +if 7 < 6 +then x = '123'; +fi += (module) parent: $global +== Variables: +varDef x id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue x id: 1 attr: 0x0 :1:4 +== Body: +varDef x id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue x id: 1 attr: 0x0 :1:4 +If id: 3 condition: 5 then: 10 else: 0 succ: 0:1:7 + BinOp id: 5 op: < (35) left: 4 right: 6 :2:5 + const id: 4 value: 7 :2:3 + const id: 6 value: 6 :2:7 + Expr id: 10 expr: 8 succ: 0 :3:7 + BinOp id: 8 op: = (1) left: 7 right: 9 :3:7 + namedValue x id: 7 attr: 0x0 :3:7 + const id: 9 value: '123' :3:9 diff --git a/test/mfparser/list1.txt b/test/mfparser/list1.txt new file mode 100644 index 0000000..c326ad0 --- /dev/null +++ b/test/mfparser/list1.txt @@ -0,0 +1,12 @@ +List b = []; += (module) parent: $global +== Variables: +varDef List b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 + namedValue b id: 1 attr: 0x0 :1:5 + listConst id: 3 :1:9 + [] +== Body: +varDef List b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 + namedValue b id: 1 attr: 0x0 :1:5 + listConst id: 3 :1:9 + [] diff --git a/test/mfparser/list2.txt b/test/mfparser/list2.txt new file mode 100644 index 0000000..828cedd --- /dev/null +++ b/test/mfparser/list2.txt @@ -0,0 +1,20 @@ +List a = [2+3, 3.14, 7, 'hi', a]; List b = []; += (module) parent: $global +== Variables: +varDef List a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 + namedValue a id: 1 attr: 0x0 :1:5 + listConst id: 3 :1:9 + [,3.140000,7,'hi',] +varDef List b id: 11 namedValue: 10 value: 12 succ: 0 :1:39 + namedValue b id: 10 attr: 0x0 :1:39 + listConst id: 12 :1:43 + [] +== Body: +varDef List a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 + namedValue a id: 1 attr: 0x0 :1:5 + listConst id: 3 :1:9 + [,3.140000,7,'hi',] +varDef List b id: 11 namedValue: 10 value: 12 succ: 0 :1:39 + namedValue b id: 10 attr: 0x0 :1:39 + listConst id: 12 :1:43 + [] diff --git a/test/mfparser/main1.txt b/test/mfparser/main1.txt new file mode 100644 index 0000000..afe940b --- /dev/null +++ b/test/mfparser/main1.txt @@ -0,0 +1,26 @@ +Int a=2+3*4; +func Void main(): +a; +endf += (module) parent: $global +== Methods: +Method main() id: 8 parent: args: 0 body: 10 :1:13 + Expr id: 10 expr: 9 succ: 0 :3:1 + namedValue a id: 9 attr: 0x0 :3:1 + = .main (method) parent: +== Variables: +varDef Int a id: 2 namedValue: 1 value: 4 succ: 0 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + BinOp id: 4 op: + (17) left: 3 right: 6 :1:7 + const id: 3 value: 2 :1:6 + BinOp id: 6 op: * (19) left: 5 right: 7 :1:9 + const id: 5 value: 3 :1:8 + const id: 7 value: 4 :1:10 +== Body: +varDef Int a id: 2 namedValue: 1 value: 4 succ: 0 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + BinOp id: 4 op: + (17) left: 3 right: 6 :1:7 + const id: 3 value: 2 :1:6 + BinOp id: 6 op: * (19) left: 5 right: 7 :1:9 + const id: 5 value: 3 :1:8 + const id: 7 value: 4 :1:10 diff --git a/test/mfparser/map1.txt b/test/mfparser/map1.txt new file mode 100644 index 0000000..f140c85 --- /dev/null +++ b/test/mfparser/map1.txt @@ -0,0 +1,12 @@ +Map a = {}; += (module) parent: $global +== Variables: +varDef Map a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + mapConst id: 3 :1:8 + {} +== Body: +varDef Map a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + mapConst id: 3 :1:8 + {} diff --git a/test/mfparser/map2.txt b/test/mfparser/map2.txt new file mode 100644 index 0000000..fd4ae67 --- /dev/null +++ b/test/mfparser/map2.txt @@ -0,0 +1,21 @@ +Map a = {'a': 2+3,'bcd':3.14,'ccc':7, 'hi':'world'}; +Map b = {}; += (module) parent: $global +== Variables: +varDef Map a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + mapConst id: 3 :1:8 + {'a':,'bcd':3.140000,'ccc':7,'hi':} +varDef Map b id: 11 namedValue: 10 value: 12 succ: 0 :2:4 + namedValue b id: 10 attr: 0x0 :2:4 + mapConst id: 12 :2:8 + {} +== Body: +varDef Map a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + mapConst id: 3 :1:8 + {'a':,'bcd':3.140000,'ccc':7,'hi':} +varDef Map b id: 11 namedValue: 10 value: 12 succ: 0 :2:4 + namedValue b id: 10 attr: 0x0 :2:4 + mapConst id: 12 :2:8 + {} diff --git a/test/mfparser/meth1.txt b/test/mfparser/meth1.txt new file mode 100644 index 0000000..ba888fc --- /dev/null +++ b/test/mfparser/meth1.txt @@ -0,0 +1,11 @@ +func Float pi: 3.1415; endf func Str delim(): '/' endf; += (module) parent: $global +== Methods: +Method delim() id: 4 parent: args: 0 body: 6 :1:28 + Expr id: 6 expr: 5 succ: 0 :1:46 + const id: 5 value: '/' :1:46 + = .delim (method) parent: +Method pi() id: 1 parent: args: 0 body: 3 :0:0 + Expr id: 3 expr: 2 succ: 0 :1:15 + const id: 2 value: 3.141500 :1:15 + = .pi (method) parent: diff --git a/test/mfparser/meth2.txt b/test/mfparser/meth2.txt new file mode 100644 index 0000000..bd20165 --- /dev/null +++ b/test/mfparser/meth2.txt @@ -0,0 +1,37 @@ +func Int fac(const Int n): +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 + = .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 diff --git a/test/mfparser/meth3.txt b/test/mfparser/meth3.txt new file mode 100644 index 0000000..0808991 --- /dev/null +++ b/test/mfparser/meth3.txt @@ -0,0 +1,32 @@ +func Int max(Int a, Int b): + Int rc = a; +if a < b then rc = b; fi +rc +endf +func Int max(const Int a, Int b, Int c): +max(a, max(b, c)) +endf += (module) parent: $global +== Methods: +Method max() id: 21 parent: args: 24 body: 40 :5:5 + Expr id: 24 expr: 23 succ: 27 + varDef Int a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 + namedValue a id: 22 attr: 0x22 :6:23 + Expr id: 40 expr: 31 succ: 0 :7:3 + call max Id: 31 args: 33 parent: 0 succ: 0 :7:3 + arg 1 id: 33 expr: 32 succ: 39 + namedValue a id: 32 attr: 0x0 :7:5 + arg 2 id: 39 expr: 34 succ: 0 + call max Id: 34 args: 36 parent: 0 succ: 0 :7:10 + arg 1 id: 36 expr: 35 succ: 38 + namedValue b id: 35 attr: 0x0 :7:12 + arg 2 id: 38 expr: 37 succ: 0 + namedValue c id: 37 attr: 0x0 :7:15 + = .max (method) parent: + == Variables: + varDef Int a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 + namedValue a id: 22 attr: 0x22 :6:23 + varDef Int b id: 26 namedValue: 25 value: 0 succ: 0 :6:30 + namedValue b id: 25 attr: 0x20 :6:30 + varDef Int c id: 29 namedValue: 28 value: 0 succ: 0 :6:37 + namedValue c id: 28 attr: 0x20 :6:37 diff --git a/test/mfparser/meth4.txt b/test/mfparser/meth4.txt new file mode 100644 index 0000000..9d237c5 --- /dev/null +++ b/test/mfparser/meth4.txt @@ -0,0 +1,59 @@ +func Int max(const Int a, Int b, Int c): +func Int max(Int a, Int b): + Int rc = a; +if a < b then rc = b; fi +rc +endf +max(a, max(b, c)) +endf += (module) parent: $global +== Methods: +Method max() id: 1 parent: args: 4 body: 40 :0:4 + Expr id: 4 expr: 3 succ: 7 + varDef Int a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + namedValue a id: 2 attr: 0x22 :1:23 + Expr id: 40 expr: 31 succ: 0 :7:3 + call max Id: 31 args: 33 parent: 0 succ: 0 :7:3 + arg 1 id: 33 expr: 32 succ: 39 + namedValue a id: 32 attr: 0x0 :7:5 + arg 2 id: 39 expr: 34 succ: 0 + call max Id: 34 args: 36 parent: 0 succ: 0 :7:10 + arg 1 id: 36 expr: 35 succ: 38 + namedValue b id: 35 attr: 0x0 :7:12 + arg 2 id: 38 expr: 37 succ: 0 + namedValue c id: 37 attr: 0x0 :7:15 + = .max (method) parent: + == Methods: + Method max() id: 11 parent: .max args: 14 body: 19 :1:41 + Expr id: 14 expr: 13 succ: 17 + varDef Int a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 + namedValue a id: 12 attr: 0x20 :2:17 + varDef Int rc id: 19 namedValue: 18 value: 20 succ: 21 :3:5 + namedValue rc id: 18 attr: 0x0 :3:5 + namedValue a id: 20 attr: 0x0 :3:11 + If id: 21 condition: 23 then: 28 else: 0 succ: 30:3:13 + BinOp id: 23 op: < (35) left: 22 right: 24 :4:5 + namedValue a id: 22 attr: 0x0 :4:5 + namedValue b id: 24 attr: 0x0 :4:9 + Expr id: 28 expr: 26 succ: 0 :4:17 + BinOp id: 26 op: = (1) left: 25 right: 27 :4:17 + namedValue rc id: 25 attr: 0x0 :4:17 + namedValue b id: 27 attr: 0x0 :4:20 + Expr id: 30 expr: 29 succ: 0 :5:3 + namedValue rc id: 29 attr: 0x0 :5:3 + = .max.max (method) parent: .max + == Variables: + varDef Int a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 + namedValue a id: 12 attr: 0x20 :2:17 + varDef Int b id: 16 namedValue: 15 value: 0 succ: 0 :2:24 + namedValue b id: 15 attr: 0x20 :2:24 + varDef Int rc id: 19 namedValue: 18 value: 20 succ: 21 :3:5 + namedValue rc id: 18 attr: 0x0 :3:5 + namedValue a id: 20 attr: 0x0 :3:11 + == Variables: + varDef Int a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + namedValue a id: 2 attr: 0x22 :1:23 + varDef Int b id: 6 namedValue: 5 value: 0 succ: 0 :1:30 + namedValue b id: 5 attr: 0x20 :1:30 + varDef Int c id: 9 namedValue: 8 value: 0 succ: 0 :1:37 + namedValue c id: 8 attr: 0x20 :1:37 diff --git a/test/mfparser/methc1.txt b/test/mfparser/methc1.txt new file mode 100644 index 0000000..afb30ca --- /dev/null +++ b/test/mfparser/methc1.txt @@ -0,0 +1,25 @@ +rand(); +sin(a); +max(1+2*3,4**(5-4)); += (module) parent: $global +== Body: +Expr id: 2 expr: 1 succ: 6 :1:4 + call rand Id: 1 args: 0 parent: 0 succ: 0 :1:4 +Expr id: 6 expr: 3 succ: 20 :2:3 + call sin Id: 3 args: 5 parent: 0 succ: 0 :2:3 + arg 1 id: 5 expr: 4 succ: 0 + namedValue a id: 4 attr: 0x0 :2:5 +Expr id: 20 expr: 7 succ: 0 :3:3 + call max Id: 7 args: 13 parent: 0 succ: 0 :3:3 + arg 1 id: 13 expr: 9 succ: 19 + BinOp id: 9 op: + (17) left: 8 right: 11 :3:5 + const id: 8 value: 1 :3:4 + BinOp id: 11 op: * (19) left: 10 right: 12 :3:7 + const id: 10 value: 2 :3:6 + const id: 12 value: 3 :3:8 + arg 2 id: 19 expr: 15 succ: 0 + BinOp id: 15 op: ** (22) left: 14 right: 17 :3:11 + const id: 14 value: 4 :3:10 + BinOp id: 17 op: - (18) left: 16 right: 18 :3:15 + const id: 16 value: 5 :3:14 + const id: 18 value: 4 :3:16 diff --git a/test/mfparser/opTest1.txt b/test/mfparser/opTest1.txt new file mode 100644 index 0000000..d34ba9f --- /dev/null +++ b/test/mfparser/opTest1.txt @@ -0,0 +1,49 @@ +Int a = 1; +Int b = 100; +--a; +b++; +a--*++b**(8-3); +a=b=(a+(b-2)*3) += (module) parent: $global +== Variables: +varDef Int a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + const id: 3 value: 1 :1:8 +varDef Int b id: 5 namedValue: 4 value: 6 succ: 9 :2:4 + namedValue b id: 4 attr: 0x0 :2:4 + const id: 6 value: 100 :2:8 +== Body: +varDef Int a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + const id: 3 value: 1 :1:8 +varDef Int b id: 5 namedValue: 4 value: 6 succ: 9 :2:4 + namedValue b id: 4 attr: 0x0 :2:4 + const id: 6 value: 100 :2:8 +Expr id: 9 expr: 7 succ: 12 :2:13 + Unary 7 op: -- (6) expr: 8 :2:13 + namedValue a id: 8 attr: 0x0 :3:3 +Expr id: 12 expr: 11 succ: 22 + Unary 11 op: ++ (5) expr: 10 + namedValue b id: 10 attr: 0x0 :4:1 +Expr id: 22 expr: 15 succ: 34 :5:3 + BinOp id: 15 op: * (19) left: 14 right: 18 :5:3 + Unary 14 op: -- (6) expr: 13 + namedValue a id: 13 attr: 0x0 :5:1 + BinOp id: 18 op: ** (22) left: 16 right: 20 :5:7 + Unary 16 op: ++ (5) expr: 17 :5:4 + namedValue b id: 17 attr: 0x0 :5:7 + BinOp id: 20 op: - (18) left: 19 right: 21 :5:11 + const id: 19 value: 8 :5:10 + const id: 21 value: 3 :5:12 +Expr id: 34 expr: 24 succ: 0 :6:1 + BinOp id: 24 op: = (1) left: 23 right: 26 :6:1 + namedValue a id: 23 attr: 0x0 :6:1 + BinOp id: 26 op: = (1) left: 25 right: 28 :6:3 + namedValue b id: 25 attr: 0x0 :6:3 + BinOp id: 28 op: + (17) left: 27 right: 32 :6:6 + namedValue a id: 27 attr: 0x0 :6:6 + BinOp id: 32 op: * (19) left: 30 right: 33 :6:12 + BinOp id: 30 op: - (18) left: 29 right: 31 :6:9 + namedValue b id: 29 attr: 0x0 :6:9 + const id: 31 value: 2 :6:10 + const id: 33 value: 3 :6:13 diff --git a/test/mfparser/repeatTest.txt b/test/mfparser/repeatTest.txt new file mode 100644 index 0000000..b23a54a --- /dev/null +++ b/test/mfparser/repeatTest.txt @@ -0,0 +1,20 @@ +Int a; +repeat +a++; +until a != 2 * 3; += (module) parent: $global +== Variables: +varDef Int a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +== Body: +varDef Int a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 +repeat id: 3 condition: 8 body: 6 succ: 0 :1:7 + BinOp id: 8 op: != (33) left: 7 right: 10 :4:8 + namedValue a id: 7 attr: 0x0 :4:8 + BinOp id: 10 op: * (19) left: 9 right: 11 :4:13 + const id: 9 value: 2 :4:11 + const id: 11 value: 3 :4:15 + Expr id: 6 expr: 5 succ: 0 + Unary 5 op: ++ (5) expr: 4 + namedValue a id: 4 attr: 0x0 :3:1 diff --git a/test/mfparser/string1.mf b/test/mfparser/string1.mf new file mode 100644 index 0000000..7beb37b --- /dev/null +++ b/test/mfparser/string1.mf @@ -0,0 +1,3 @@ +Str x1 = "x1 123456789 123456789 123456789 123456789 123456789"; +Str x2 = "x2 123456789 123456789 123456789 123456789 123456789"; +Str x3 = "x3 123456789 123456789 123456789 123456789 123456789"; diff --git a/test/mfparser/string1.txt b/test/mfparser/string1.txt new file mode 100644 index 0000000..5dfbe02 --- /dev/null +++ b/test/mfparser/string1.txt @@ -0,0 +1,24 @@ +Str x1 = "x1 123456789 123456789 123456789 123456789 123456789"; +Str x2 = "x2 123456789 123456789 123456789 123456789 123456789"; +Str x3 = "x3 123456789 123456789 123456789 123456789 123456789"; += test/rplmfparser/string1.mf (module) parent: $global +== Variables: +varDef Str x1 id: 2 namedValue: 1 value: 3 succ: 5 test/rplmfparser/string1.mf:1:4 + namedValue x1 id: 1 attr: 0x0 test/rplmfparser/string1.mf:1:4 + const id: 3 value: 'x1 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:1:9 +varDef Str x2 id: 5 namedValue: 4 value: 6 succ: 8 test/rplmfparser/string1.mf:3:4 + namedValue x2 id: 4 attr: 0x0 test/rplmfparser/string1.mf:3:4 + const id: 6 value: 'x2 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:3:9 +varDef Str x3 id: 8 namedValue: 7 value: 9 succ: 0 test/rplmfparser/string1.mf:5:4 + namedValue x3 id: 7 attr: 0x0 test/rplmfparser/string1.mf:5:4 + const id: 9 value: 'x3 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:5:9 +== Body: +varDef Str x1 id: 2 namedValue: 1 value: 3 succ: 5 test/rplmfparser/string1.mf:1:4 + namedValue x1 id: 1 attr: 0x0 test/rplmfparser/string1.mf:1:4 + const id: 3 value: 'x1 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:1:9 +varDef Str x2 id: 5 namedValue: 4 value: 6 succ: 8 test/rplmfparser/string1.mf:3:4 + namedValue x2 id: 4 attr: 0x0 test/rplmfparser/string1.mf:3:4 + const id: 6 value: 'x2 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:3:9 +varDef Str x3 id: 8 namedValue: 7 value: 9 succ: 0 test/rplmfparser/string1.mf:5:4 + namedValue x3 id: 7 attr: 0x0 test/rplmfparser/string1.mf:5:4 + const id: 9 value: 'x3 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:5:9 diff --git a/test/mfparser/varDefTest.txt b/test/mfparser/varDefTest.txt new file mode 100644 index 0000000..2d9cafd --- /dev/null +++ b/test/mfparser/varDefTest.txt @@ -0,0 +1,22 @@ +const lazy Str s = 'Hi'; +const List l; +Int i = 3; += (module) parent: $global +== Variables: +varDef Str s id: 2 namedValue: 1 value: 3 succ: 5 :1:15 + namedValue s id: 1 attr: 0x12 :1:15 + const id: 3 value: 'Hi' :1:19 +varDef List l id: 5 namedValue: 4 value: 0 succ: 7 :2:11 + namedValue l id: 4 attr: 0x2 :2:11 +varDef Int i id: 7 namedValue: 6 value: 8 succ: 0 :3:4 + namedValue i id: 6 attr: 0x0 :3:4 + const id: 8 value: 3 :3:8 +== Body: +varDef Str s id: 2 namedValue: 1 value: 3 succ: 5 :1:15 + namedValue s id: 1 attr: 0x12 :1:15 + const id: 3 value: 'Hi' :1:19 +varDef List l id: 5 namedValue: 4 value: 0 succ: 7 :2:11 + namedValue l id: 4 attr: 0x2 :2:11 +varDef Int i id: 7 namedValue: 6 value: 8 succ: 0 :3:4 + namedValue i id: 6 attr: 0x0 :3:4 + const id: 8 value: 3 :3:8 diff --git a/test/mfparser/whileTest.txt b/test/mfparser/whileTest.txt new file mode 100644 index 0000000..981d612 --- /dev/null +++ b/test/mfparser/whileTest.txt @@ -0,0 +1,21 @@ +Int a = 20; +while 3 < 5 do + a = 7 +od += (module) parent: $global +== Variables: +varDef Int a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + const id: 3 value: 20 :1:8 +== Body: +varDef Int a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 + namedValue a id: 1 attr: 0x0 :1:4 + const id: 3 value: 20 :1:8 +while id: 4 condition: 6 body: 11 succ: 0 :1:12 + BinOp id: 6 op: < (35) left: 5 right: 7 :2:8 + const id: 5 value: 3 :2:6 + const id: 7 value: 5 :2:10 + Expr id: 11 expr: 9 succ: 0 :3:3 + BinOp id: 9 op: = (1) left: 8 right: 10 :3:3 + namedValue a id: 8 attr: 0x0 :3:3 + const id: 10 value: 7 :3:5 diff --git a/test/rplmfparser/baseTest.txt b/test/rplmfparser/baseTest.txt deleted file mode 100644 index 5577d25..0000000 --- a/test/rplmfparser/baseTest.txt +++ /dev/null @@ -1,9 +0,0 @@ -2+3*4 -= (module) parent: $global -== Body: -Expr id: 6 expr: 2 succ: 0 :1:1 - BinOp id: 2 op: + (17) left: 1 right: 4 :1:1 - const id: 1 value: 2 :0:0 - BinOp id: 4 op: * (19) left: 3 right: 5 :1:3 - const id: 3 value: 3 :1:2 - const id: 5 value: 4 :1:4 diff --git a/test/rplmfparser/field1.txt b/test/rplmfparser/field1.txt deleted file mode 100644 index b9960df..0000000 --- a/test/rplmfparser/field1.txt +++ /dev/null @@ -1,22 +0,0 @@ -file.find('*.c')[0].name; -[1,2,3].join(' '); -3.14.trunc; -= (module) parent: $global -== Body: -Expr id: 8 expr: 7 succ: 15 :1:24 - field name id: 7 parent: 5 succ: :1:24 - indexedValue id: 5 index: 6 parent: 2 :1:16 - const id: 6 value: 0 :1:17 - call find Id: 2 args: 4 parent: 1 succ: 0 :1:9 - arg 1 id: 4 expr: 3 succ: 0 - const id: 3 value: '*.c' :1:10 - namedValue file id: 1 attr: 0x0 :1:4 -Expr id: 15 expr: 12 succ: 18 :2:12 - call join Id: 12 args: 14 parent: 9 succ: 0 :2:12 - arg 1 id: 14 expr: 13 succ: 0 - const id: 13 value: ' ' :2:13 - listConst id: 9 :1:26 - [1,2,] -Expr id: 18 expr: 17 succ: 0 :3:10 - field trunc id: 17 parent: 16 succ: :3:10 - const id: 16 value: 3.140000 :2:19 diff --git a/test/rplmfparser/forC1.txt b/test/rplmfparser/forC1.txt deleted file mode 100644 index 73215c3..0000000 --- a/test/rplmfparser/forC1.txt +++ /dev/null @@ -1,23 +0,0 @@ -Int a; -for b from 10 to 1 step -2 do -a += 1; -od -= (module) parent: $global -== Variables: -varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -varDef Int b id: 4 namedValue: 3 value: 0 succ: 0 :2:4-3:0 - namedValue b id: 3 attr: 0x40 :2:4 -== Body: -varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -forC id: 5 var: 3 from: 6 to: 7 step: 8 body: 13 succ: 0 :1:7 - namedValue b id: 3 attr: 0x40 :2:4 - const id: 6 value: 10 :2:11 - const id: 7 value: 1 :2:17 - Unary 8 op: - (2) expr: 9 :2:24 - const id: 9 value: 2 :2:25 - Expr id: 13 expr: 11 succ: 0 :3:2 - BinOp id: 11 op: += (2) left: 10 right: 12 :3:2 - namedValue a id: 10 attr: 0x0 :3:2 - const id: 12 value: 1 :3:5 diff --git a/test/rplmfparser/forC2.txt b/test/rplmfparser/forC2.txt deleted file mode 100644 index 008df5a..0000000 --- a/test/rplmfparser/forC2.txt +++ /dev/null @@ -1,17 +0,0 @@ -Int a; for to 10 do a += 1 od -= (module) parent: $global -== Variables: -varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -varDef Int $1_7 id: 4 namedValue: 3 value: 0 succ: 0 :1:7-1:0 - namedValue $1_7 id: 3 attr: 0x40 :1:7 -== Body: -varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -forC id: 5 var: 3 from: 0 to: 6 step: 0 body: 10 succ: 0 :1:7 - namedValue $1_7 id: 3 attr: 0x40 :1:7 - const id: 6 value: 10 :1:14 - Expr id: 10 expr: 8 succ: 0 :1:22 - BinOp id: 8 op: += (2) left: 7 right: 9 :1:22 - namedValue a id: 7 attr: 0x0 :1:22 - const id: 9 value: 1 :1:25 diff --git a/test/rplmfparser/forIt1.txt b/test/rplmfparser/forIt1.txt deleted file mode 100644 index 297f1c2..0000000 --- a/test/rplmfparser/forIt1.txt +++ /dev/null @@ -1,20 +0,0 @@ -Map a; -for x in a do -a += 1; -od -= (module) parent: $global -== Variables: -varDef Map a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -varDef Int x id: 4 namedValue: 3 value: 0 succ: 0 :2:4-3:0 - namedValue x id: 3 attr: 0x40 :2:4 -== Body: -varDef Map a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -forIt id: 5 var: 3 set: 6 body: 10 succ: 0 :1:7 - namedValue x id: 3 attr: 0x40 :2:4 - namedValue a id: 6 attr: 0x0 :2:11 - Expr id: 10 expr: 8 succ: 0 :3:2 - BinOp id: 8 op: += (2) left: 7 right: 9 :3:2 - namedValue a id: 7 attr: 0x0 :3:2 - const id: 9 value: 1 :3:5 diff --git a/test/rplmfparser/ifTest1.txt b/test/rplmfparser/ifTest1.txt deleted file mode 100644 index 1a01773..0000000 --- a/test/rplmfparser/ifTest1.txt +++ /dev/null @@ -1,40 +0,0 @@ -Int a; -Int b; -a = b = 2; -if 11 < 12 -then a = 13 * 14 -else a = 15 / 16 -fi -= (module) parent: $global -== Variables: -varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -varDef b id: 4 namedValue: 3 value: 0 succ: 10 :2:4 - namedValue b id: 3 attr: 0x0 :2:4 -== Body: -varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -varDef b id: 4 namedValue: 3 value: 0 succ: 10 :2:4 - namedValue b id: 3 attr: 0x0 :2:4 -Expr id: 10 expr: 6 succ: 11 :3:2 - BinOp id: 6 op: = (1) left: 5 right: 8 :3:2 - namedValue a id: 5 attr: 0x0 :3:2 - BinOp id: 8 op: = (1) left: 7 right: 9 :3:6 - namedValue b id: 7 attr: 0x0 :3:6 - const id: 9 value: 2 :3:8 -If id: 11 condition: 13 then: 20 else: 26 succ: 0:3:11 - BinOp id: 13 op: < (35) left: 12 right: 14 :4:6 - const id: 12 value: 11 :4:3 - const id: 14 value: 12 :4:8 - Expr id: 20 expr: 16 succ: 0 :5:7 - BinOp id: 16 op: = (1) left: 15 right: 18 :5:7 - namedValue a id: 15 attr: 0x0 :5:7 - BinOp id: 18 op: * (19) left: 17 right: 19 :5:12 - const id: 17 value: 13 :5:9 - const id: 19 value: 14 :5:14 - Expr id: 26 expr: 22 succ: 0 :6:7 - BinOp id: 22 op: = (1) left: 21 right: 24 :6:7 - namedValue a id: 21 attr: 0x0 :6:7 - BinOp id: 24 op: / (20) left: 23 right: 25 :6:12 - const id: 23 value: 15 :6:9 - const id: 25 value: 16 :6:14 diff --git a/test/rplmfparser/ifTest2.txt b/test/rplmfparser/ifTest2.txt deleted file mode 100644 index 67fa8f9..0000000 --- a/test/rplmfparser/ifTest2.txt +++ /dev/null @@ -1,19 +0,0 @@ -Str x; -if 7 < 6 -then x = '123'; -fi -= (module) parent: $global -== Variables: -varDef x id: 2 namedValue: 1 value: 0 succ: 3 :1:4 - namedValue x id: 1 attr: 0x0 :1:4 -== Body: -varDef x id: 2 namedValue: 1 value: 0 succ: 3 :1:4 - namedValue x id: 1 attr: 0x0 :1:4 -If id: 3 condition: 5 then: 10 else: 0 succ: 0:1:7 - BinOp id: 5 op: < (35) left: 4 right: 6 :2:5 - const id: 4 value: 7 :2:3 - const id: 6 value: 6 :2:7 - Expr id: 10 expr: 8 succ: 0 :3:7 - BinOp id: 8 op: = (1) left: 7 right: 9 :3:7 - namedValue x id: 7 attr: 0x0 :3:7 - const id: 9 value: '123' :3:9 diff --git a/test/rplmfparser/list1.txt b/test/rplmfparser/list1.txt deleted file mode 100644 index c326ad0..0000000 --- a/test/rplmfparser/list1.txt +++ /dev/null @@ -1,12 +0,0 @@ -List b = []; -= (module) parent: $global -== Variables: -varDef List b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 - namedValue b id: 1 attr: 0x0 :1:5 - listConst id: 3 :1:9 - [] -== Body: -varDef List b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 - namedValue b id: 1 attr: 0x0 :1:5 - listConst id: 3 :1:9 - [] diff --git a/test/rplmfparser/list2.txt b/test/rplmfparser/list2.txt deleted file mode 100644 index 828cedd..0000000 --- a/test/rplmfparser/list2.txt +++ /dev/null @@ -1,20 +0,0 @@ -List a = [2+3, 3.14, 7, 'hi', a]; List b = []; -= (module) parent: $global -== Variables: -varDef List a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 - namedValue a id: 1 attr: 0x0 :1:5 - listConst id: 3 :1:9 - [,3.140000,7,'hi',] -varDef List b id: 11 namedValue: 10 value: 12 succ: 0 :1:39 - namedValue b id: 10 attr: 0x0 :1:39 - listConst id: 12 :1:43 - [] -== Body: -varDef List a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 - namedValue a id: 1 attr: 0x0 :1:5 - listConst id: 3 :1:9 - [,3.140000,7,'hi',] -varDef List b id: 11 namedValue: 10 value: 12 succ: 0 :1:39 - namedValue b id: 10 attr: 0x0 :1:39 - listConst id: 12 :1:43 - [] diff --git a/test/rplmfparser/map1.txt b/test/rplmfparser/map1.txt deleted file mode 100644 index f140c85..0000000 --- a/test/rplmfparser/map1.txt +++ /dev/null @@ -1,12 +0,0 @@ -Map a = {}; -= (module) parent: $global -== Variables: -varDef Map a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 - mapConst id: 3 :1:8 - {} -== Body: -varDef Map a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 - mapConst id: 3 :1:8 - {} diff --git a/test/rplmfparser/map2.txt b/test/rplmfparser/map2.txt deleted file mode 100644 index fd4ae67..0000000 --- a/test/rplmfparser/map2.txt +++ /dev/null @@ -1,21 +0,0 @@ -Map a = {'a': 2+3,'bcd':3.14,'ccc':7, 'hi':'world'}; -Map b = {}; -= (module) parent: $global -== Variables: -varDef Map a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 - mapConst id: 3 :1:8 - {'a':,'bcd':3.140000,'ccc':7,'hi':} -varDef Map b id: 11 namedValue: 10 value: 12 succ: 0 :2:4 - namedValue b id: 10 attr: 0x0 :2:4 - mapConst id: 12 :2:8 - {} -== Body: -varDef Map a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 - mapConst id: 3 :1:8 - {'a':,'bcd':3.140000,'ccc':7,'hi':} -varDef Map b id: 11 namedValue: 10 value: 12 succ: 0 :2:4 - namedValue b id: 10 attr: 0x0 :2:4 - mapConst id: 12 :2:8 - {} diff --git a/test/rplmfparser/meth1.txt b/test/rplmfparser/meth1.txt deleted file mode 100644 index ba888fc..0000000 --- a/test/rplmfparser/meth1.txt +++ /dev/null @@ -1,11 +0,0 @@ -func Float pi: 3.1415; endf func Str delim(): '/' endf; -= (module) parent: $global -== Methods: -Method delim() id: 4 parent: args: 0 body: 6 :1:28 - Expr id: 6 expr: 5 succ: 0 :1:46 - const id: 5 value: '/' :1:46 - = .delim (method) parent: -Method pi() id: 1 parent: args: 0 body: 3 :0:0 - Expr id: 3 expr: 2 succ: 0 :1:15 - const id: 2 value: 3.141500 :1:15 - = .pi (method) parent: diff --git a/test/rplmfparser/meth2.txt b/test/rplmfparser/meth2.txt deleted file mode 100644 index bd20165..0000000 --- a/test/rplmfparser/meth2.txt +++ /dev/null @@ -1,37 +0,0 @@ -func Int fac(const Int n): -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 - = .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 diff --git a/test/rplmfparser/meth3.txt b/test/rplmfparser/meth3.txt deleted file mode 100644 index 0808991..0000000 --- a/test/rplmfparser/meth3.txt +++ /dev/null @@ -1,32 +0,0 @@ -func Int max(Int a, Int b): - Int rc = a; -if a < b then rc = b; fi -rc -endf -func Int max(const Int a, Int b, Int c): -max(a, max(b, c)) -endf -= (module) parent: $global -== Methods: -Method max() id: 21 parent: args: 24 body: 40 :5:5 - Expr id: 24 expr: 23 succ: 27 - varDef Int a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 - namedValue a id: 22 attr: 0x22 :6:23 - Expr id: 40 expr: 31 succ: 0 :7:3 - call max Id: 31 args: 33 parent: 0 succ: 0 :7:3 - arg 1 id: 33 expr: 32 succ: 39 - namedValue a id: 32 attr: 0x0 :7:5 - arg 2 id: 39 expr: 34 succ: 0 - call max Id: 34 args: 36 parent: 0 succ: 0 :7:10 - arg 1 id: 36 expr: 35 succ: 38 - namedValue b id: 35 attr: 0x0 :7:12 - arg 2 id: 38 expr: 37 succ: 0 - namedValue c id: 37 attr: 0x0 :7:15 - = .max (method) parent: - == Variables: - varDef Int a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 - namedValue a id: 22 attr: 0x22 :6:23 - varDef Int b id: 26 namedValue: 25 value: 0 succ: 0 :6:30 - namedValue b id: 25 attr: 0x20 :6:30 - varDef Int c id: 29 namedValue: 28 value: 0 succ: 0 :6:37 - namedValue c id: 28 attr: 0x20 :6:37 diff --git a/test/rplmfparser/meth4.txt b/test/rplmfparser/meth4.txt deleted file mode 100644 index 9d237c5..0000000 --- a/test/rplmfparser/meth4.txt +++ /dev/null @@ -1,59 +0,0 @@ -func Int max(const Int a, Int b, Int c): -func Int max(Int a, Int b): - Int rc = a; -if a < b then rc = b; fi -rc -endf -max(a, max(b, c)) -endf -= (module) parent: $global -== Methods: -Method max() id: 1 parent: args: 4 body: 40 :0:4 - Expr id: 4 expr: 3 succ: 7 - varDef Int a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 - namedValue a id: 2 attr: 0x22 :1:23 - Expr id: 40 expr: 31 succ: 0 :7:3 - call max Id: 31 args: 33 parent: 0 succ: 0 :7:3 - arg 1 id: 33 expr: 32 succ: 39 - namedValue a id: 32 attr: 0x0 :7:5 - arg 2 id: 39 expr: 34 succ: 0 - call max Id: 34 args: 36 parent: 0 succ: 0 :7:10 - arg 1 id: 36 expr: 35 succ: 38 - namedValue b id: 35 attr: 0x0 :7:12 - arg 2 id: 38 expr: 37 succ: 0 - namedValue c id: 37 attr: 0x0 :7:15 - = .max (method) parent: - == Methods: - Method max() id: 11 parent: .max args: 14 body: 19 :1:41 - Expr id: 14 expr: 13 succ: 17 - varDef Int a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 - namedValue a id: 12 attr: 0x20 :2:17 - varDef Int rc id: 19 namedValue: 18 value: 20 succ: 21 :3:5 - namedValue rc id: 18 attr: 0x0 :3:5 - namedValue a id: 20 attr: 0x0 :3:11 - If id: 21 condition: 23 then: 28 else: 0 succ: 30:3:13 - BinOp id: 23 op: < (35) left: 22 right: 24 :4:5 - namedValue a id: 22 attr: 0x0 :4:5 - namedValue b id: 24 attr: 0x0 :4:9 - Expr id: 28 expr: 26 succ: 0 :4:17 - BinOp id: 26 op: = (1) left: 25 right: 27 :4:17 - namedValue rc id: 25 attr: 0x0 :4:17 - namedValue b id: 27 attr: 0x0 :4:20 - Expr id: 30 expr: 29 succ: 0 :5:3 - namedValue rc id: 29 attr: 0x0 :5:3 - = .max.max (method) parent: .max - == Variables: - varDef Int a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 - namedValue a id: 12 attr: 0x20 :2:17 - varDef Int b id: 16 namedValue: 15 value: 0 succ: 0 :2:24 - namedValue b id: 15 attr: 0x20 :2:24 - varDef Int rc id: 19 namedValue: 18 value: 20 succ: 21 :3:5 - namedValue rc id: 18 attr: 0x0 :3:5 - namedValue a id: 20 attr: 0x0 :3:11 - == Variables: - varDef Int a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 - namedValue a id: 2 attr: 0x22 :1:23 - varDef Int b id: 6 namedValue: 5 value: 0 succ: 0 :1:30 - namedValue b id: 5 attr: 0x20 :1:30 - varDef Int c id: 9 namedValue: 8 value: 0 succ: 0 :1:37 - namedValue c id: 8 attr: 0x20 :1:37 diff --git a/test/rplmfparser/methc1.txt b/test/rplmfparser/methc1.txt deleted file mode 100644 index afb30ca..0000000 --- a/test/rplmfparser/methc1.txt +++ /dev/null @@ -1,25 +0,0 @@ -rand(); -sin(a); -max(1+2*3,4**(5-4)); -= (module) parent: $global -== Body: -Expr id: 2 expr: 1 succ: 6 :1:4 - call rand Id: 1 args: 0 parent: 0 succ: 0 :1:4 -Expr id: 6 expr: 3 succ: 20 :2:3 - call sin Id: 3 args: 5 parent: 0 succ: 0 :2:3 - arg 1 id: 5 expr: 4 succ: 0 - namedValue a id: 4 attr: 0x0 :2:5 -Expr id: 20 expr: 7 succ: 0 :3:3 - call max Id: 7 args: 13 parent: 0 succ: 0 :3:3 - arg 1 id: 13 expr: 9 succ: 19 - BinOp id: 9 op: + (17) left: 8 right: 11 :3:5 - const id: 8 value: 1 :3:4 - BinOp id: 11 op: * (19) left: 10 right: 12 :3:7 - const id: 10 value: 2 :3:6 - const id: 12 value: 3 :3:8 - arg 2 id: 19 expr: 15 succ: 0 - BinOp id: 15 op: ** (22) left: 14 right: 17 :3:11 - const id: 14 value: 4 :3:10 - BinOp id: 17 op: - (18) left: 16 right: 18 :3:15 - const id: 16 value: 5 :3:14 - const id: 18 value: 4 :3:16 diff --git a/test/rplmfparser/opTest1.txt b/test/rplmfparser/opTest1.txt deleted file mode 100644 index d34ba9f..0000000 --- a/test/rplmfparser/opTest1.txt +++ /dev/null @@ -1,49 +0,0 @@ -Int a = 1; -Int b = 100; ---a; -b++; -a--*++b**(8-3); -a=b=(a+(b-2)*3) -= (module) parent: $global -== Variables: -varDef Int a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 - const id: 3 value: 1 :1:8 -varDef Int b id: 5 namedValue: 4 value: 6 succ: 9 :2:4 - namedValue b id: 4 attr: 0x0 :2:4 - const id: 6 value: 100 :2:8 -== Body: -varDef Int a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 - const id: 3 value: 1 :1:8 -varDef Int b id: 5 namedValue: 4 value: 6 succ: 9 :2:4 - namedValue b id: 4 attr: 0x0 :2:4 - const id: 6 value: 100 :2:8 -Expr id: 9 expr: 7 succ: 12 :2:13 - Unary 7 op: -- (6) expr: 8 :2:13 - namedValue a id: 8 attr: 0x0 :3:3 -Expr id: 12 expr: 11 succ: 22 - Unary 11 op: ++ (5) expr: 10 - namedValue b id: 10 attr: 0x0 :4:1 -Expr id: 22 expr: 15 succ: 34 :5:3 - BinOp id: 15 op: * (19) left: 14 right: 18 :5:3 - Unary 14 op: -- (6) expr: 13 - namedValue a id: 13 attr: 0x0 :5:1 - BinOp id: 18 op: ** (22) left: 16 right: 20 :5:7 - Unary 16 op: ++ (5) expr: 17 :5:4 - namedValue b id: 17 attr: 0x0 :5:7 - BinOp id: 20 op: - (18) left: 19 right: 21 :5:11 - const id: 19 value: 8 :5:10 - const id: 21 value: 3 :5:12 -Expr id: 34 expr: 24 succ: 0 :6:1 - BinOp id: 24 op: = (1) left: 23 right: 26 :6:1 - namedValue a id: 23 attr: 0x0 :6:1 - BinOp id: 26 op: = (1) left: 25 right: 28 :6:3 - namedValue b id: 25 attr: 0x0 :6:3 - BinOp id: 28 op: + (17) left: 27 right: 32 :6:6 - namedValue a id: 27 attr: 0x0 :6:6 - BinOp id: 32 op: * (19) left: 30 right: 33 :6:12 - BinOp id: 30 op: - (18) left: 29 right: 31 :6:9 - namedValue b id: 29 attr: 0x0 :6:9 - const id: 31 value: 2 :6:10 - const id: 33 value: 3 :6:13 diff --git a/test/rplmfparser/repeatTest.txt b/test/rplmfparser/repeatTest.txt deleted file mode 100644 index b23a54a..0000000 --- a/test/rplmfparser/repeatTest.txt +++ /dev/null @@ -1,20 +0,0 @@ -Int a; -repeat -a++; -until a != 2 * 3; -= (module) parent: $global -== Variables: -varDef Int a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -== Body: -varDef Int a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 -repeat id: 3 condition: 8 body: 6 succ: 0 :1:7 - BinOp id: 8 op: != (33) left: 7 right: 10 :4:8 - namedValue a id: 7 attr: 0x0 :4:8 - BinOp id: 10 op: * (19) left: 9 right: 11 :4:13 - const id: 9 value: 2 :4:11 - const id: 11 value: 3 :4:15 - Expr id: 6 expr: 5 succ: 0 - Unary 5 op: ++ (5) expr: 4 - namedValue a id: 4 attr: 0x0 :3:1 diff --git a/test/rplmfparser/string1.mf b/test/rplmfparser/string1.mf deleted file mode 100644 index 7beb37b..0000000 --- a/test/rplmfparser/string1.mf +++ /dev/null @@ -1,3 +0,0 @@ -Str x1 = "x1 123456789 123456789 123456789 123456789 123456789"; -Str x2 = "x2 123456789 123456789 123456789 123456789 123456789"; -Str x3 = "x3 123456789 123456789 123456789 123456789 123456789"; diff --git a/test/rplmfparser/string1.txt b/test/rplmfparser/string1.txt deleted file mode 100644 index 5dfbe02..0000000 --- a/test/rplmfparser/string1.txt +++ /dev/null @@ -1,24 +0,0 @@ -Str x1 = "x1 123456789 123456789 123456789 123456789 123456789"; -Str x2 = "x2 123456789 123456789 123456789 123456789 123456789"; -Str x3 = "x3 123456789 123456789 123456789 123456789 123456789"; -= test/rplmfparser/string1.mf (module) parent: $global -== Variables: -varDef Str x1 id: 2 namedValue: 1 value: 3 succ: 5 test/rplmfparser/string1.mf:1:4 - namedValue x1 id: 1 attr: 0x0 test/rplmfparser/string1.mf:1:4 - const id: 3 value: 'x1 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:1:9 -varDef Str x2 id: 5 namedValue: 4 value: 6 succ: 8 test/rplmfparser/string1.mf:3:4 - namedValue x2 id: 4 attr: 0x0 test/rplmfparser/string1.mf:3:4 - const id: 6 value: 'x2 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:3:9 -varDef Str x3 id: 8 namedValue: 7 value: 9 succ: 0 test/rplmfparser/string1.mf:5:4 - namedValue x3 id: 7 attr: 0x0 test/rplmfparser/string1.mf:5:4 - const id: 9 value: 'x3 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:5:9 -== Body: -varDef Str x1 id: 2 namedValue: 1 value: 3 succ: 5 test/rplmfparser/string1.mf:1:4 - namedValue x1 id: 1 attr: 0x0 test/rplmfparser/string1.mf:1:4 - const id: 3 value: 'x1 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:1:9 -varDef Str x2 id: 5 namedValue: 4 value: 6 succ: 8 test/rplmfparser/string1.mf:3:4 - namedValue x2 id: 4 attr: 0x0 test/rplmfparser/string1.mf:3:4 - const id: 6 value: 'x2 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:3:9 -varDef Str x3 id: 8 namedValue: 7 value: 9 succ: 0 test/rplmfparser/string1.mf:5:4 - namedValue x3 id: 7 attr: 0x0 test/rplmfparser/string1.mf:5:4 - const id: 9 value: 'x3 123456789 123456789 123456789 123456789 123456789' test/rplmfparser/string1.mf:5:9 diff --git a/test/rplmfparser/varDefTest.txt b/test/rplmfparser/varDefTest.txt deleted file mode 100644 index 2d9cafd..0000000 --- a/test/rplmfparser/varDefTest.txt +++ /dev/null @@ -1,22 +0,0 @@ -const lazy Str s = 'Hi'; -const List l; -Int i = 3; -= (module) parent: $global -== Variables: -varDef Str s id: 2 namedValue: 1 value: 3 succ: 5 :1:15 - namedValue s id: 1 attr: 0x12 :1:15 - const id: 3 value: 'Hi' :1:19 -varDef List l id: 5 namedValue: 4 value: 0 succ: 7 :2:11 - namedValue l id: 4 attr: 0x2 :2:11 -varDef Int i id: 7 namedValue: 6 value: 8 succ: 0 :3:4 - namedValue i id: 6 attr: 0x0 :3:4 - const id: 8 value: 3 :3:8 -== Body: -varDef Str s id: 2 namedValue: 1 value: 3 succ: 5 :1:15 - namedValue s id: 1 attr: 0x12 :1:15 - const id: 3 value: 'Hi' :1:19 -varDef List l id: 5 namedValue: 4 value: 0 succ: 7 :2:11 - namedValue l id: 4 attr: 0x2 :2:11 -varDef Int i id: 7 namedValue: 6 value: 8 succ: 0 :3:4 - namedValue i id: 6 attr: 0x0 :3:4 - const id: 8 value: 3 :3:8 diff --git a/test/rplmfparser/whileTest.txt b/test/rplmfparser/whileTest.txt deleted file mode 100644 index 981d612..0000000 --- a/test/rplmfparser/whileTest.txt +++ /dev/null @@ -1,21 +0,0 @@ -Int a = 20; -while 3 < 5 do - a = 7 -od -= (module) parent: $global -== Variables: -varDef Int a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 - const id: 3 value: 20 :1:8 -== Body: -varDef Int a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 - namedValue a id: 1 attr: 0x0 :1:4 - const id: 3 value: 20 :1:8 -while id: 4 condition: 6 body: 11 succ: 0 :1:12 - BinOp id: 6 op: < (35) left: 5 right: 7 :2:8 - const id: 5 value: 3 :2:6 - const id: 7 value: 5 :2:10 - Expr id: 11 expr: 9 succ: 0 :3:3 - BinOp id: 9 op: = (1) left: 8 right: 10 :3:3 - namedValue a id: 8 attr: 0x0 :3:3 - const id: 10 value: 7 :3:5 diff --git a/unittests/rplmfparser_test.cpp b/unittests/rplmfparser_test.cpp index 896566e..6266a48 100644 --- a/unittests/rplmfparser_test.cpp +++ b/unittests/rplmfparser_test.cpp @@ -56,7 +56,7 @@ private: void checkAST(const char* fileExpected, int lineNo){ QByteArray fnExpected = "test"; fnExpected += QDir::separator().toLatin1(); - fnExpected += "rplmfparser"; + fnExpected += "mfparser"; fnExpected += (char) QDir::separator().toLatin1(); fnExpected += fileExpected; QByteArray fnCurrent = getTempFile(fileExpected, "rplmfparser"); @@ -194,9 +194,15 @@ public: parser.parse(); checkAST("meth4.txt", __LINE__); } + void mainTest(){ + setSource("Int a=2+3*4;\nfunc Void main():\na;\nendf"); + RplMFParser parser(m_source, m_tree); + parser.parse(); + checkAST("main1.txt", __LINE__); + } virtual void doIt(void) { - fileClassTest(); + mainTest(); varDefTest(); repeatTest(); baseTest(); @@ -209,6 +215,7 @@ public: forCTest(); listTest(); opTest(); + fileClassTest(); } }; void testRplMFParser() { diff --git a/unittests/rplvm_test.cpp b/unittests/rplvm_test.cpp index 8294491..244058e 100644 --- a/unittests/rplvm_test.cpp +++ b/unittests/rplvm_test.cpp @@ -51,6 +51,7 @@ private: vm.setFlag(RplVirtualMachine::VF_TRACE_STATEMENTS); RplFileWriter writer(fnCurrent); vm.setTraceWriter(&writer); + writer.write(m_currentSource); vm.executeModule(""); assertEqualFiles(fnExpected.constData(), fnCurrent.constData(), __FILE__, lineNo);