From: hama Date: Sat, 23 Aug 2014 13:05:53 +0000 (+0200) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=32d6ddf3373e33854968f4cc2795570d47a8665c;p=reqt dayly work --- diff --git a/rplcore/rplcontainer.cpp b/rplcore/rplcontainer.cpp index 2dbd976..c05b7bf 100644 --- a/rplcore/rplcontainer.cpp +++ b/rplcore/rplcontainer.cpp @@ -123,7 +123,7 @@ void RplContainer::addInt(int value) { *ptr++ = '-'; value = - value; } - snprintf(ptr, sizeof buffer - 1, "%x ", value); + qsnprintf(ptr, sizeof buffer - 1, "%x ", value); m_data.append(buffer); } /** @@ -134,7 +134,7 @@ void RplContainer::addInt(int value) { void RplContainer::addInt(qint64 value) { addType(TAG_INT); char buffer[128]; - snprintf(buffer, sizeof buffer, "%llx ", value); + qsnprintf(buffer, sizeof buffer, "%llx ", value); m_data.append(buffer); } @@ -184,10 +184,10 @@ const QByteArray& RplContainer::getData() { if(m_typeList.length() != 0) { char buffer[128]; // RPL&1 0a b5[2]cis: !12 - snprintf(buffer, sizeof buffer, "%x[%d]%s:", (unsigned int) m_data.length(), + qsnprintf(buffer, sizeof buffer, "%x[%d]%s:", (unsigned int) m_data.length(), m_countBags, m_typeList.data()); char header[128+8]; - snprintf(header, sizeof header, "%s%02x%s", MAGIC_1, + qsnprintf(header, sizeof header, "%s%02x%s", MAGIC_1, (unsigned int) strlen(buffer), buffer); m_data.insert(0, header); } diff --git a/rplcore/rplexception.cpp b/rplcore/rplexception.cpp index c6528f6..fac935f 100644 --- a/rplcore/rplexception.cpp +++ b/rplcore/rplexception.cpp @@ -67,7 +67,7 @@ RplException::RplException(const char* format, ...) : char buffer[64000]; va_list ap; va_start(ap, format); - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); va_end(ap); m_message = buffer; } @@ -93,7 +93,7 @@ RplException::RplException(RplLoggerLevel level, int location, char buffer[64000]; va_list ap; va_start(ap, format); - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); va_end(ap); m_message = buffer; if(logger == NULL) @@ -138,7 +138,7 @@ RplRangeException::RplRangeException(RplLoggerLevel level, int location, char buffer[64000]; if(message == NULL) message = "value outside limits"; - snprintf(buffer, sizeof buffer, "%s: %lu [%lu, %lu]", + qsnprintf(buffer, sizeof buffer, "%s: %lu [%lu, %lu]", message == NULL ? "" : message, current, lbound, ubound); if(logger == NULL) @@ -187,7 +187,7 @@ RplInvalidDataException::RplInvalidDataException(RplLoggerLevel level, size_t ix; char* ptr = buffer + strlen(buffer); for(ix = 0; ix < dataSize; ix++) { - snprintf(ptr, sizeof(buffer) - (ptr - buffer) - 1, "%02x ", + qsnprintf(ptr, sizeof(buffer) - (ptr - buffer) - 1, "%02x ", ((unsigned char*) data)[ix]); ptr += strlen(ptr); } diff --git a/rplcore/rpllogger.cpp b/rplcore/rpllogger.cpp index b201c27..84f20f7 100644 --- a/rplcore/rpllogger.cpp +++ b/rplcore/rpllogger.cpp @@ -311,7 +311,7 @@ bool RplLogger::logv(RplLoggerLevel level, int location, const char* format, char buffer[64000]; va_list ap; va_start(ap, format); - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); va_end(ap); return log(level, location, buffer); } @@ -330,7 +330,7 @@ bool RplLogger::logv(RplLoggerLevel level, int location, char buffer[64000]; va_list ap; va_start(ap, format); - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); va_end(ap); return log(level, location, buffer); } @@ -347,7 +347,7 @@ bool RplLogger::logv(RplLoggerLevel level, int location, bool RplLogger::log(RplLoggerLevel level, int location, const char* format, va_list& varlist) { char buffer[64000]; - vsnprintf(buffer, sizeof buffer, format, varlist); + qvsnprintf(buffer, sizeof buffer, format, varlist); return log(level, location, buffer); } @@ -361,7 +361,7 @@ QByteArray RplLogger::buildStdPrefix(RplLoggerLevel level, int location) { time_t now = time(NULL); struct tm* now2 = localtime(&now); char buffer[64]; - snprintf(buffer, sizeof buffer, "%c%d.%02d.%02d %02d:%02d:%02d (%d): ", + qsnprintf(buffer, sizeof buffer, "%c%d.%02d.%02d %02d:%02d:%02d (%d): ", getPrefixOfLevel(level), now2->tm_year + 1900, now2->tm_mon + 1, @@ -546,7 +546,7 @@ void RplFileAppender::open() { if(m_fp != NULL) fclose(m_fp); char fullName[512]; - snprintf(fullName, sizeof fullName, "%s.%03d.log", m_prefix.data(), + qsnprintf(fullName, sizeof fullName, "%s.%03d.log", m_prefix.data(), ++m_currentNo); m_fp = fopen(fullName, "a"); if(m_fp == NULL) diff --git a/rplcore/rplstring.cpp b/rplcore/rplstring.cpp index a9c4b83..635658c 100644 --- a/rplcore/rplstring.cpp +++ b/rplcore/rplstring.cpp @@ -135,7 +135,7 @@ QByteArray RplString::hexDump(uint8_t* data, int length, int bytesPerLine) { char buffer[16]; for(int lineNo = 0; lineNo < fullLines; lineNo++) { for(col = 0; col < bytesPerLine; col++) { - snprintf(buffer, sizeof buffer, "%02x ", data[ixData + col]); + qsnprintf(buffer, sizeof buffer, "%02x ", data[ixData + col]); rc.append(buffer); } rc.append(' '); @@ -150,7 +150,7 @@ QByteArray RplString::hexDump(uint8_t* data, int length, int bytesPerLine) { int restBytes = length - ixData; if(restBytes > 0) { for(col = 0; col < restBytes; col++) { - snprintf(buffer, sizeof buffer, "%02x ", data[ixData + col]); + qsnprintf(buffer, sizeof buffer, "%02x ", data[ixData + col]); rc.append(buffer); } for(col = restBytes; col < bytesPerLine; col++) { @@ -267,7 +267,7 @@ QByteArray RplString::toCString(const char* source, int maxLength){ default: { char buffer[5]; - snprintf(buffer, sizeof buffer, "\\x%02x", + qsnprintf(buffer, sizeof buffer, "\\x%02x", ((unsigned int) cc) % 0xff); rc += buffer; break; @@ -286,7 +286,7 @@ QByteArray RplString::toCString(const char* source, int maxLength){ */ QByteArray RplString::toNumber(int value, const char* format) { char buffer[128]; - snprintf(buffer, sizeof buffer, format, value); + qsnprintf(buffer, sizeof buffer, format, value); return QByteArray(buffer); } diff --git a/rplcore/rpltest.cpp b/rplcore/rpltest.cpp index 249efa6..ea31b61 100644 --- a/rplcore/rpltest.cpp +++ b/rplcore/rpltest.cpp @@ -358,12 +358,12 @@ bool RplTest::assertEqualFiles(const char* expected, const char* current, QByteArray currentContent = RplString::read(current, true); if (expectedContent.isEmpty()){ char buffer[512]; - snprintf(buffer, sizeof buffer, "%s has no content. Does it exist?", + qsnprintf(buffer, sizeof buffer, "%s has no content. Does it exist?", expected); error(buffer); } else if (currentContent.isEmpty()){ char buffer[512]; - snprintf(buffer, sizeof buffer, "%s has no content. Does it exist?", + qsnprintf(buffer, sizeof buffer, "%s has no content. Does it exist?", current); error(buffer); } else { diff --git a/rplcore/rplwriter.cpp b/rplcore/rplwriter.cpp index 3ec9ead..53e018b 100644 --- a/rplcore/rplwriter.cpp +++ b/rplcore/rplwriter.cpp @@ -84,7 +84,7 @@ void RplWriter::formatLine(const char* format, ...) char buffer[64000]; va_list ap; va_start(ap, format); - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); va_end(ap); writeLine(buffer); } @@ -98,7 +98,7 @@ void RplWriter::formatLine(const char* format, ...) void RplWriter::write(va_list ap, const char* format) { char buffer[64000]; - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); write(buffer); } @@ -128,7 +128,7 @@ void RplWriter::formatIndented(int indent, const char* format, ...) char buffer[64000]; va_list ap; va_start(ap, format); - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); va_end(ap); writeLine(buffer); } diff --git a/rplexpr/rplasclasses.cpp b/rplexpr/rplasclasses.cpp index 10b6638..c234568 100644 --- a/rplexpr/rplasclasses.cpp +++ b/rplexpr/rplasclasses.cpp @@ -126,11 +126,15 @@ void RplSymbolSpace::startScope(RplASScope& scope) * * @param scope the status of the scope at start. */ -void RplSymbolSpace::finishScope(RplASScope& scope) +void RplSymbolSpace::finishScope(int endOfScope, RplASScope& scope) { // in methods/classes not needed: - for (int ix = scope.m_varNoAtStart; ix < m_listOfVars.size(); ix++){ - const QString& name = m_listOfVars[ix]->name(); + int ix = scope.m_varNoAtStart - scope.m_builtInVars; + int last = m_listOfVars.size(); + for (; ix < last; ix++){ + RplASVarDefinition* var = m_listOfVars[ix]; + var->setEndOfScope(endOfScope); + const QString& name = var->name(); if (m_variables.contains(name)) m_variables.remove(name); } @@ -234,18 +238,11 @@ void RplSymbolSpace::dump(RplWriter& writer, int indent, const char* header) } } - if (m_variables.size() > 0){ + if (m_listOfVars.size() > 0){ writer.writeIndented(indent, "== Variables:"); - sorted.clear(); - sorted.reserve(m_variables.size()); - VariableMap::iterator it5; - for (it5 = m_variables.begin(); it5 != m_variables.end(); it5++){ - sorted.append(it5.key()); - } - qSort(sorted.begin(), sorted.end(), qLess()); QList::iterator it6; - for (it6 = sorted.begin(); it6 != sorted.end(); it6++){ - RplASVarDefinition* var = m_variables[*it6]; + for (int ix = 0; ix < m_listOfVars.size(); ix++){ + RplASVarDefinition* var = m_listOfVars[ix]; var->dump(writer, indent); } } diff --git a/rplexpr/rplasclasses.hpp b/rplexpr/rplasclasses.hpp index 8341867..72c2038 100644 --- a/rplexpr/rplasclasses.hpp +++ b/rplexpr/rplasclasses.hpp @@ -32,6 +32,7 @@ protected: class RplASScope { public: + int m_builtInVars; int m_varNoAtStart; }; @@ -61,7 +62,7 @@ public: virtual ~RplSymbolSpace(); public: void startScope(RplASScope& scope); - void finishScope(RplASScope& scope); + void finishScope(int endOfScope, RplASScope& scope); RplASVarDefinition* findVariable(const QString& name) const; RplASClass* findClass(const QString& name) const; RplASMethod* findMethod(const QString& name) const; diff --git a/rplexpr/rplastree.cpp b/rplexpr/rplastree.cpp index 41e10e9..a34a0d3 100644 --- a/rplexpr/rplastree.cpp +++ b/rplexpr/rplastree.cpp @@ -87,7 +87,7 @@ void RplASException::build(const RplSourcePosition* position, char buffer[64000]; if (position != NULL) m_message = position->toString().toUtf8(); - vsnprintf(buffer, sizeof buffer, format, varList); + qvsnprintf(buffer, sizeof buffer, format, varList); m_message += buffer; } @@ -522,12 +522,12 @@ void RplASItem::error(RplLogger* logger, int location, const char* format, ...) { char buffer[1024]; int halfBufferSize = (sizeof buffer) / 2; - snprintf(buffer, halfBufferSize, "id: %d [%s]:", m_id, + qsnprintf(buffer, halfBufferSize, "id: %d [%s]:", m_id, positionStr(buffer + halfBufferSize, halfBufferSize)); int length = strlen(buffer); va_list ap; va_start(ap, format); - vsnprintf(buffer + length, (sizeof buffer) - length, format, ap); + qvsnprintf(buffer + length, (sizeof buffer) - length, format, ap); va_end(ap); logger->log(LOG_ERROR, location, buffer); } @@ -883,7 +883,7 @@ RplASNamedValue::RplASNamedValue(RplASClass* dataType,RplSymbolSpace* space, m_attributes(attributes), m_dataType(dataType), m_symbolSpace(space), - m_variableNo(0) + m_variableNo(-1) { } @@ -1022,7 +1022,8 @@ void RplASIndexedValue::dump(RplWriter& writer, int indent) */ RplASVarDefinition::RplASVarDefinition() : RplASNode3(AST_VAR_DEFINITION), - RplASStatement() + RplASStatement(), + m_endOfScope(0) { m_flags |= NF_STATEMENT; } @@ -1037,13 +1038,19 @@ void RplASVarDefinition::dump(RplWriter& writer, int indent) { RplASNamedValue* namedValue = dynamic_cast(m_child2); QByteArray name = namedValue->name().toUtf8(); + char endOfScope[32]; + endOfScope[0] = '\0'; + if (m_endOfScope > 0) + qsnprintf(endOfScope, sizeof endOfScope, "-%d:0", m_endOfScope); char buffer[256]; - writer.formatIndented(indent, "varDef %s id: %d namedValue: %d value: %d succ: %d %s", + writer.formatIndented(indent, "varDef %s %s id: %d namedValue: %d value: %d succ: %d %s%s", + namedValue == NULL || namedValue->dataType() == NULL + ? "?" : namedValue->dataType()->name().toUtf8().constData(), name.constData(), m_id, m_child2 == NULL ? 0 : m_child2->id(), m_child3 == NULL ? 0 : m_child3->id(), m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + positionStr(buffer, sizeof buffer), endOfScope); if (m_child2 != NULL) m_child2->dump(writer, indent + 1); if (m_child3 != NULL) @@ -1073,6 +1080,28 @@ RplASClass* RplASVarDefinition::datatype() const RplASClass* rc = namedValue->dataType(); return rc; } +/** + * @brief Returns the column of the scope end. + * + * 0 means end of method or end of class + * + * @return 0 or the column of the scope end + */ +int RplASVarDefinition::endOfScope() const +{ + return m_endOfScope; +} + +/** + * @brief Sets the column of the scope end. + * + * @param endOfScope the column of the scope end + */ +void RplASVarDefinition::setEndOfScope(int endOfScope) +{ + m_endOfScope = endOfScope; +} + /** * @brief Executes the statement. @@ -1749,7 +1778,7 @@ void RplASIf::dump(RplWriter& writer, int indent) * * @param variable NULL or the iterator variable */ -RplASForIterated::RplASForIterated(RplASNamedValue* variable) : +RplASForIterated::RplASForIterated(RplASVarDefinition* variable) : RplASNode4(AST_ITERATED_FOR), RplASStatement() { @@ -1812,7 +1841,7 @@ void RplASForIterated::dump(RplWriter& writer, int indent) * * @param variable NULL or the counter variable */ -RplASForCounted::RplASForCounted(RplASNamedValue* variable) : +RplASForCounted::RplASForCounted(RplASVarDefinition* variable) : RplASNode6(AST_ITERATED_FOR), RplASStatement() { diff --git a/rplexpr/rplastree.hpp b/rplexpr/rplastree.hpp index 0d2816b..24d54ea 100644 --- a/rplexpr/rplastree.hpp +++ b/rplexpr/rplastree.hpp @@ -359,6 +359,14 @@ public: void dump(RplWriter& writer, int indent); const QString& name() const; RplASClass* datatype() const; + int endOfScope() const; + void setEndOfScope(int endOfScope); + +private: + /// the column of the blockend containing the definition. + /// if 0: end is end of method or end of class + /// Note: the source unit is stored in RplASItem::m_sourcePosition + int m_endOfScope; }; class RplASExprStatement : public RplASNode2, public RplASStatement @@ -478,7 +486,7 @@ public: class RplASForIterated : public RplASNode4, public RplASStatement { public: - RplASForIterated(RplASNamedValue* variable); + RplASForIterated(RplASVarDefinition* variable); public: virtual void execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); @@ -487,7 +495,7 @@ public: class RplASForCounted : public RplASNode6, public RplASStatement { public: - RplASForCounted(RplASNamedValue* variable); + RplASForCounted(RplASVarDefinition* variable); public: virtual void execute(RplVMThread& thread); virtual void dump(RplWriter& writer, int indent); diff --git a/rplexpr/rpllexer.cpp b/rplexpr/rpllexer.cpp index 183fde5..7899fc8 100644 --- a/rplexpr/rpllexer.cpp +++ b/rplexpr/rpllexer.cpp @@ -17,7 +17,6 @@ #define CHAR_INFO_SIZE (int(sizeof m_charInfo / sizeof m_charInfo[0])) -RplLexer* RplLexer::m_active = NULL; /** @class RplToken rpllexer.hpp "rplexpr/rpllexer.hpp" * @@ -40,7 +39,7 @@ RplLexException::RplLexException(const RplSourcePosition& position, m_message = position.toString().toUtf8(); va_list ap; va_start(ap, format); - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); va_end(ap); m_message += buffer; } @@ -241,6 +240,106 @@ bool RplToken::isCapitalizedId() const return rc; } +/** + * @brief Returns the description of the current token. + * + * @return a description of the instance + */ +QByteArray RplToken::dump() const +{ + QByteArray rc; + rc = nameOfType(m_tokenType); + rc.append(": ").append(this->asUtf8()); + return rc; +} +QByteArray RplToken::asUtf8() const +{ + char buffer[4096]; + buffer[0] = '\0'; + + switch(m_tokenType){ + case TOKEN_UNDEF: + break; + case TOKEN_STRING: + qsnprintf(buffer, sizeof buffer, "'%.*s'", int(sizeof buffer) - 1, + m_printableString.toUtf8().constData()); + break; + case TOKEN_NUMBER: + qsnprintf(buffer, sizeof buffer, "%lld", m_value.m_integer); + break; + case TOKEN_REAL: + qsnprintf(buffer, sizeof buffer, "%f", m_value.m_real); + break; + case TOKEN_KEYWORD: + case TOKEN_OPERATOR: + qsnprintf(buffer, sizeof buffer, "%lld", (int) m_value.m_id); + break; + case TOKEN_ID: + qsnprintf(buffer, sizeof buffer, "'%.*s'", int(sizeof buffer) - 1, + m_string.toUtf8().constData()); + break; + case TOKEN_COMMENT_REST_OF_LINE: + case TOKEN_COMMENT_START: + case TOKEN_COMMENT_END: + case TOKEN_SPACE: + case TOKEN_END_OF_SOURCE: + default: + break; + } + return buffer; +} +/** + * @brief Returns then name of a token type. + * @param type the type to convert + * @return the token type name + */ +const char* RplToken::nameOfType(RplTokenType type) +{ + const char* rc = "?"; + + switch(type){ + case TOKEN_UNDEF: + rc = "undef"; + break; + case TOKEN_STRING: + rc = "String"; + break; + case TOKEN_NUMBER: + rc = "Number"; + break; + case TOKEN_REAL: + rc = "Real"; + break; + case TOKEN_KEYWORD: + rc = "Keyword"; + break; + case TOKEN_OPERATOR: + rc = "Operator"; + break; + case TOKEN_ID: + rc = "Id"; + break; + case TOKEN_COMMENT_REST_OF_LINE: + rc = "Comment-1-line"; + break; + case TOKEN_COMMENT_START: + rc = "Comment-m-line"; + break; + case TOKEN_COMMENT_END: + rc = "end of comment"; + break; + case TOKEN_SPACE: + rc = "space"; + break; + case TOKEN_END_OF_SOURCE: + rc = "end of source"; + break; + default: + break; + } + return rc; +} + /** @class RplLexer rpllexer.hpp "rplexpr/rpllexer.hpp" * @@ -372,6 +471,9 @@ RplLexer::RplLexer(RplSource* source, m_storageFlags(storageFlags), // m_prioOfOp // m_assocOfOp + #if defined (RPL_LEXER_TRACE) + m_trace(true), + #endif m_opNames() { memset(m_prioOfOp, 0, sizeof m_prioOfOp); @@ -385,16 +487,12 @@ RplLexer::RplLexer(RplSource* source, charClassToCharInfo(restCharsId, CC_REST_ID, m_charInfo); initializeComments(comments); m_input.reserve(m_maxTokenLength*2); - if (m_active == NULL) - m_active = this; } /** * @brief Destructor. */ RplLexer::~RplLexer() { - if (m_active == this) - m_active = NULL; } /** @@ -826,6 +924,17 @@ void RplLexer::scanComment() m_input.remove(0, length); m_currentCol += length; } +#if defined (RPL_LEXER_TRACE) +bool RplLexer::trace() const +{ + return m_trace; +} + +void RplLexer::setTrace(bool trace) +{ + m_trace = trace; +} +#endif /** * @brief Returns the last read token. * @@ -952,6 +1061,15 @@ RplToken* RplLexer::nextToken() "unknown lexical symbol: %s", symbol.toUtf8().constData()); } } +#if defined (RPL_LEXER_TRACE) + if (m_trace){ + char buffer[256]; + printf("token: %s pos: %s\n", m_currentToken->dump().constData(), + m_currentPosition->utf8(buffer, sizeof buffer)); + if (strcmp(buffer, ":2:6") == 0) + buffer[0] = 0; + } +#endif return rc; } /** @@ -964,6 +1082,16 @@ void RplLexer::undoLastToken() m_waitingToken = m_currentToken; m_currentToken = m_currentToken == &m_token1 ? &m_token2 : &m_token1; m_waitingPosition1 = m_currentPosition; +#if defined (RPL_LEXER_TRACE) + if (m_trace){ + char buffer[256]; + printf("undo last token: waiting-token: %s pos: %s\n", + m_waitingToken->dump().constData(), + m_waitingPosition1->utf8(buffer, sizeof buffer)); + if (strcmp(buffer, ":2:6") == 0) + buffer[0] = 0; + } +#endif } /** diff --git a/rplexpr/rpllexer.hpp b/rplexpr/rpllexer.hpp index cfc8b8b..4fc0ce2 100644 --- a/rplexpr/rpllexer.hpp +++ b/rplexpr/rpllexer.hpp @@ -55,6 +55,9 @@ public: bool isKeyword(int expected, int alternative = 0) const; void clear(); bool isCapitalizedId() const; + QByteArray dump() const; + static const char* nameOfType(RplTokenType type); + QByteArray asUtf8() const; protected: RplTokenType m_tokenType; QString m_string; @@ -183,6 +186,8 @@ public: bool isRightAssociative(int op) const; const RplSourcePosition* currentPosition() const; RplToken* currentToken() const; + bool trace() const; + void setTrace(bool trace); private: void prepareOperators(const char* operators, const char* rightAssociatives); @@ -231,8 +236,10 @@ protected: char m_prioOfOp[128]; char m_assocOfOp[128]; QList m_opNames; -public: - static RplLexer* m_active; +//#define RPL_LEXER_TRACE +#if defined (RPL_LEXER_TRACE) + bool m_trace; +#endif }; diff --git a/rplexpr/rplmfparser.cpp b/rplexpr/rplmfparser.cpp index 653daff..b3aa969 100644 --- a/rplexpr/rplmfparser.cpp +++ b/rplexpr/rplmfparser.cpp @@ -157,6 +157,23 @@ RplASItem* RplMFParser::parseRepeat() return rc; } +/** + * @brief Creates a variable definition for a builtin variable. + * @param var the basic variable data + * @return + */ +RplASVarDefinition* RplMFParser::buildVarDef(RplASNamedValue* var) +{ + RplASVarDefinition* rc = new RplASVarDefinition(); + rc->setPosition(var->position()); + rc->setChild2(var); + RplSymbolSpace* symbols = m_tree.currentSpace(); + int varNo; + symbols->addVariable(rc, varNo); + var->setVariableNo(varNo); + return rc; +} + /** * @brief Parses a for statement. * @@ -171,6 +188,7 @@ RplASItem* RplMFParser::parseRepeat() */ RplASItem* RplMFParser::parseFor() { + int builtinVars = 1; RplASNode2* rc = NULL; const RplSourcePosition* startPosition = m_lexer.currentPosition(); RplToken* token = m_lexer.nextNonSpaceToken(); @@ -183,14 +201,26 @@ RplASItem* RplMFParser::parseFor() token = m_lexer.nextNonSpaceToken(); } if (token->isKeyword(K_IN)){ - RplASForIterated* node = new RplASForIterated(var); + RplASVarDefinition* varDef = buildVarDef(var); + RplASForIterated* node = new RplASForIterated(varDef); rc = node; node->setPosition(startPosition); node->setChild3(var); RplASItem* iterable = parseExpr(0); node->setChild4(iterable); } else { - RplASForCounted* node = new RplASForCounted(var); + if (var == NULL){ + char name[32]; + // Build a unique name inside the scope: + qsnprintf(name, sizeof name, "$%d_%d", startPosition->lineNo(), + startPosition->column()); + var = new RplASNamedValue(RplASInteger::m_instance, + m_tree.currentSpace(), name, + RplASNamedValue::A_LOOP); + var->setPosition(startPosition); + } + RplASVarDefinition* varDef = buildVarDef(var); + RplASForCounted* node = new RplASForCounted(varDef); rc = node; node->setPosition(startPosition); node->setChild3(var); @@ -207,7 +237,7 @@ RplASItem* RplMFParser::parseFor() } if (! m_lexer.currentToken()->isKeyword(K_DO)) syntaxError(L_PARSE_FOR_NO_TO, "'to' expected"); - rc->setChild2(parseBody(K_OD)); + rc->setChild2(parseBody(K_OD, K_UNDEF, builtinVars)); m_lexer.nextNonSpaceToken(); return rc; } @@ -503,7 +533,7 @@ RplASItem* RplMFParser::buildVarOrField(const QString& name, RplASItem* rc = NULL; if (parent == NULL){ RplSymbolSpace* space = m_tree.currentSpace(); - RplASVarDefinition* var = space->findVariable(var->name()); + RplASVarDefinition* var = space->findVariable(name); RplASClass* clazz = NULL; if (var != NULL) clazz = var->datatype(); @@ -642,6 +672,8 @@ RplASItem* RplMFParser::parseOperand(int level, RplASItem* parent) case TOKEN_ID: { QString name = token->toString(); + if (name == "a") + name = "a"; token = m_lexer.nextNonSpaceToken(); startPosition = m_lexer.currentPosition(); if (token->tokenType() != TOKEN_OPERATOR){ @@ -920,12 +952,11 @@ RplASItem* RplMFParser::parseLocalVar(){ * * @param keywordStop the first possible keyword which finishes the stm. list * @param keywordStop2 the 2nd possible keyword which finishes the statements - * @param opStop the first possible delimiting operator - * @param opStop2 the 2nd possible delimiting operator + * @param builtinVars number of variables valid only in this body * @return the first element of the statement list */ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, - Operator opStop, Operator opStop2) + int builtinVars) { RplToken* token = m_lexer.nextNonSpaceToken(); RplASItem* item = NULL; @@ -933,6 +964,7 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, RplASNode1* lastStatement = NULL; RplASScope scope; m_tree.currentSpace()->startScope(scope); + scope.m_builtInVars = builtinVars; bool again = true; const RplSourcePosition* lastPos = NULL; do { @@ -947,11 +979,6 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, switch(token->tokenType()) { case TOKEN_OPERATOR: - if (opStop != O_UNDEF && token->isOperator(opStop, opStop2)){ - again = false; - break; - } - // fall through case TOKEN_STRING: case TOKEN_NUMBER: case TOKEN_REAL: @@ -1019,10 +1046,8 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, error(L_PARSE_BODY_WRONG_ITEM, "wrong item type: %d", item == NULL ? 0 : item->nodeType()); token = m_lexer.currentToken(); - if ((keywordStop != K_UNDEF + if (keywordStop != K_UNDEF && token->isKeyword(keywordStop, keywordStop2)) - || (opStop != O_UNDEF - && token->isOperator(opStop, opStop2))) again = false; } } catch(RplSyntaxError exc){ @@ -1053,8 +1078,10 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, } } while(again); - if (keywordStop != K_ENDF && keywordStop != K_ENDC) - m_tree.currentSpace()->finishScope(scope); + if (keywordStop != K_ENDF && keywordStop != K_ENDC + && keywordStop != K_UNDEF) + m_tree.currentSpace()->finishScope(m_lexer.currentPosition()->lineNo(), + scope); return body; } diff --git a/rplexpr/rplmfparser.hpp b/rplexpr/rplmfparser.hpp index 44df6e1..36b4532 100644 --- a/rplexpr/rplmfparser.hpp +++ b/rplexpr/rplmfparser.hpp @@ -74,7 +74,7 @@ public: RplASItem* parseVarDefinition(RplASNamedValue::Attributes attribute); RplASItem* parseExpr(int depth); RplASItem* parseBody(Keyword keywordStop, Keyword keywordStop2 = K_UNDEF, - Operator opStop = O_UNDEF, Operator opStop2 = O_UNDEF); + int builtinVars = 0); void parseMethod(); void parseClass(); void parseImport(); @@ -94,6 +94,7 @@ protected: RplASItem* parent); RplASExprStatement*parseParameterList(); RplASItem* parseLocalVar(); + RplASVarDefinition* buildVarDef(RplASNamedValue* var); protected: static RplASBinaryOp::BinOperator convertBinaryOp(int op); static RplASUnaryOp::UnaryOp convertUnaryOp(int op); diff --git a/rplexpr/rplparser.cpp b/rplexpr/rplparser.cpp index 815c63c..81b1011 100644 --- a/rplexpr/rplparser.cpp +++ b/rplexpr/rplparser.cpp @@ -104,7 +104,7 @@ void RplParser::addSimpleMessage(LevelTag prefix, int location, const char* message){ char buffer[2048]; QString msg; - snprintf(buffer, sizeof buffer, "%c%04d %s:%d-%d: ", prefix, location, + qsnprintf(buffer, sizeof buffer, "%c%04d %s:%d-%d: ", prefix, location, position->sourceUnit()->name(), position->lineNo(), position->column()); int used = strlen(buffer); @@ -129,7 +129,7 @@ void RplParser::addMessage(LevelTag prefix, int location, const RplSourcePosition* position, const char* format, va_list varList){ char buffer[2048]; - vsnprintf(buffer, sizeof buffer, format, varList); + qvsnprintf(buffer, sizeof buffer, format, varList); addSimpleMessage(prefix, location, position, buffer); } @@ -169,7 +169,7 @@ void RplParser::syntaxError(int location, const char* message, { char buffer[256]; char buffer2[512]; - snprintf(buffer2, sizeof buffer2, + qsnprintf(buffer2, sizeof buffer2, "The starting symbol %s is located here. Missing point: %s", symbol, m_lexer.currentPosition()->utf8(buffer, sizeof buffer)); diff --git a/rplexpr/rplsource.cpp b/rplexpr/rplsource.cpp index 3c1e359..3711899 100644 --- a/rplexpr/rplsource.cpp +++ b/rplexpr/rplsource.cpp @@ -171,7 +171,7 @@ QString RplSourcePosition::toString() const */ char* RplSourcePosition::utf8(char buffer[], size_t bufferSize) const { - snprintf(buffer, bufferSize, "%s:%d:%d", + qsnprintf(buffer, bufferSize, "%s:%d:%d", m_sourceUnit == NULL ? "" : m_sourceUnit->name(), m_lineNo, m_column); return buffer; diff --git a/rplexpr/rplvm.cpp b/rplexpr/rplvm.cpp index 2c681af..873d3e4 100644 --- a/rplexpr/rplvm.cpp +++ b/rplexpr/rplvm.cpp @@ -47,7 +47,7 @@ RplVmException::RplVmException(const char* format, ...) : char buffer[16000]; va_list ap; va_start(ap, format); - vsnprintf(buffer, sizeof buffer, format, ap); + qvsnprintf(buffer, sizeof buffer, format, ap); va_end(ap); m_message = buffer; } diff --git a/rplmath/rplmatrix.cpp b/rplmath/rplmatrix.cpp index fe268b0..872af7b 100644 --- a/rplmath/rplmatrix.cpp +++ b/rplmath/rplmatrix.cpp @@ -25,7 +25,7 @@ RplMatrixException::RplMatrixException(const RplMatrix& RplMatrix, va_list args; va_start(args, format); - vsnprintf(buffer, sizeof buffer, format, args); + qvsnprintf(buffer, sizeof buffer, format, args); va_end(args); m_message += buffer; } @@ -347,13 +347,13 @@ QByteArray RplMatrix::toString(const char* prefix, const char* format, char buffer[128]; Tuple2 minMaxi(minMax()); QByteArray rc; - snprintf(buffer, sizeof buffer, format, minMaxi.m_value1); + qsnprintf(buffer, sizeof buffer, format, minMaxi.m_value1); int length = strlen(buffer); - snprintf(buffer, sizeof buffer, format, minMaxi.m_value2); + qsnprintf(buffer, sizeof buffer, format, minMaxi.m_value2); int length2 = strlen(buffer); if (length < length2) length = length2; - snprintf(buffer, sizeof buffer, format, + qsnprintf(buffer, sizeof buffer, format, (minMaxi.m_value1 + minMaxi.m_value2) / 2); length2 = strlen(buffer); if (length < length2) @@ -367,7 +367,7 @@ QByteArray RplMatrix::toString(const char* prefix, const char* format, rc += "["; for (int row = 0; row < m_rows; row++){ for (int col = 0; col < m_cols; col++){ - snprintf(buffer, sizeof buffer, format, m_values[m_cols*row + col]); + qsnprintf(buffer, sizeof buffer, format, m_values[m_cols*row + col]); rc += buffer; rc += colSeparator; } diff --git a/test/rplmfparser/defTest.txt b/test/rplmfparser/defTest.txt deleted file mode 100644 index e8826b3..0000000 --- a/test/rplmfparser/defTest.txt +++ /dev/null @@ -1,20 +0,0 @@ -Int i = 3; const lazy Str s = 'Hi'; const List l; -= (module) parent: $global -== Variables: -varDef i id: 2 namedValue: 1 value: 3 succ: 5 :1:4 - namedValue i id: 1 attr: 0x0 :1:4 - const id: 3 value: 3 :1:8 -varDef l id: 8 namedValue: 7 value: 0 succ: 0 :1:47 - namedValue l id: 7 attr: 0x2 :1:47 -varDef s id: 5 namedValue: 4 value: 6 succ: 8 :1:26 - namedValue s id: 4 attr: 0x12 :1:26 - const id: 6 value: 'Hi' :1:30 -== Body: -varDef i id: 2 namedValue: 1 value: 3 succ: 5 :1:4 - namedValue i id: 1 attr: 0x0 :1:4 - const id: 3 value: 3 :1:8 -varDef s id: 5 namedValue: 4 value: 6 succ: 8 :1:26 - namedValue s id: 4 attr: 0x12 :1:26 - const id: 6 value: 'Hi' :1:30 -varDef l id: 8 namedValue: 7 value: 0 succ: 0 :1:47 - namedValue l id: 7 attr: 0x2 :1:47 diff --git a/test/rplmfparser/forC1.txt b/test/rplmfparser/forC1.txt index 5a5517a..73215c3 100644 --- a/test/rplmfparser/forC1.txt +++ b/test/rplmfparser/forC1.txt @@ -4,18 +4,20 @@ a += 1; od = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 +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 a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 +varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 namedValue a id: 1 attr: 0x0 :1:4 -forC id: 4 var: 3 from: 5 to: 6 step: 7 body: 12 succ: 0 :1:7 - namedValue b id: 3 attr: 0x0 :2:4 - const id: 5 value: 10 :2:11 - const id: 6 value: 1 :2:17 - Unary 7 op: - (2) expr: 8 :2:24 - const id: 8 value: 2 :2:25 - Expr id: 12 expr: 10 succ: 0 :3:2 - BinOp id: 10 op: += (2) left: 9 right: 11 :3:2 - namedValue a id: 9 attr: 0x0 :3:2 - const id: 11 value: 1 :3:5 +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 index 4db7cf7..008df5a 100644 --- a/test/rplmfparser/forC2.txt +++ b/test/rplmfparser/forC2.txt @@ -1,14 +1,17 @@ Int a; for to 10 do a += 1 od = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 +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 a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 +varDef Int a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 namedValue a id: 1 attr: 0x0 :1:4 -forC id: 3 var: 0 from: 0 to: 4 step: 0 body: 8 succ: 0 :1:7 - const id: 4 value: 10 :1:14 - Expr id: 8 expr: 6 succ: 0 :1:22 - BinOp id: 6 op: += (2) left: 5 right: 7 :1:22 - namedValue a id: 5 attr: 0x0 :1:22 - const id: 7 value: 1 :1:25 +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 index 66071de..297f1c2 100644 --- a/test/rplmfparser/forIt1.txt +++ b/test/rplmfparser/forIt1.txt @@ -4,15 +4,17 @@ a += 1; od = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 +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 a id: 2 namedValue: 1 value: 0 succ: 4 :1:4 +varDef Map a id: 2 namedValue: 1 value: 0 succ: 5 :1:4 namedValue a id: 1 attr: 0x0 :1:4 -forIt id: 4 var: 3 set: 5 body: 9 succ: 0 :1:7 - namedValue x id: 3 attr: 0x0 :2:4 - namedValue a id: 5 attr: 0x0 :2:11 - Expr id: 9 expr: 7 succ: 0 :3:2 - BinOp id: 7 op: += (2) left: 6 right: 8 :3:2 - namedValue a id: 6 attr: 0x0 :3:2 - const id: 8 value: 1 :3:5 +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/list1.txt b/test/rplmfparser/list1.txt index 9c0026e..c326ad0 100644 --- a/test/rplmfparser/list1.txt +++ b/test/rplmfparser/list1.txt @@ -1,12 +1,12 @@ List b = []; = (module) parent: $global == Variables: -varDef b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 +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 b id: 2 namedValue: 1 value: 3 succ: 0 :1:5 +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 index 1f2deea..828cedd 100644 --- a/test/rplmfparser/list2.txt +++ b/test/rplmfparser/list2.txt @@ -1,20 +1,20 @@ List a = [2+3, 3.14, 7, 'hi', a]; List b = []; = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 +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 b id: 11 namedValue: 10 value: 12 succ: 0 :1:39 +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 a id: 2 namedValue: 1 value: 3 succ: 11 :1:5 +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 b id: 11 namedValue: 10 value: 12 succ: 0 :1:39 +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 index 1e51ff7..f140c85 100644 --- a/test/rplmfparser/map1.txt +++ b/test/rplmfparser/map1.txt @@ -1,12 +1,12 @@ Map a = {}; = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 +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 a id: 2 namedValue: 1 value: 3 succ: 0 :1:4 +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 index 35c7852..fd4ae67 100644 --- a/test/rplmfparser/map2.txt +++ b/test/rplmfparser/map2.txt @@ -2,20 +2,20 @@ Map a = {'a': 2+3,'bcd':3.14,'ccc':7, 'hi':'world'}; Map b = {}; = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 +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 b id: 11 namedValue: 10 value: 12 succ: 0 :2:4 +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 a id: 2 namedValue: 1 value: 3 succ: 11 :1:4 +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 b id: 11 namedValue: 10 value: 12 succ: 0 :2:4 +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/meth2.txt b/test/rplmfparser/meth2.txt index cca30a2..bd20165 100644 --- a/test/rplmfparser/meth2.txt +++ b/test/rplmfparser/meth2.txt @@ -5,9 +5,9 @@ rc endf == Methods: Method fac() id: 1 parent: args: 4 body: 6 :0:55 Expr id: 4 expr: 3 succ: 0 - varDef n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + varDef Int n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 namedValue n id: 2 attr: 0x22 :1:23 - varDef rc id: 6 namedValue: 5 value: 0 succ: 7 :2:4 + 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 @@ -31,7 +31,7 @@ Method fac() id: 1 parent: args: 4 body: 6 :0:55 namedValue rc id: 25 attr: 0x0 :3:3 = .fac (method) parent: == Variables: - varDef n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + varDef Int n id: 3 namedValue: 2 value: 0 succ: 0 :1:23 namedValue n id: 2 attr: 0x22 :1:23 - varDef rc id: 6 namedValue: 5 value: 0 succ: 7 :2:4 + 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 index f3fe793..0808991 100644 --- a/test/rplmfparser/meth3.txt +++ b/test/rplmfparser/meth3.txt @@ -10,7 +10,7 @@ endf == Methods: Method max() id: 21 parent: args: 24 body: 40 :5:5 Expr id: 24 expr: 23 succ: 27 - varDef a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 + 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 @@ -24,9 +24,9 @@ Method max() id: 21 parent: args: 24 body: 40 :5:5 namedValue c id: 37 attr: 0x0 :7:15 = .max (method) parent: == Variables: - varDef a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 + varDef Int a id: 23 namedValue: 22 value: 0 succ: 0 :6:23 namedValue a id: 22 attr: 0x22 :6:23 - varDef b id: 26 namedValue: 25 value: 0 succ: 0 :6:30 + varDef Int b id: 26 namedValue: 25 value: 0 succ: 0 :6:30 namedValue b id: 25 attr: 0x20 :6:30 - varDef c id: 29 namedValue: 28 value: 0 succ: 0 :6:37 + 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 index 3414ab6..9d237c5 100644 --- a/test/rplmfparser/meth4.txt +++ b/test/rplmfparser/meth4.txt @@ -10,7 +10,7 @@ endf == Methods: Method max() id: 1 parent: args: 4 body: 40 :0:4 Expr id: 4 expr: 3 succ: 7 - varDef a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + 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 @@ -26,9 +26,9 @@ Method max() id: 1 parent: args: 4 body: 40 :0:4 == Methods: Method max() id: 11 parent: .max args: 14 body: 19 :1:41 Expr id: 14 expr: 13 succ: 17 - varDef a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 + varDef Int a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 namedValue a id: 12 attr: 0x20 :2:17 - varDef rc id: 19 namedValue: 18 value: 20 succ: 21 :3:5 + 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 @@ -43,17 +43,17 @@ Method max() id: 1 parent: args: 4 body: 40 :0:4 namedValue rc id: 29 attr: 0x0 :5:3 = .max.max (method) parent: .max == Variables: - varDef a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 + varDef Int a id: 13 namedValue: 12 value: 0 succ: 0 :2:17 namedValue a id: 12 attr: 0x20 :2:17 - varDef b id: 16 namedValue: 15 value: 0 succ: 0 :2:24 + varDef Int b id: 16 namedValue: 15 value: 0 succ: 0 :2:24 namedValue b id: 15 attr: 0x20 :2:24 - varDef rc id: 19 namedValue: 18 value: 20 succ: 21 :3:5 + 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 a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 + varDef Int a id: 3 namedValue: 2 value: 0 succ: 0 :1:23 namedValue a id: 2 attr: 0x22 :1:23 - varDef b id: 6 namedValue: 5 value: 0 succ: 0 :1:30 + varDef Int b id: 6 namedValue: 5 value: 0 succ: 0 :1:30 namedValue b id: 5 attr: 0x20 :1:30 - varDef c id: 9 namedValue: 8 value: 0 succ: 0 :1:37 + 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/opTest1.txt b/test/rplmfparser/opTest1.txt index 91b1fc3..d34ba9f 100644 --- a/test/rplmfparser/opTest1.txt +++ b/test/rplmfparser/opTest1.txt @@ -6,17 +6,17 @@ a--*++b**(8-3); a=b=(a+(b-2)*3) = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 +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 b id: 5 namedValue: 4 value: 6 succ: 9 :2:4 +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 a id: 2 namedValue: 1 value: 3 succ: 5 :1:4 +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 b id: 5 namedValue: 4 value: 6 succ: 9 :2:4 +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 diff --git a/test/rplmfparser/repeatTest.txt b/test/rplmfparser/repeatTest.txt index cf15252..b23a54a 100644 --- a/test/rplmfparser/repeatTest.txt +++ b/test/rplmfparser/repeatTest.txt @@ -4,10 +4,10 @@ a++; until a != 2 * 3; = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 +varDef Int a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 namedValue a id: 1 attr: 0x0 :1:4 == Body: -varDef a id: 2 namedValue: 1 value: 0 succ: 3 :1:4 +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 diff --git a/test/rplmfparser/varDefTest.txt b/test/rplmfparser/varDefTest.txt new file mode 100644 index 0000000..2d9cafd --- /dev/null +++ b/test/rplmfparser/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/rplmfparser/whileTest.txt b/test/rplmfparser/whileTest.txt index 64c22dc..981d612 100644 --- a/test/rplmfparser/whileTest.txt +++ b/test/rplmfparser/whileTest.txt @@ -4,11 +4,11 @@ while 3 < 5 do od = (module) parent: $global == Variables: -varDef a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 +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 a id: 2 namedValue: 1 value: 3 succ: 4 :1:4 +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 diff --git a/unittests/main.cpp b/unittests/main.cpp index cda0fae..f72f9d3 100644 --- a/unittests/main.cpp +++ b/unittests/main.cpp @@ -31,7 +31,7 @@ void testExpr(){ testRplBenchmark(); extern void testRplVM(); - //testRplVM(); + testRplVM(); extern void testRplMFParser(); testRplMFParser(); diff --git a/unittests/rplmfparser_test.cpp b/unittests/rplmfparser_test.cpp index c2841b8..6ecc5ed 100644 --- a/unittests/rplmfparser_test.cpp +++ b/unittests/rplmfparser_test.cpp @@ -61,11 +61,11 @@ public: checkAST("baseTest.txt", __LINE__); } - void defTest(){ - setSource("Int i = 3; const lazy Str s = 'Hi'; const List l;"); + void varDefTest(){ + setSource("const lazy Str s = 'Hi';\nconst List l;\nInt i = 3;"); RplMFParser parser(m_source, m_tree); parser.parse(); - checkAST("defTest.txt", __LINE__); + checkAST("varDefTest.txt", __LINE__); } void ifTest(){ @@ -176,6 +176,10 @@ public: checkAST("meth4.txt", __LINE__); } virtual void doIt(void) { + varDefTest(); + repeatTest(); + baseTest(); + whileTest(); methodTest(); fieldTest(); methodCallTest(); @@ -184,11 +188,6 @@ public: forCTest(); listTest(); opTest(); - ifTest(); - whileTest(); - repeatTest(); - defTest(); - baseTest(); } }; void testRplMFParser() { diff --git a/unittests/rplsource_test.cpp b/unittests/rplsource_test.cpp index 23aef30..ecc05fc 100644 --- a/unittests/rplsource_test.cpp +++ b/unittests/rplsource_test.cpp @@ -78,6 +78,7 @@ protected: reader.addSource("source1", m_content1_1 + m_content1_2); reader.addSource("source2", m_content2); RplSourceUnit* unit = reader.openSourceUnit("source1"); + checkNN(unit); checkE("source1", unit->name()); checkE(0, unit->lineNo()); checkOne(6, reader);