From: hama Date: Sun, 24 Aug 2014 10:59:32 +0000 (+0200) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=f5f76577aa372b82a6ffad24ff5513a080e21655;p=reqt dayly work --- diff --git a/bench/mk_bench.pl b/bench/mk_bench.pl index 666f0dd..7902cf2 100644 --- a/bench/mk_bench.pl +++ b/bench/mk_bench.pl @@ -10,7 +10,13 @@ my $loops = shift; $loops = 200 unless $loops; print "count: $count loops: $loops\n"; -if ($lang =~ /^py/i){ +if ($lang =~ /^all/i){ + &pyAssign; + &cppAssign; + &javaAssign; + &plAssign; + &mfAssign; +} elsif ($lang =~ /^py/i){ &pyAssign; } elsif ($lang =~ /^j/i){ &javaAssign; diff --git a/rplcore/rplcharptrmap.cpp b/rplcore/rplcharptrmap.cpp new file mode 100644 index 0000000..bcaf414 --- /dev/null +++ b/rplcore/rplcharptrmap.cpp @@ -0,0 +1,64 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. +*/ + + +#include "rplcore/rplcore.hpp" + +/** @class RplKeyCharPtr rplcharptrmap.hpp "rplcore/rplcharptrmap.hpp" + * + * @brief Allows using char* pointers as key in QMap. + * + * The template QMap uses the operator < to search in the map. + * But the char* pointers have no such an operator. + * The solution is the class RplMapCharPtr which implements + * this operator. + * + * strcmp() is used to implement the '<' operator. + */ + +/** + * @brief Constructor. + * + * @param ptr the key used in the map. + */ +RplKeyCharPtr::RplKeyCharPtr(const char* ptr) : + m_ptr(ptr) +{ +} + + +/** @class RplCharPtrMap rplcharptrmap.hpp "rplcore/rplcharptrmap.hpp" + * + * @brief A template for a map using const char* as keys. + * + * The value type is dynamic (a parameter type of the template). + * + * Usage: + *

+ * RplCharPtrMap ids;
+ * if (! id.contains("jonny"))
+ *    ids["jonny"] = 1;
+ * 
+ * + * Important:
+ * Keys used with this class must be unchangable and must live during the + * whole life of the map. + * + * Wrong example: + *

+ * RplCharPtrMap ids;
+ * void init(int keyNo, int value){
+ *    char key[10];
+ *    qsnprintf(buffer, sizeof buffer, "key%d", keyNo);
+ *    ids[key] = value;
+ * }
+ * init(1, 100);
+ * 
+ * The lifetime of the key is the body of the function init(). + * The key becomes invalid after the call. + */ diff --git a/rplcore/rplcharptrmap.hpp b/rplcore/rplcharptrmap.hpp new file mode 100644 index 0000000..93df1c7 --- /dev/null +++ b/rplcore/rplcharptrmap.hpp @@ -0,0 +1,37 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. +*/ + + +#ifndef RPLCHARPTRMAP_HPP +#define RPLCHARPTRMAP_HPP + +class RplKeyCharPtr { + friend bool operator <(RplKeyCharPtr const& op1, RplKeyCharPtr const& op2); +public: + RplKeyCharPtr(const char* ptr); +private: + const char* m_ptr; +}; +/** + * @brief Compares two instances of the class RplKeyCharPtr. + * @param op1 1st operand + * @param op2 2nd operand + * @return true: op1 < op2
+ * false: op1 >= op2 + */ +inline bool operator <(RplKeyCharPtr const& op1, RplKeyCharPtr const& op2){ + bool rc = strcmp(op1.m_ptr, op2.m_ptr) < 0; + return rc; +} + +template +class RplCharPtrMap : public QMap +{ +}; + +#endif // RPLCHARPTRMAP_HPP diff --git a/rplcore/rplcore.hpp b/rplcore/rplcore.hpp index a09be09..8df4f75 100644 --- a/rplcore/rplcore.hpp +++ b/rplcore/rplcore.hpp @@ -35,6 +35,7 @@ typedef unsigned char uint8_t; #include "rplmodules.hpp" #include "rplcore/rplbytestorage.hpp" +#include "rplcore/rplcharptrmap.hpp" #include "rplcore/rplwriter.hpp" #include "rplcore/rpllogger.hpp" #include "rplcore/rplexception.hpp" diff --git a/rpldoc.zip b/rpldoc.zip index 340d79e..4958194 100644 Binary files a/rpldoc.zip and b/rpldoc.zip differ diff --git a/rplexpr/rplasclasses.cpp b/rplexpr/rplasclasses.cpp index c234568..aab5963 100644 --- a/rplexpr/rplasclasses.cpp +++ b/rplexpr/rplasclasses.cpp @@ -124,7 +124,9 @@ void RplSymbolSpace::startScope(RplASScope& scope) * * Finishes the "live" of the variables created in the ending scope. * - * @param scope the status of the scope at start. + * @param endOfScope line (inside the current source unit) which finishes the + * scope + * @param scope the status of the scope at start. */ void RplSymbolSpace::finishScope(int endOfScope, RplASScope& scope) { diff --git a/rplexpr/rplastree.cpp b/rplexpr/rplastree.cpp index a34a0d3..df05d16 100644 --- a/rplexpr/rplastree.cpp +++ b/rplexpr/rplastree.cpp @@ -85,8 +85,10 @@ void RplASException::build(const RplSourcePosition* position, const char* format, va_list varList) { char buffer[64000]; - if (position != NULL) + if (position != NULL){ m_message = position->toString().toUtf8(); + m_message += ": "; + } qvsnprintf(buffer, sizeof buffer, format, varList); m_message += buffer; } @@ -874,6 +876,7 @@ RplASMapOfVariants* RplASMapConstant::map() * * @param dataType the data type (class) * @param name the name of the variable + * @param space the current symbol space * @param attributes the attributes of the variable */ RplASNamedValue::RplASNamedValue(RplASClass* dataType,RplSymbolSpace* space, diff --git a/rplexpr/rpllexer.cpp b/rplexpr/rpllexer.cpp index 7899fc8..f573ab5 100644 --- a/rplexpr/rpllexer.cpp +++ b/rplexpr/rpllexer.cpp @@ -1066,7 +1066,7 @@ RplToken* RplLexer::nextToken() 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) + if (strstr(buffer, "0:28") != NULL) buffer[0] = 0; } #endif diff --git a/rplexpr/rpllexer.hpp b/rplexpr/rpllexer.hpp index 4fc0ce2..232f6f9 100644 --- a/rplexpr/rpllexer.hpp +++ b/rplexpr/rpllexer.hpp @@ -10,6 +10,7 @@ #ifndef RPLLEXER_HPP #define RPLLEXER_HPP +//#define RPL_LEXER_TRACE enum RplTokenType { TOKEN_UNDEF, @@ -186,9 +187,10 @@ public: bool isRightAssociative(int op) const; const RplSourcePosition* currentPosition() const; RplToken* currentToken() const; +#if defined RPL_LEXER_TRACE bool trace() const; void setTrace(bool trace); - +#endif private: void prepareOperators(const char* operators, const char* rightAssociatives); void initializeComments(const char* comments); @@ -236,7 +238,6 @@ protected: char m_prioOfOp[128]; char m_assocOfOp[128]; QList m_opNames; -//#define RPL_LEXER_TRACE #if defined (RPL_LEXER_TRACE) bool m_trace; #endif diff --git a/rplexpr/rplsource.cpp b/rplexpr/rplsource.cpp index 3711899..576744f 100644 --- a/rplexpr/rplsource.cpp +++ b/rplexpr/rplsource.cpp @@ -297,9 +297,11 @@ RplSourceUnit* RplReader::currentSourceUnit() const { /** * @brief Sets the current source unit. * - * @param sourceUnit the name of the new source unit + * @param sourceUnit the name of the new source unit + * @return true: source unit exists
+ * false: source unit not found */ -bool RplReader::setCurrentSourceUnit(RplSourceUnitName sourceUnit) { +bool RplReader::setCurrentSourceUnit(RplSourceUnitName& sourceUnit) { bool rc = m_units.contains(sourceUnit); if(rc) { m_currentSourceUnit = m_units.value(sourceUnit); @@ -815,6 +817,8 @@ bool RplFileReader::nextLine(int maxSize, RplSourceUnitContent& buffer, if(! rc) { m_source.popSourceUnit(this); } else { + m_currentSourceUnit->setLineNo(m_currentSourceUnit->lineNo() + 1); + unit->m_currentPosition = 0; unit->m_line = unit->m_textStream.readLine(); rc = fillBuffer(maxSize, buffer, hasMore); } @@ -849,7 +853,7 @@ bool RplFileReader::fillBuffer(int maxSize, RplSourceUnitContent& buffer, /** * @brief Adds a source file to the reader * - * @param dirEntry the file + * @param filename the file' name (relative or absolute) */ void RplFileReader::addSource(RplSourceUnitName filename) { // Deleting in ~RplSourceUnit(): diff --git a/rplexpr/rplsource.hpp b/rplexpr/rplsource.hpp index f0f95a5..61f4c47 100644 --- a/rplexpr/rplsource.hpp +++ b/rplexpr/rplsource.hpp @@ -108,7 +108,7 @@ public: virtual void clear(); RplSource& source(); RplSourceUnit* currentSourceUnit() const; - bool setCurrentSourceUnit(RplSourceUnitName currentSourceUnit); + bool setCurrentSourceUnit(RplSourceUnitName& currentSourceUnit); protected: void removeSourceUnit(); diff --git a/rplstatic/rplstatic.pro b/rplstatic/rplstatic.pro index 6936ccc..2263c8d 100644 --- a/rplstatic/rplstatic.pro +++ b/rplstatic/rplstatic.pro @@ -39,7 +39,8 @@ SOURCES += \ ../rplexpr/rplvm.cpp \ ../rplexpr/rplparser.cpp \ ../rplcore/rplbytestorage.cpp \ - ../rplcore/rplwriter.cpp + ../rplcore/rplwriter.cpp \ + ../rplcore/rplcharptrmap.cpp HEADERS += ../rplmodules.hpp \ ../rplcore/rplconfig.hpp \ @@ -70,7 +71,8 @@ HEADERS += ../rplmodules.hpp \ ../rplexpr/rplvm.hpp \ ../rplexpr/rplparser.hpp \ ../rplcore/rplbytestorage.hpp \ - ../rplcore/rplwriter.hpp + ../rplcore/rplwriter.hpp \ + ../rplcore/rplcharptrmap.hpp unix:!symbian { maemo5 { diff --git a/unittests/main.cpp b/unittests/main.cpp index f72f9d3..2cb6555 100644 --- a/unittests/main.cpp +++ b/unittests/main.cpp @@ -11,6 +11,9 @@ #include void testCore(){ + extern void testRplCharPtrMap(); + testRplCharPtrMap(); + extern void testRplWriter(); testRplWriter(); @@ -27,33 +30,37 @@ void testCore(){ } void testExpr(){ + extern void testRplSource(); + testRplSource(); extern void testRplBenchmark(); - testRplBenchmark(); + //testRplBenchmark(); extern void testRplVM(); - testRplVM(); + //testRplVM(); extern void testRplMFParser(); testRplMFParser(); extern void testRplASTree(); testRplASTree(); - extern void testRplSource(); - testRplSource(); extern void testRplLexer(); testRplLexer(); } void testStandard(){ - testExpr(); + //testExpr(); testCore(); extern void testRplMatrix(); testRplMatrix(); } +void labor(){ +} + int main(int argc, char *argv[]) { + //labor(); if (argc > 1) printf("not used: %s\n", argv[1]); diff --git a/unittests/rplcharptrmap_test.cpp b/unittests/rplcharptrmap_test.cpp new file mode 100644 index 0000000..3600efb --- /dev/null +++ b/unittests/rplcharptrmap_test.cpp @@ -0,0 +1,34 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. +*/ + +#include "rplcore/rplcore.hpp" +#include "rplcore/rpltest.hpp" + +class TestRplCharPtrMap : public RplTest{ +public: + TestRplCharPtrMap() : + RplTest("RplCharPtrMap") + { + } +protected: + void testBasic(){ + RplCharPtrMap map; + map["x"] = "x1"; + checkT(map.contains("x")); + checkF(map.contains("y")); + checkE("x1", map["x"]); + } + + virtual void doIt(void) { + testBasic(); + } +}; +void testRplCharPtrMap() { + TestRplCharPtrMap test; + test.run(); +} diff --git a/unittests/rplvm_test.cpp b/unittests/rplvm_test.cpp index 16767fa..8425c95 100644 --- a/unittests/rplvm_test.cpp +++ b/unittests/rplvm_test.cpp @@ -57,7 +57,7 @@ private: } public: void baseTest(){ - setSource("Int a=2+3*4"); + setSource("Int a=2+3*4;"); checkAST("baseTest.txt", __LINE__); } virtual void doIt(void) { diff --git a/unittests/unittests.pro b/unittests/unittests.pro index 6728c27..1dede45 100644 --- a/unittests/unittests.pro +++ b/unittests/unittests.pro @@ -43,5 +43,6 @@ SOURCES += main.cpp \ rplvm_test.cpp \ rplbytestorage_test.cpp \ rplwriter_test.cpp \ - rplbench.cpp + rplbench.cpp \ + rplcharptrmap_test.cpp