From 59e0f0942a45ef3176c0eb1d4d442384b455da28 Mon Sep 17 00:00:00 2001 From: hama Date: Sat, 4 Apr 2015 01:06:57 +0200 Subject: [PATCH] Refactoring: names similar to crepublib --- appl/qfilesearch | 1 + .../ReByteStorage.cpp | 25 +- .../ReByteStorage.hpp | 16 +- .../ReCharPtrMap.cpp | 12 +- .../ReCharPtrMap.hpp | 18 +- rplcore/rplconfig.cpp => base/ReConfig.cpp | 83 +- rplcore/rplconfig.hpp => base/ReConfig.hpp | 16 +- .../ReConfigurator.hpp | 8 +- .../rplcontainer.cpp => base/ReContainer.cpp | 132 +-- .../rplcontainer.hpp => base/ReContainer.hpp | 20 +- .../rplexception.cpp => base/ReException.cpp | 36 +- base/ReException.hpp | 45 + rplcore/rpllogger.cpp => base/ReLogger.cpp | 144 +-- rplcore/rpllogger.hpp => base/ReLogger.hpp | 108 +-- rplcore/rplqstring.cpp => base/ReQString.cpp | 20 +- rplcore/rplqstring.hpp => base/ReQtring.hpp | 10 +- .../rplstring.cpp => base/ReStringUtil.cpp | 50 +- .../rplstring.hpp => base/ReStringUtil.hpp | 2 +- .../ReTerminator.cpp | 22 +- .../ReTerminator.hpp | 14 +- rplcore/rpltest.cpp => base/ReTest.cpp | 67 +- rplcore/rpltest.hpp => base/ReTest.hpp | 38 +- rplcore/rplwriter.cpp => base/ReWriter.cpp | 42 +- rplcore/rplwriter.hpp => base/ReWriter.hpp | 14 +- rplcore/rplcore.hpp => base/rebase.hpp | 39 +- {rplcore => base}/testrplexample.cpp | 12 +- cunit/cuReConfig.cpp | 60 ++ cunit/cuReContainer.cpp | 58 ++ cunit/cuReEnigma.cpp | 112 +++ {unittests => cunit}/main.cpp | 28 +- cunit/rplastree_test.cpp | 103 ++ {unittests => cunit}/rplbench.cpp | 22 +- {unittests => cunit}/rplbytestorage_test.cpp | 24 +- {unittests => cunit}/rplcharptrmap_test.cpp | 16 +- {unittests => cunit}/rplexception_test.cpp | 22 +- {unittests => cunit}/rpllexer_test.cpp | 144 +-- {unittests => cunit}/rplmatrix_test.cpp | 124 +-- {unittests => cunit}/rplmfparser_test.cpp | 62 +- cunit/rplqstring_test.cpp | 125 +++ {unittests => cunit}/rplsource_test.cpp | 50 +- cunit/rplstring_test.cpp | 196 ++++ {unittests => cunit}/rplvm_test.cpp | 34 +- {unittests => cunit}/rplwriter_test.cpp | 14 +- {unittests => cunit}/unittests.pro | 0 rplexpr/rplastree.cpp => expr/ReASTree.cpp | 918 +++++++++--------- expr/ReASTree.hpp | 759 +++++++++++++++ .../rplasclasses.cpp => expr/ReAsClasses.cpp | 344 +++---- .../rplasclasses.hpp => expr/ReAsClasses.hpp | 148 +-- rplexpr/rpllexer.cpp => expr/ReLexer.cpp | 154 +-- rplexpr/rpllexer.hpp => expr/ReLexer.hpp | 64 +- .../rplmfparser.cpp => expr/ReMFParser.cpp | 472 ++++----- .../rplmfparser.hpp => expr/ReMFParser.hpp | 60 +- rplexpr/rplparser.cpp => expr/ReParser.cpp | 48 +- rplexpr/rplparser.hpp => expr/ReParser.hpp | 28 +- rplexpr/rplsource.cpp => expr/ReSource.cpp | 238 ++--- rplexpr/rplsource.hpp => expr/ReSource.hpp | 164 ++-- rplexpr/rplvm.cpp => expr/ReVM.cpp | 161 +-- expr/ReVM.hpp | 114 +++ rplexpr/rplexpr.hpp => expr/reexpr.hpp | 2 +- rplmath/rplenigma.cpp => math/ReEnigma.cpp | 166 +--- rplmath/rplenigma.hpp => math/ReEnigma.hpp | 16 +- rplmath/rplmatrix.cpp => math/ReMatrix.cpp | 353 +++---- rplmath/rplmatrix.hpp => math/ReMatrix.hpp | 2 +- rplmath/rplrandom.cpp => math/ReRandom.cpp | 33 +- math/ReRandom.hpp | 26 + rplmath/rplmath.hpp => math/remath.hpp | 11 +- net/ReNetConfig.cpp | 15 + .../rplnetconfig.hpp => net/ReNetConfig.hpp | 2 +- .../rpltcpclient.cpp => net/ReTCPClient.cpp | 36 +- .../rpltcpclient.hpp => net/ReTCPClient.hpp | 30 +- rplnet/rpltcppeer.cpp => net/ReTCPPeer.cpp | 76 +- rplnet/rpltcppeer.hpp => net/ReTCPPeer.hpp | 32 +- .../rpltcpserver.cpp => net/ReTCPServer.cpp | 66 +- .../rpltcpserver.hpp => net/ReTCPServer.hpp | 78 +- rplnet/rplnet.hpp => net/renet.hpp | 10 +- remodules.hpp | 29 + rplcore/rplexception.hpp | 45 - rplexpr/rplastree.hpp | 755 -------------- rplexpr/rplvm.hpp | 111 --- rplmath/rplrandom.hpp | 27 - rplmodules.hpp | 31 - rplnet/rplnetconfig.cpp | 14 - rplstatic/getsrc.pl | 29 - rplstatic/rplstatic.pro | 84 -- static/rplstatic.pro | 83 ++ {rplstatic => static}/rplstaticlib.cpp | 2 +- {rplstatic => static}/rplstaticlib.hpp | 0 unittests/rplastree_test.cpp | 103 -- unittests/rplqstring_test.cpp | 125 --- unittests/rplstring_test.cpp | 196 ---- 90 files changed, 4244 insertions(+), 4204 deletions(-) create mode 160000 appl/qfilesearch rename rplcore/rplbytestorage.cpp => base/ReByteStorage.cpp (85%) rename rplcore/rplbytestorage.hpp => base/ReByteStorage.hpp (79%) rename rplcore/rplcharptrmap.cpp => base/ReCharPtrMap.cpp (84%) rename rplcore/rplcharptrmap.hpp => base/ReCharPtrMap.hpp (54%) rename rplcore/rplconfig.cpp => base/ReConfig.cpp (66%) rename rplcore/rplconfig.hpp => base/ReConfig.hpp (72%) rename rplcore/rplconfigurator.hpp => base/ReConfigurator.hpp (80%) rename rplcore/rplcontainer.cpp => base/ReContainer.cpp (77%) rename rplcore/rplcontainer.hpp => base/ReContainer.hpp (87%) rename rplcore/rplexception.cpp => base/ReException.cpp (86%) create mode 100644 base/ReException.hpp rename rplcore/rpllogger.cpp => base/ReLogger.cpp (78%) rename rplcore/rpllogger.hpp => base/ReLogger.hpp (56%) rename rplcore/rplqstring.cpp => base/ReQString.cpp (90%) rename rplcore/rplqstring.hpp => base/ReQtring.hpp (75%) rename rplcore/rplstring.cpp => base/ReStringUtil.cpp (90%) rename rplcore/rplstring.hpp => base/ReStringUtil.hpp (98%) rename rplcore/rplterminator.cpp => base/ReTerminator.cpp (69%) rename rplcore/rplterminator.hpp => base/ReTerminator.hpp (63%) rename rplcore/rpltest.cpp => base/ReTest.cpp (87%) rename rplcore/rpltest.hpp => base/ReTest.hpp (77%) rename rplcore/rplwriter.cpp => base/ReWriter.cpp (79%) rename rplcore/rplwriter.hpp => base/ReWriter.hpp (86%) rename rplcore/rplcore.hpp => base/rebase.hpp (52%) rename {rplcore => base}/testrplexample.cpp (78%) create mode 100644 cunit/cuReConfig.cpp create mode 100644 cunit/cuReContainer.cpp create mode 100644 cunit/cuReEnigma.cpp rename {unittests => cunit}/main.cpp (75%) create mode 100644 cunit/rplastree_test.cpp rename {unittests => cunit}/rplbench.cpp (72%) rename {unittests => cunit}/rplbytestorage_test.cpp (79%) rename {unittests => cunit}/rplcharptrmap_test.cpp (65%) rename {unittests => cunit}/rplexception_test.cpp (59%) rename {unittests => cunit}/rpllexer_test.cpp (69%) rename {unittests => cunit}/rplmatrix_test.cpp (71%) rename {unittests => cunit}/rplmfparser_test.cpp (82%) create mode 100644 cunit/rplqstring_test.cpp rename {unittests => cunit}/rplsource_test.cpp (68%) create mode 100644 cunit/rplstring_test.cpp rename {unittests => cunit}/rplvm_test.cpp (71%) rename {unittests => cunit}/rplwriter_test.cpp (72%) rename {unittests => cunit}/unittests.pro (100%) rename rplexpr/rplastree.cpp => expr/ReASTree.cpp (76%) create mode 100644 expr/ReASTree.hpp rename rplexpr/rplasclasses.cpp => expr/ReAsClasses.cpp (69%) rename rplexpr/rplasclasses.hpp => expr/ReAsClasses.hpp (53%) rename rplexpr/rpllexer.cpp => expr/ReLexer.cpp (90%) rename rplexpr/rpllexer.hpp => expr/ReLexer.hpp (86%) rename rplexpr/rplmfparser.cpp => expr/ReMFParser.cpp (74%) rename rplexpr/rplmfparser.hpp => expr/ReMFParser.hpp (64%) rename rplexpr/rplparser.cpp => expr/ReParser.cpp (84%) rename rplexpr/rplparser.hpp => expr/ReParser.hpp (70%) rename rplexpr/rplsource.cpp => expr/ReSource.cpp (71%) rename rplexpr/rplsource.hpp => expr/ReSource.hpp (51%) rename rplexpr/rplvm.cpp => expr/ReVM.cpp (66%) create mode 100644 expr/ReVM.hpp rename rplexpr/rplexpr.hpp => expr/reexpr.hpp (95%) rename rplmath/rplenigma.cpp => math/ReEnigma.cpp (64%) rename rplmath/rplenigma.hpp => math/ReEnigma.hpp (85%) rename rplmath/rplmatrix.cpp => math/ReMatrix.cpp (61%) rename rplmath/rplmatrix.hpp => math/ReMatrix.hpp (98%) rename rplmath/rplrandom.cpp => math/ReRandom.cpp (77%) create mode 100644 math/ReRandom.hpp rename rplmath/rplmath.hpp => math/remath.hpp (65%) create mode 100644 net/ReNetConfig.cpp rename rplnet/rplnetconfig.hpp => net/ReNetConfig.hpp (95%) rename rplnet/rpltcpclient.cpp => net/ReTCPClient.cpp (75%) rename rplnet/rpltcpclient.hpp => net/ReTCPClient.hpp (73%) rename rplnet/rpltcppeer.cpp => net/ReTCPPeer.cpp (82%) rename rplnet/rpltcppeer.hpp => net/ReTCPPeer.hpp (75%) rename rplnet/rpltcpserver.cpp => net/ReTCPServer.cpp (70%) rename rplnet/rpltcpserver.hpp => net/ReTCPServer.hpp (56%) rename rplnet/rplnet.hpp => net/renet.hpp (71%) create mode 100644 remodules.hpp delete mode 100644 rplcore/rplexception.hpp delete mode 100644 rplexpr/rplastree.hpp delete mode 100644 rplexpr/rplvm.hpp delete mode 100644 rplmath/rplrandom.hpp delete mode 100644 rplmodules.hpp delete mode 100644 rplnet/rplnetconfig.cpp delete mode 100644 rplstatic/getsrc.pl delete mode 100644 rplstatic/rplstatic.pro create mode 100644 static/rplstatic.pro rename {rplstatic => static}/rplstaticlib.cpp (87%) rename {rplstatic => static}/rplstaticlib.hpp (100%) delete mode 100644 unittests/rplastree_test.cpp delete mode 100644 unittests/rplqstring_test.cpp delete mode 100644 unittests/rplstring_test.cpp diff --git a/appl/qfilesearch b/appl/qfilesearch new file mode 160000 --- /dev/null +++ b/appl/qfilesearch @@ -0,0 +1 @@ +Subproject commit 0000000000000000000000000000000000000000 diff --git a/rplcore/rplbytestorage.cpp b/base/ReByteStorage.cpp similarity index 85% rename from rplcore/rplbytestorage.cpp rename to base/ReByteStorage.cpp index df1600b..033c048 100644 --- a/rplcore/rplbytestorage.cpp +++ b/base/ReByteStorage.cpp @@ -15,20 +15,19 @@ * @brief Definitions for a very efficient storage for bytes and C strings. */ -#include "rplcore/rplcore.hpp" - -/** @class RplByteStorage rplbytestorage.hpp "rplcore/rplbytestorage.hpp" +#include "base/rebase.hpp" +/** @class ReByteStorage ReByteStorage.hpp "base/ReByteStorage.hpp" * * @brief Implements a very efficient byte storage. * * Efficiency: Allocation of one block needs mostly only 1 comparison * and 2 assignments. * - * Restriction: The blocks can be returned (freed) only once, not block by block. + * Restriction: The blocks can be returned (freed) only all together, not block by block. * This can be an advantage! * * Process: - * The storage administrates large buffers. Allocation can be done only in the + * The storage manages large buffers. Allocation can be done only in the * last buffer. If the buffer has too little space for the new block a new * buffer will be allocated and linked into the buffer list. * One buffer can store dozens or hundreds of blocks. Therefore allocation and @@ -40,7 +39,7 @@ * * @param bufferSize the size of one buffer */ -RplByteStorage::RplByteStorage(int bufferSize) : +ReByteStorage::ReByteStorage(int bufferSize) : m_bufferSize(bufferSize), m_buffer(NULL), m_rest(0), @@ -53,7 +52,7 @@ RplByteStorage::RplByteStorage(int bufferSize) : /** * @brief Destructor. */ -RplByteStorage::~RplByteStorage() +ReByteStorage::~ReByteStorage() { const uint8_t* ptr = m_buffer; while(ptr != NULL){ @@ -77,7 +76,7 @@ RplByteStorage::~RplByteStorage() * @param size of the new block (inclusive the trailing '\0') * @return a new block with the size bytes */ -char* RplByteStorage::allocBuffer(int size) +char* ReByteStorage::allocBuffer(int size) { m_rest = size + sizeof(uint8_t*) <= (size_t) m_bufferSize ? m_bufferSize : size + sizeof(uint8_t*); @@ -101,7 +100,7 @@ char* RplByteStorage::allocBuffer(int size) * If < 0 strlen(source) will be used * @return a copy of the source string. The copy ends always with '\0' */ -const char* RplByteStorage::allocateChars(const char* source, int size) +const char* ReByteStorage::allocateChars(const char* source, int size) { if (size < 0) size = strlen(source); @@ -119,7 +118,7 @@ const char* RplByteStorage::allocateChars(const char* source, int size) * @param source the source string * @return a copy of the source string. The copy ends always with '\0' */ -const char* RplByteStorage::allocUtf8(const QString& source) +const char* ReByteStorage::allocUtf8(const ReString& source) { const char* rc = allocateChars(source.toUtf8().constData()); return rc; @@ -132,7 +131,7 @@ const char* RplByteStorage::allocUtf8(const QString& source) * * @return a byte block (without a trailing '\0') */ -uint8_t* RplByteStorage::allocateBytes(int size) +uint8_t* ReByteStorage::allocateBytes(int size) { uint8_t* rc = size <= m_rest ? m_freePosition : reinterpret_cast(allocBuffer(size)); @@ -148,7 +147,7 @@ uint8_t* RplByteStorage::allocateBytes(int size) * * @return a byte block (without a trailing '\0') */ -uint8_t* RplByteStorage::allocateZeros(int size) +uint8_t* ReByteStorage::allocateZeros(int size) { uint8_t* rc = allocateBytes(size); memset(rc, 0, size); @@ -162,7 +161,7 @@ uint8_t* RplByteStorage::allocateZeros(int size) * @param size the size of the block to allocate * @return a byte block (without a trailing '\0') */ -uint8_t* RplByteStorage::allocateBytes(void* source, int size) +uint8_t* ReByteStorage::allocateBytes(void* source, int size) { uint8_t* rc = allocateBytes(size); memcpy(rc, source, size); diff --git a/rplcore/rplbytestorage.hpp b/base/ReByteStorage.hpp similarity index 79% rename from rplcore/rplbytestorage.hpp rename to base/ReByteStorage.hpp index 41e0a9c..51496b6 100644 --- a/rplcore/rplbytestorage.hpp +++ b/base/ReByteStorage.hpp @@ -7,14 +7,14 @@ */ -#ifndef RPLCHARSTORAGE_HPP -#define RPLCHARSTORAGE_HPP +#ifndef RECHARSTORAGE_HPP +#define RECHARSTORAGE_HPP -class RplByteStorage +class ReByteStorage { public: - RplByteStorage(int blockSize); - ~RplByteStorage(); + ReByteStorage(int blockSize); + ~ReByteStorage(); public: char* allocBuffer(int size); /** @@ -30,7 +30,7 @@ public: return rc; } const char* allocateChars(const char* source, int size = -1); - const char* allocUtf8(const QString& source); + const char* allocUtf8(const ReString& source); uint8_t* allocateBytes(int size); uint8_t* allocateZeros(int size); uint8_t*allocateBytes(void* source, int size); @@ -39,8 +39,8 @@ private: uint8_t* m_buffer; int m_rest; uint8_t* m_freePosition; - qint64 m_summarySize; + int64_t m_summarySize; int m_buffers; }; -#endif // RPLCHARSTORAGE_HPP +#endif // RECHARSTORAGE_HPP diff --git a/rplcore/rplcharptrmap.cpp b/base/ReCharPtrMap.cpp similarity index 84% rename from rplcore/rplcharptrmap.cpp rename to base/ReCharPtrMap.cpp index a995536..d421b62 100644 --- a/rplcore/rplcharptrmap.cpp +++ b/base/ReCharPtrMap.cpp @@ -7,9 +7,9 @@ */ -#include "rplcore/rplcore.hpp" +#include "base/rebase.hpp" -/** @class RplKeyCharPtr rplcharptrmap.hpp "rplcore/rplcharptrmap.hpp" +/** @class ReKeyCharPtr ReCharPtrMap.hpp "base/ReCharPtrMap.hpp" * * @brief Allows using char* pointers as key in QMap. * @@ -28,13 +28,13 @@ * @note the pointer will be stored in the map as a key, * not the content */ -RplKeyCharPtr::RplKeyCharPtr(const char* ptr) : +ReKeyCharPtr::ReKeyCharPtr(const char* ptr) : m_ptr(ptr) { } -/** @class RplCharPtrMap rplcharptrmap.hpp "rplcore/rplcharptrmap.hpp" +/** @class ReCharPtrMap ReCharPtrMap.hpp "base/ReCharPtrMap.hpp" * * @brief A template for a map using const char* as keys. * @@ -42,7 +42,7 @@ RplKeyCharPtr::RplKeyCharPtr(const char* ptr) : * * Usage: *

- * RplCharPtrMap ids;
+ * ReCharPtrMap ids;
  * if (! id.contains("jonny"))
  *    ids["jonny"] = 1;
  * 
@@ -53,7 +53,7 @@ RplKeyCharPtr::RplKeyCharPtr(const char* ptr) : * * Wrong example: *

- * RplCharPtrMap ids;
+ * ReCharPtrMap ids;
  * void init(int keyNo, int value){
  *    char key[10];
  *    qsnprintf(buffer, sizeof buffer, "key%d", keyNo);
diff --git a/rplcore/rplcharptrmap.hpp b/base/ReCharPtrMap.hpp
similarity index 54%
rename from rplcore/rplcharptrmap.hpp
rename to base/ReCharPtrMap.hpp
index 93df1c7..f76bcfb 100644
--- a/rplcore/rplcharptrmap.hpp
+++ b/base/ReCharPtrMap.hpp
@@ -7,31 +7,31 @@
 */
 
 
-#ifndef RPLCHARPTRMAP_HPP
-#define RPLCHARPTRMAP_HPP
+#ifndef RECHARPTRMAP_HPP
+#define RECHARPTRMAP_HPP
 
-class RplKeyCharPtr {
-    friend bool operator <(RplKeyCharPtr const& op1, RplKeyCharPtr const& op2);
+class ReKeyCharPtr {
+    friend bool operator <(ReKeyCharPtr const& op1, ReKeyCharPtr const& op2);
 public:
-    RplKeyCharPtr(const char* ptr);
+    ReKeyCharPtr(const char* ptr);
 private:
     const char* m_ptr;
 };
 /**
- * @brief Compares two instances of the class RplKeyCharPtr.
+ * @brief Compares two instances of the class ReKeyCharPtr.
  * @param op1   1st operand
  * @param op2   2nd operand
  * @return      true: op1 < op2
* false: op1 >= op2 */ -inline bool operator <(RplKeyCharPtr const& op1, RplKeyCharPtr const& op2){ +inline bool operator <(ReKeyCharPtr const& op1, ReKeyCharPtr const& op2){ bool rc = strcmp(op1.m_ptr, op2.m_ptr) < 0; return rc; } template -class RplCharPtrMap : public QMap +class ReCharPtrMap : public QMap { }; -#endif // RPLCHARPTRMAP_HPP +#endif // RECHARPTRMAP_HPP diff --git a/rplcore/rplconfig.cpp b/base/ReConfig.cpp similarity index 66% rename from rplcore/rplconfig.cpp rename to base/ReConfig.cpp index 642a647..b605572 100644 --- a/rplcore/rplconfig.cpp +++ b/base/ReConfig.cpp @@ -5,7 +5,7 @@ * 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 "base/rebase.hpp" /** @file * @@ -16,7 +16,7 @@ * @brief Definitions for reading/writing configuration files. */ -/** @class RplConfig rplconfig.hpp "rplcore/rplconfig.hpp" +/** @class ReConfig ReConfig.hpp "base/ReConfig.hpp" * * @brief Imports and exports a configuration file into a QHash instance. * @@ -31,7 +31,7 @@ */ enum Locations { - LOC_WRITE_1 = RPL_FIRST_OF(RPLMODULE_CONFIG), // 10201 + LOC_WRITE_1 = LOC_FIRST_OF(LOC_CONFIG), // 10201 LOC_WRITE_2, LOC_READ_1, LOC_READ_2, @@ -46,7 +46,7 @@ enum Locations { * @param readOnly true: the configuration must not be written * @param logger NULL or a logger */ -RplConfig::RplConfig(const char* file, bool readOnly, RplLogger* logger) : +ReConfig::ReConfig(const char* file, bool readOnly, ReLogger* logger) : m_file(file), m_lineList(), m_readOnly(readOnly), @@ -64,7 +64,7 @@ RplConfig::RplConfig(const char* file, bool readOnly, RplLogger* logger) : * * Frees the resources. */ -RplConfig::~RplConfig() { +ReConfig::~ReConfig() { if(m_ownLogger) delete m_logger; m_logger = NULL; @@ -73,13 +73,13 @@ RplConfig::~RplConfig() { /** * Inititializes a logger. */ -void RplConfig::initLogger() { - m_logger = new RplLogger(); - RplMemoryAppender* appender = new RplMemoryAppender(); +void ReConfig::initLogger() { + m_logger = new ReLogger(); + ReMemoryAppender* appender = new ReMemoryAppender(); appender->setAutoDelete(true); m_logger->addAppender(appender); - RplStreamAppender* appender2 = new RplStreamAppender(stdout); + ReStreamAppender* appender2 = new ReStreamAppender(stdout); appender2->setAutoDelete(true); m_logger->addAppender(appender2); } @@ -92,7 +92,7 @@ void RplConfig::initLogger() { * @return defaultValue: key does not exist * otherwise: the value assigned to key */ -int RplConfig::asInt(const char* key, int defaultValue) const { +int ReConfig::asInt(const char* key, int defaultValue) const { int rc = defaultValue; if(contains(key)) { rc = atoi((*this)[key]); @@ -108,7 +108,7 @@ int RplConfig::asInt(const char* key, int defaultValue) const { * @return defaultValue: key does not exist * otherwise: the value assigned to key */ -bool RplConfig::asBool(const char* key, bool defaultValue) const { +bool ReConfig::asBool(const char* key, bool defaultValue) const { bool rc = defaultValue; if(contains(key)) { QByteArray value = (*this)[key].toLower(); @@ -126,7 +126,7 @@ bool RplConfig::asBool(const char* key, bool defaultValue) const { * @param defaultValue if the key does not exist this is the result * @return defaultValue: key does not exist */ -QByteArray RplConfig::asString(const char* key, const char* defaultValue) { +QByteArray ReConfig::asString(const char* key, const char* defaultValue) { QByteArray rc = defaultValue; if(contains(key)) { rc = (*this)[key]; @@ -141,7 +141,7 @@ QByteArray RplConfig::asString(const char* key, const char* defaultValue) { * @return true: OK
* false: error occurred */ -bool RplConfig::read(const char* file) { +bool ReConfig::read(const char* file) { bool rc = true; m_lineList.reserve(1024); FILE* fp = fopen(file, "r"); @@ -178,7 +178,7 @@ bool RplConfig::read(const char* file) { * @return true: OK
* false: error occurred */ -bool RplConfig::write(const char* file) { +bool ReConfig::write(const char* file) { bool rc = false; if(m_readOnly) m_logger->log(LOG_ERROR, LOC_WRITE_1, "cannot write: (readonly"); @@ -189,58 +189,3 @@ bool RplConfig::write(const char* file) { return rc; } -// ------------------ -#if ! defined RPL_TEST -#define RPL_TEST -#endif -#ifdef RPL_TEST -#include "rplcore/rpltest.hpp" -/** - * @brief Unit test of RplConfig. - */ -class TestRplConfig: public RplTest { -public: - TestRplConfig() : - RplTest("RplConfig") { - } - -public: - void testBasic() { - QByteArray fn = getTempFile("test.data", "config"); - RplString::write(fn, "#comment\na=1\nb.1==x\n#=\nB=zzz"); - RplConfig config(fn.constData()); - checkE(3, config.size()); - checkE("1", config["a"]); - checkE("=x", config["b.1"]); - checkE("zzz", config["B"]); - } - void testAsX() { - QByteArray fn = getTempFile("test.data", "config"); - RplString::write(fn, "i=123\nb=1\nb2=true\nb3=yes\ns=abc"); - RplConfig config(fn.constData()); - checkE(5, config.size()); - checkE(123, config.asInt("i", -1)); - checkE(-1, config.asInt("I", -1)); - checkT(config.asBool("b", false)); - checkT(config.asBool("b2", false)); - checkT(config.asBool("b3", false)); - checkT(config.asBool("-", true)); - checkF(config.asBool("-", false)); - checkE("abc", config.asString("s", "x")); - checkE("x", config.asString("S", "x")); - } - - virtual void doIt() { - testAsX(); - testBasic(); - - } -}; - -#endif -void testRplConfig() { -#ifdef RPL_TEST - TestRplConfig test; - test.run(); -#endif -} diff --git a/rplcore/rplconfig.hpp b/base/ReConfig.hpp similarity index 72% rename from rplcore/rplconfig.hpp rename to base/ReConfig.hpp index abf3a71..70fa36e 100644 --- a/rplcore/rplconfig.hpp +++ b/base/ReConfig.hpp @@ -5,14 +5,14 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#ifndef RPLCONFIG_HPP -#define RPLCONFIG_HPP +#ifndef RECONFIG_HPP +#define RECONFIG_HPP -class RplConfig : public RplConfigurator, public QHash { +class ReConfig : public ReConfigurator, public QHash { public: - RplConfig(const char* file = NULL, bool readOnly = true, - RplLogger* logger = NULL); - virtual ~RplConfig(); + ReConfig(const char* file = NULL, bool readOnly = true, + ReLogger* logger = NULL); + virtual ~ReConfig(); public: bool read(const char* file); @@ -29,9 +29,9 @@ private: const char* m_file; QList m_lineList; bool m_readOnly; - RplLogger* m_logger; + ReLogger* m_logger; // true: the logger must be destroyed in the destructor bool m_ownLogger; }; -#endif // RPLCONFIG_HPP +#endif // RECONFIG_HPP diff --git a/rplcore/rplconfigurator.hpp b/base/ReConfigurator.hpp similarity index 80% rename from rplcore/rplconfigurator.hpp rename to base/ReConfigurator.hpp index c651800..ab201bc 100644 --- a/rplcore/rplconfigurator.hpp +++ b/base/ReConfigurator.hpp @@ -5,14 +5,14 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#ifndef RPLCONFIGURATOR_HPP -#define RPLCONFIGURATOR_HPP +#ifndef RECONFIGURATOR_HPP +#define RECONFIGURATOR_HPP -class RplConfigurator { +class ReConfigurator { public: virtual int asInt(const char* key, int defaultValue) const = 0; virtual bool asBool(const char* key, bool defaultValue) const = 0; virtual QByteArray asString(const char* key, const char* defaultValue) = 0; }; -#endif // RPLCONFIGURATOR_HPP +#endif // RECONFIGURATOR_HPP diff --git a/rplcore/rplcontainer.cpp b/base/ReContainer.cpp similarity index 77% rename from rplcore/rplcontainer.cpp rename to base/ReContainer.cpp index c05b7bf..9e8e251 100644 --- a/rplcore/rplcontainer.cpp +++ b/base/ReContainer.cpp @@ -5,18 +5,18 @@ * 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 "base/rebase.hpp" /** @file * @brief Implements a portable data container. */ -/** @file rplcore/rplcontainer.hpp +/** @file recore/ReContainer.hpp * * @brief Definition for a portable data container. */ -/** @class RplContainer rplcontainer.hpp "rplcore/rplcontainer.hpp" +/** @class ReContainer ReContainer.hpp "base/ReContainer.hpp" * * @brief Implements a portable data container. * @@ -45,7 +45,7 @@ enum { // 11000 - LOC_FILL_1 = RPLMODULE_CONTAINER * 1000, + LOC_FILL_1 = LOC_CONTAINER * 1000, LOC_FILL_2, LOC_FILL_3, LOC_NEXT_BAG_1, @@ -56,14 +56,14 @@ enum { LOC_NEXT_BAG_2, }; -const char* RplContainer::MAGIC_1 = "Rpl&1"; +const char* ReContainer::MAGIC_1 = "Rpl&1"; /** * @brief Constructor. * * @param sizeHint Probable length of the container */ -RplContainer::RplContainer(size_t sizeHint) : +ReContainer::ReContainer(size_t sizeHint) : m_data(""), m_countBags(0), m_typeList(""), @@ -77,7 +77,7 @@ RplContainer::RplContainer(size_t sizeHint) : /** * @brief Destructor. */ -RplContainer::~RplContainer() { +ReContainer::~ReContainer() { } /** @@ -85,7 +85,7 @@ RplContainer::~RplContainer() { * * @param tag the type tag */ -void RplContainer::addType(type_tag_t tag) { +void ReContainer::addType(type_tag_t tag) { if(m_countBags == 0) startBag(); if(m_countBags == 1) @@ -95,7 +95,7 @@ void RplContainer::addType(type_tag_t tag) { /** * @brief Starts a new bag. */ -void RplContainer::startBag() { +void ReContainer::startBag() { m_countBags++; m_ixBag = 0; } @@ -104,10 +104,10 @@ void RplContainer::startBag() { * * @param value value to insert */ -void RplContainer::addChar(char value) { +void ReContainer::addChar(char value) { addType(TAG_CHAR); //if (m_typeList.at(m_ixBag) != TAG_INT) - // RplLogger::logAndThrow(LOG_ERROR, __FILE__, __LINE__, 1, "unexpected type: %c instead of c", m_typeList.at(m_ixBag)); + // ReLogger::logAndThrow(LOG_ERROR, __FILE__, __LINE__, 1, "unexpected type: %c instead of c", m_typeList.at(m_ixBag)); m_data.append(value); } /** @@ -115,7 +115,7 @@ void RplContainer::addChar(char value) { * * @param value value to add */ -void RplContainer::addInt(int value) { +void ReContainer::addInt(int value) { addType(TAG_INT); char buffer[64]; char* ptr = buffer; @@ -131,7 +131,7 @@ void RplContainer::addInt(int value) { * * @param value value to add */ -void RplContainer::addInt(qint64 value) { +void ReContainer::addInt(int64_t value) { addType(TAG_INT); char buffer[128]; qsnprintf(buffer, sizeof buffer, "%llx ", value); @@ -143,7 +143,7 @@ void RplContainer::addInt(qint64 value) { * * @param value value to add */ -void RplContainer::addString(const char* value) { +void ReContainer::addString(const char* value) { addType(TAG_STRING); // store with trailing '\0' m_data.append(value, strlen(value) + 1); @@ -154,7 +154,7 @@ void RplContainer::addString(const char* value) { * @param value binary data * @param size size of the binary data in bytes */ -void RplContainer::addData(uint8_t* value, size_t size) { +void ReContainer::addData(uint8_t* value, size_t size) { if(size <= 255) { addType(TAG_DATA255); m_data.append((char) size); @@ -180,7 +180,7 @@ void RplContainer::addData(uint8_t* value, size_t size) { * * @return the container as a byte array */ -const QByteArray& RplContainer::getData() { +const QByteArray& ReContainer::getData() { if(m_typeList.length() != 0) { char buffer[128]; // RPL&1 0a b5[2]cis: !12 @@ -199,7 +199,7 @@ const QByteArray& RplContainer::getData() { * * @param data the container as a byte array */ -void RplContainer::fill(const QByteArray& data) { +void ReContainer::fill(const QByteArray& data) { m_data = data; const char* ptr = m_data.data(); if(strncmp(ptr, MAGIC_1, strlen(MAGIC_1)) != 0) @@ -236,21 +236,21 @@ void RplContainer::fill(const QByteArray& data) { * * @return the number of bags */ -int RplContainer::getCountBags() const { +int ReContainer::getCountBags() const { return m_countBags; } /** * @brief Sets the begin of the new bag. */ -void RplContainer::nextBag() { +void ReContainer::nextBag() { if(m_ixItem < m_typeList.length() && m_ixItem != -1) - throw RplException(LOG_ERROR, LOC_NEXT_BAG_1, NULL, + throw ReException(LOG_ERROR, LOC_NEXT_BAG_1, NULL, "end of bag not reached: remaining items: %s", m_typeList.data() + m_ixItem); m_ixItem = 0; m_ixBag++; if(m_ixBag >= m_countBags) - throw RplException(LOG_ERROR, LOC_NEXT_BAG_2, NULL, + throw ReException(LOG_ERROR, LOC_NEXT_BAG_2, NULL, "no more bags: %d", m_ixBag); } /** @@ -258,24 +258,24 @@ void RplContainer::nextBag() { * * @param expected the expected data type */ -void RplContainer::nextItem(type_tag_t expected) { +void ReContainer::nextItem(type_tag_t expected) { if(m_ixBag < 0) { m_ixBag = 0; m_ixItem = 0; } if(m_ixItem >= m_typeList.length()) - throw RplException(LOG_ERROR, LOC_NEXT_ITEM_1, "no more items in the bag"); + throw ReException(LOG_ERROR, LOC_NEXT_ITEM_1, "no more items in the bag"); type_tag_t current = (type_tag_t) m_typeList.at(m_ixItem); // Unify all data types: if(current == TAG_DATA4G || current == TAG_DATA64K) current = TAG_DATA255; if(current != expected) - throw RplException(LOG_ERROR, LOC_NEXT_ITEM_2, NULL, + throw ReException(LOG_ERROR, LOC_NEXT_ITEM_2, NULL, "current item is a %c, not a %c", (char) m_typeList.at(m_ixItem), (char) expected); m_ixItem++; if(m_readPosition > (uint8_t*)(m_data.data() + m_data.length())) - throw RplException(LOG_ERROR, LOC_NEXT_ITEM_3, NULL, + throw ReException(LOG_ERROR, LOC_NEXT_ITEM_3, NULL, "container size too small. Bag: %d of %d Item: %d of %d", 1 + m_ixBag, m_countBags, 1 + m_ixItem, m_typeList.length()); } @@ -285,7 +285,7 @@ void RplContainer::nextItem(type_tag_t expected) { * * @return the next char from the container */ -char RplContainer::nextChar() { +char ReContainer::nextChar() { nextItem(TAG_CHAR); char rc = *m_readPosition++; return rc; @@ -296,7 +296,7 @@ char RplContainer::nextChar() { * * @return the next integer from the container */ -int RplContainer::nextInt() { +int ReContainer::nextInt() { nextItem(TAG_INT); bool isNegativ = *m_readPosition == '-'; if(isNegativ) @@ -315,19 +315,19 @@ int RplContainer::nextInt() { * * @return the next integer from the container */ -qint64 RplContainer::nextInt64() { +int64_t ReContainer::nextInt64() { nextItem(TAG_INT); bool isNegativ = *m_readPosition == '-'; if(isNegativ) m_readPosition++; - qint64 value = 0; + uint64_t value = 0; if(sscanf((const char*) m_readPosition, "%llx ", &value) != 1) throw RplInvalidDataException(LOG_ERROR, LOC_NEXT_INT_1, "not a hex_number", m_readPosition, 16); m_readPosition = (uint8_t*) strchr((const char*) m_readPosition, ' ') + 1; if(isNegativ) value = - value; - return value; + return (int64_t) value; } /** @@ -335,7 +335,7 @@ qint64 RplContainer::nextInt64() { * * @return the next '\0' delimited string from the container */ -const char* RplContainer::nextString() { +const char* ReContainer::nextString() { nextItem(TAG_STRING); const char* rc = (const char*) m_readPosition; m_readPosition += strlen(rc) + 1; @@ -350,7 +350,7 @@ const char* RplContainer::nextString() { * false: data contains the item data only * @return the size of the read data */ -size_t RplContainer::nextData(QByteArray& data, bool append) { +size_t ReContainer::nextData(QByteArray& data, bool append) { nextItem(TAG_DATA255); type_tag_t tag = (type_tag_t) m_typeList.at(m_ixItem - 1); size_t length = 0; @@ -390,13 +390,13 @@ size_t RplContainer::nextData(QByteArray& data, bool append) { * @param separatorItems separator between two items, e.g. '\\n' or '|' * @return a human readable string describing the container */ -QByteArray RplContainer::dump(const char* title, +QByteArray ReContainer::dump(const char* title, int maxBags, int maxStringLength, int maxBlobLength, char separatorItems) { QByteArray rc; rc.reserve(64000); rc.append("=== ").append(title).append('\n'); - rc.append("Bags: ").append(RplString::toNumber(m_countBags)); + rc.append("Bags: ").append(ReStringUtil::toNumber(m_countBags)); rc.append(" Types: ").append(m_typeList).append('\n'); // save the current state: int safeIxBag = m_ixBag; @@ -408,7 +408,7 @@ QByteArray RplContainer::dump(const char* title, if(maxBags > m_countBags) maxBags = m_countBags; for(int ixBag = 0; ixBag < maxBags; ixBag++) { - rc.append("--- bag ").append(RplString::toNumber(ixBag)).append(":\n"); + rc.append("--- bag ").append(ReStringUtil::toNumber(ixBag)).append(":\n"); nextBag(); QByteArray item; int maxLength; @@ -420,8 +420,8 @@ QByteArray RplContainer::dump(const char* title, break; case TAG_INT: iValue = nextInt(); - rc.append(" i: ").append(RplString::toNumber(iValue)).append(" / "); - rc.append(RplString::toNumber(iValue, "%x")).append(separatorItems); + rc.append(" i: ").append(ReStringUtil::toNumber(iValue)).append(" / "); + rc.append(ReStringUtil::toNumber(iValue, "%x")).append(separatorItems); break; case TAG_STRING: sValue = nextString(); @@ -434,9 +434,9 @@ QByteArray RplContainer::dump(const char* title, case TAG_DATA4G: nextData(item, false); rc.append(' ').append((char) currentType).append(": ["); - rc.append(RplString::toNumber(item.length())).append("] "); + rc.append(ReStringUtil::toNumber(item.length())).append("] "); maxLength = item.length() < maxBlobLength ? item.length() : maxBlobLength; - rc.append(RplString::hexDump(item.data(), maxLength, + rc.append(ReStringUtil::hexDump(item.data(), maxLength, 16)).append(separatorItems); break; default: @@ -451,57 +451,3 @@ QByteArray RplContainer::dump(const char* title, return rc; } -// ------------------ -#if ! defined RPL_TEST -#define RPL_TEST -#endif -#ifdef RPL_TEST -#include "rplcore/rpltest.hpp" -/** - * @brief Unit test for RplContainer - */ -class TestRplContainer : public RplTest { -public: - TestRplContainer() : RplTest("RplContainer") {} - -public: - void testBasic() { - RplContainer container(256); - // Rpl&1 09 36[2]cis:!7b Nirwana <0> Y -ab34 A long string with an trailing '0' <0>
- container.startBag(); - container.addChar('!'); - container.addInt(123); - container.addString("Nirwana"); - container.startBag(); - container.addChar('Y'); - container.addInt(-0xab34); - container.addString("A long string with an trailing '0'"); - - QByteArray data = container.getData(); - - RplContainer container2(256); - container2.fill(data); - checkE(2, container2.getCountBags()); - checkE('!', container2.nextChar()); - checkE(123, container2.nextInt()); - checkE("Nirwana", container2.nextString()); - container2.nextBag(); - checkE('Y', container2.nextChar()); - checkE(-0xab34, container2.nextInt()); - checkE("A long string with an trailing '0'", container2.nextString()); - - log(("Example: " + data).constData()); - } - - virtual void doIt() { - testBasic(); - } -}; - -#endif -void testRplContainer() { -#ifdef RPL_TEST - TestRplContainer test; - test.run(); -#endif -} diff --git a/rplcore/rplcontainer.hpp b/base/ReContainer.hpp similarity index 87% rename from rplcore/rplcontainer.hpp rename to base/ReContainer.hpp index 621a616..5a08aca 100644 --- a/rplcore/rplcontainer.hpp +++ b/base/ReContainer.hpp @@ -5,15 +5,15 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#ifndef RPLCONTAINER_HPP -#define RPLCONTAINER_HPP +#ifndef RECONTAINER_HPP +#define RECONTAINER_HPP // the sources generated from QT include this file directly: #ifndef RPLCORE_HPP #include #include #endif -class RplContainer { +class ReContainer { public: typedef enum { @@ -27,20 +27,20 @@ public: } type_tag_t; static const char* MAGIC_1; public: - RplContainer(size_t sizeHint); - virtual ~RplContainer(); + ReContainer(size_t sizeHint); + virtual ~ReContainer(); private: // No copy constructor: no implementation! - RplContainer(const RplContainer& source); + ReContainer(const ReContainer& source); // Prohibits assignment operator: no implementation! - RplContainer& operator =(const RplContainer& source); + ReContainer& operator =(const ReContainer& source); public: // Building the container: void addType(type_tag_t tag); void startBag(); void addChar(char cc); void addInt(int value); - void addInt(qint64 value); + void addInt(int64_t value); void addString(const char* value); void addData(uint8_t* value, size_t size); const QByteArray& getData(); @@ -52,7 +52,7 @@ public: void nextBag(); char nextChar(); int nextInt(); - qint64 nextInt64(); + int64_t nextInt64(); const char* nextString(); size_t nextData(QByteArray& data, bool append = false); @@ -79,4 +79,4 @@ private: const uint8_t* m_readPosition; }; -#endif // RPLCONTAINER_HPP +#endif // RECONTAINER_HPP diff --git a/rplcore/rplexception.cpp b/base/ReException.cpp similarity index 86% rename from rplcore/rplexception.cpp rename to base/ReException.cpp index fac935f..0af373d 100644 --- a/rplcore/rplexception.cpp +++ b/base/ReException.cpp @@ -22,8 +22,8 @@ * * Example: *

- * #include "rplcore/rplcore.hpp"
- * #include "rplexpr/rplexpr.hpp"
+ * #include "base/rebase.hpp"
+ * #include "expr/reexpr.hpp"
  * 
* In this case all definitions of rplcore and rplexpr are available. */ @@ -34,16 +34,16 @@ * * @brief Definitions for a generally usable exceptions. */ -#include "rplcore/rplcore.hpp" +#include "base/rebase.hpp" -/** @class RplException rplexception.hpp "rplcore/rplexception.hpp" +/** @class ReException ReException.hpp "base/ReException.hpp" * * @brief A generally usable exception with or without logging. * * Note: If the logger is not given by parameter * the usage of the global logger is not threadsafe. */ -class RplException; +class ReException; /** @@ -51,7 +51,7 @@ class RplException; * * For derived classes only! */ -RplException::RplException() : +ReException::ReException() : m_message("") { } @@ -62,7 +62,7 @@ RplException::RplException() : * @param format the reason of the exception * @param ... the values for the placeholders in the format. */ -RplException::RplException(const char* format, ...) : +ReException::ReException(const char* format, ...) : m_message("") { char buffer[64000]; va_list ap; @@ -87,8 +87,8 @@ RplException::RplException(const char* format, ...) : * in format * @param logger if NULL the global logger will be used */ -RplException::RplException(RplLoggerLevel level, int location, - RplLogger* logger, const char* format, ...) : +ReException::ReException(ReLoggerLevel level, int location, + ReLogger* logger, const char* format, ...) : m_message("") { char buffer[64000]; va_list ap; @@ -97,7 +97,7 @@ RplException::RplException(RplLoggerLevel level, int location, va_end(ap); m_message = buffer; if(logger == NULL) - logger = RplLogger::globalLogger(); + logger = ReLogger::globalLogger(); logger->log(level, location, buffer); } @@ -131,10 +131,10 @@ RplException::RplException(RplLoggerLevel level, int location, * @param logger if NULL the global logger will be used */ -RplRangeException::RplRangeException(RplLoggerLevel level, int location, +ReRangeException::ReRangeException(ReLoggerLevel level, int location, size_t current, - size_t lbound, size_t ubound, const char* message, RplLogger* logger) : - RplException("") { + size_t lbound, size_t ubound, const char* message, ReLogger* logger) : + ReException("") { char buffer[64000]; if(message == NULL) message = "value outside limits"; @@ -142,7 +142,7 @@ RplRangeException::RplRangeException(RplLoggerLevel level, int location, message == NULL ? "" : message, current, lbound, ubound); if(logger == NULL) - logger = RplLogger::globalLogger(); + logger = ReLogger::globalLogger(); logger->log(level, location, buffer); } @@ -172,11 +172,11 @@ RplRangeException::RplRangeException(RplLoggerLevel level, int location, * @param dataSize the size of the data which should be dumped * @param logger if NULL the global logger will be used */ -RplInvalidDataException::RplInvalidDataException(RplLoggerLevel level, +RplInvalidDataException::RplInvalidDataException(ReLoggerLevel level, int location, const char* message, const void* data, - size_t dataSize, RplLogger* logger) : - RplException("") { + size_t dataSize, ReLogger* logger) : + ReException("") { char buffer[64000]; if(message == NULL) message = "invalid data: "; @@ -199,6 +199,6 @@ RplInvalidDataException::RplInvalidDataException(RplLoggerLevel level, *ptr++ = '.'; } if(logger == NULL) - logger = RplLogger::globalLogger(); + logger = ReLogger::globalLogger(); logger->log(level, location, buffer); } diff --git a/base/ReException.hpp b/base/ReException.hpp new file mode 100644 index 0000000..8fb8113 --- /dev/null +++ b/base/ReException.hpp @@ -0,0 +1,45 @@ +/* + * 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 REEXCEPTION_HPP +#define REEXCEPTION_HPP + +// the sources generated from QT include this file directly: +#ifndef RPLCORE_HPP +#include +#endif + +class ReException { +protected: + ReException(); +public: + ReException(const char* message, ...); + ReException(ReLoggerLevel level, int location, const char* message, + ReLogger* logger = NULL); + ReException(ReLoggerLevel level, int location, ReLogger* logger, + const char* message, ...); + const QByteArray& getMessage() const { + return m_message; + } +protected: + QByteArray m_message; +}; + +class ReRangeException : public ReException { +public: + ReRangeException(ReLoggerLevel level, int location, size_t current, + size_t lbound, size_t ubound, + const char* message = NULL, ReLogger* logger = NULL); +}; + +class RplInvalidDataException : public ReException { +public: + RplInvalidDataException(ReLoggerLevel level, int location, const char* message, + const void* data = NULL, size_t dataSize = 0, ReLogger* logger = NULL); +}; + +#endif // REEXCEPTION_HPP diff --git a/rplcore/rpllogger.cpp b/base/ReLogger.cpp similarity index 78% rename from rplcore/rpllogger.cpp rename to base/ReLogger.cpp index 84f20f7..0e913f7 100644 --- a/rplcore/rpllogger.cpp +++ b/base/ReLogger.cpp @@ -13,15 +13,15 @@ * * Definitions for a configurable logger for different output media. */ -#include "rplcore/rplcore.hpp" +#include "base/rebase.hpp" #include #include enum { - LOC_ADD_APPENDER_1 = RPL_FIRST_OF(RPLMODULE_LOGGER), // 10101 + LOC_ADD_APPENDER_1 = LOC_FIRST_OF(LOC_LOGGER), // 10101 }; -RplLogger* RplLogger::m_globalLogger = NULL; +ReLogger* ReLogger::m_globalLogger = NULL; /** * @brief Returns the global logger. @@ -30,9 +30,9 @@ RplLogger* RplLogger::m_globalLogger = NULL; * * @return the global logger */ -RplLogger* RplLogger::globalLogger() { +ReLogger* ReLogger::globalLogger() { if(m_globalLogger == NULL) { - m_globalLogger = new RplLogger(); + m_globalLogger = new ReLogger(); m_globalLogger->buildStandardAppender("globallogger"); } return m_globalLogger; @@ -40,12 +40,12 @@ RplLogger* RplLogger::globalLogger() { /** * @brief Frees the resources of the global logger. */ -void RplLogger::destroyGlobalLogger() { +void ReLogger::destroyGlobalLogger() { delete m_globalLogger; m_globalLogger = NULL; } -/** @class RplAppender rpllogger.hpp "rplcore/rpllogger.hpp" +/** @class ReAppender rpllogger.hpp "rplcore/rpllogger.hpp" * * @brief Puts the logging info to a medium (e.g. a file). * @@ -55,9 +55,9 @@ void RplLogger::destroyGlobalLogger() { /** * @brief Constructor. * - * @param name identifies the logger. Useful for RplLogger::findLogger() + * @param name identifies the logger. Useful for ReLogger::findLogger() */ -RplAppender::RplAppender(const QByteArray& name) : +ReAppender::ReAppender(const QByteArray& name) : m_name(name), m_level(LOG_INFO) { @@ -65,7 +65,7 @@ RplAppender::RplAppender(const QByteArray& name) : /** * @brief Destructor. */ -RplAppender::~RplAppender() { +ReAppender::~ReAppender() { } /** @@ -73,7 +73,7 @@ RplAppender::~RplAppender() { * * @return the name of the instance */ -const char* RplAppender::getName() const { +const char* ReAppender::getName() const { return m_name.data(); } @@ -82,7 +82,7 @@ const char* RplAppender::getName() const { * * @param level */ -void RplAppender::setLevel(RplLoggerLevel level) { +void ReAppender::setLevel(ReLoggerLevel level) { m_level = level; } /** @@ -90,7 +90,7 @@ void RplAppender::setLevel(RplLoggerLevel level) { * * @return the level */ -RplLoggerLevel RplAppender::getLevel() const { +ReLoggerLevel ReAppender::getLevel() const { return m_level; } /** @@ -99,7 +99,7 @@ RplLoggerLevel RplAppender::getLevel() const { * @param level the level of the location. * @return true: the location level is greater or equals to the appender's level */ -bool RplAppender::isActive(RplLoggerLevel level) { +bool ReAppender::isActive(ReLoggerLevel level) { return level <= m_level; } @@ -108,7 +108,7 @@ bool RplAppender::isActive(RplLoggerLevel level) { * * @param onNotOff the state of the auto deletion */ -void RplAppender::setAutoDelete(bool onNotOff) { +void ReAppender::setAutoDelete(bool onNotOff) { m_autoDelete = onNotOff; } @@ -117,22 +117,22 @@ void RplAppender::setAutoDelete(bool onNotOff) { * * @return true: the logger destroys the instance */ -bool RplAppender::isAutoDelete() const { +bool ReAppender::isAutoDelete() const { return m_autoDelete; } -/** @class RplLogger rpllogger.hpp "rplcore/rpllogger.hpp" +/** @class ReLogger rpllogger.hpp "rplcore/rpllogger.hpp" * * @brief Implements a logger. * * The logger takes the call from the calling location. - * But the output assumes the class RplAppender, + * But the output assumes the class ReAppender, * more exactly: a subclass from the abstract class - * RplAppender, + * ReAppender, * * For single threaded applications there is a possability of * a global logger. In this case the logger can be got with the static - * method RplLogger::globalLogger(). + * method ReLogger::globalLogger(). * * Note: using the global logger is not threadsafe! * @@ -143,7 +143,7 @@ bool RplAppender::isAutoDelete() const { /** * @brief Constructor. */ -RplLogger::RplLogger() : +ReLogger::ReLogger() : // m_appenders(), m_countAppenders(0), m_stdPrefix(), @@ -155,9 +155,9 @@ RplLogger::RplLogger() : /** * @brief Destructor. */ -RplLogger::~RplLogger() { +ReLogger::~ReLogger() { for(size_t ix = 0; ix < m_countAppenders; ix++) { - RplAppender* appender = m_appenders[ix]; + ReAppender* appender = m_appenders[ix]; if(appender->isAutoDelete()) { delete appender; } @@ -170,7 +170,7 @@ RplLogger::~RplLogger() { * @param level the level to "convert" * @return the assigned prefix char */ -char RplLogger::getPrefixOfLevel(RplLoggerLevel level) const { +char ReLogger::getPrefixOfLevel(ReLoggerLevel level) const { char rc = ' '; switch(level) { case LOG_ERROR: @@ -199,10 +199,10 @@ char RplLogger::getPrefixOfLevel(RplLoggerLevel level) const { * @return false: all appenders are not activated by this level
* true: otherwise */ -bool RplLogger::isActive(RplLoggerLevel level) const { +bool ReLogger::isActive(ReLoggerLevel level) const { bool rc = false; for(size_t ix = 0; ix < m_countAppenders; ix++) { - RplAppender* appender = m_appenders[ix]; + ReAppender* appender = m_appenders[ix]; if(appender->isActive(level)) { rc = true; break; @@ -216,9 +216,9 @@ bool RplLogger::isActive(RplLoggerLevel level) const { * * @param level level to set */ -void RplLogger::setLevel(RplLoggerLevel level) { +void ReLogger::setLevel(ReLoggerLevel level) { for(size_t ix = 0; ix < m_countAppenders; ix++) { - RplAppender* appender = m_appenders[ix]; + ReAppender* appender = m_appenders[ix]; appender->setLevel(level); } } @@ -229,7 +229,7 @@ void RplLogger::setLevel(RplLoggerLevel level) { * @param onNotOff true: the logger is thread save.
* false: not thread save */ -void RplLogger::setWithLocking(bool onNotOff) { +void ReLogger::setWithLocking(bool onNotOff) { m_withLocking = onNotOff; } @@ -242,7 +242,7 @@ void RplLogger::setWithLocking(bool onNotOff) { * @param location an unique identifier of the location * @return the standard logging line prefix */ -const QByteArray& RplLogger::getStdPrefix(RplLoggerLevel level, int location) { +const QByteArray& ReLogger::getStdPrefix(ReLoggerLevel level, int location) { if(m_stdPrefix.isEmpty()) m_stdPrefix = buildStdPrefix(level, location); return m_stdPrefix; @@ -256,11 +256,11 @@ const QByteArray& RplLogger::getStdPrefix(RplLoggerLevel level, int location) { * @param message the logging message * @return true: for chaining */ -bool RplLogger::log(RplLoggerLevel level, int location, const char* message) { +bool ReLogger::log(ReLoggerLevel level, int location, const char* message) { m_stdPrefix = ""; bool first = true; for(size_t ix = 0; ix < m_countAppenders; ix++) { - RplAppender* appender = m_appenders[ix]; + ReAppender* appender = m_appenders[ix]; if(appender->isActive(level)) { if(first && m_withLocking) m_mutex.lock(); @@ -279,7 +279,7 @@ bool RplLogger::log(RplLoggerLevel level, int location, const char* message) { * @param message the logging message * @return true: for chaining */ -bool RplLogger::log(RplLoggerLevel level, int location, +bool ReLogger::log(ReLoggerLevel level, int location, const QByteArray& message) { return log(level, location, message.data()); } @@ -292,8 +292,8 @@ bool RplLogger::log(RplLoggerLevel level, int location, * @param message the logging message * @return true: for chaining */ -bool RplLogger::log(RplLoggerLevel level, int location, - const QString& message) { +bool ReLogger::log(ReLoggerLevel level, int location, + const ReString& message) { return log(level, location, message.toUtf8().data()); } @@ -306,7 +306,7 @@ bool RplLogger::log(RplLoggerLevel level, int location, * @param ... the values of the placeholders (varargs) * @return true: for chaining */ -bool RplLogger::logv(RplLoggerLevel level, int location, const char* format, +bool ReLogger::logv(ReLoggerLevel level, int location, const char* format, ...) { char buffer[64000]; va_list ap; @@ -325,7 +325,7 @@ bool RplLogger::logv(RplLoggerLevel level, int location, const char* format, * @param ... the values of the placeholders (varargs) * @return true: for chaining */ -bool RplLogger::logv(RplLoggerLevel level, int location, +bool ReLogger::logv(ReLoggerLevel level, int location, const QByteArray& format, ...) { char buffer[64000]; va_list ap; @@ -344,7 +344,7 @@ bool RplLogger::logv(RplLoggerLevel level, int location, * @param varlist variable arguments * @return true: for chaining */ -bool RplLogger::log(RplLoggerLevel level, int location, const char* format, +bool ReLogger::log(ReLoggerLevel level, int location, const char* format, va_list& varlist) { char buffer[64000]; qvsnprintf(buffer, sizeof buffer, format, varlist); @@ -357,7 +357,7 @@ bool RplLogger::log(RplLoggerLevel level, int location, const char* format, * @param level the level of the location * @param location an unique identifier of the location */ -QByteArray RplLogger::buildStdPrefix(RplLoggerLevel level, int location) { +QByteArray ReLogger::buildStdPrefix(ReLoggerLevel level, int location) { time_t now = time(NULL); struct tm* now2 = localtime(&now); char buffer[64]; @@ -378,7 +378,7 @@ QByteArray RplLogger::buildStdPrefix(RplLoggerLevel level, int location) { * * @param appender appender to add */ -void RplLogger::addAppender(RplAppender* appender) { +void ReLogger::addAppender(ReAppender* appender) { if(m_countAppenders < sizeof m_appenders / sizeof m_appenders[0]) { m_appenders[m_countAppenders++] = appender; } else { @@ -394,10 +394,10 @@ void RplLogger::addAppender(RplAppender* appender) { * @return NULL: no appender with this name is registered
* otherwise: the wanted appender */ -RplAppender* RplLogger::findAppender(const char* name) const { - RplAppender* rc = NULL; +ReAppender* ReLogger::findAppender(const char* name) const { + ReAppender* rc = NULL; for(size_t ix = 0; ix < m_countAppenders; ix++) { - RplAppender* current = m_appenders[ix]; + ReAppender* current = m_appenders[ix]; if(strcmp(name, current->getName()) == 0) { rc = current; break; @@ -416,7 +416,7 @@ RplAppender* RplLogger::findAppender(const char* name) const { * the prefix of the log file if no entry in the * configuration file */ -void RplLogger::buildStandardAppender(RplConfig* config, +void ReLogger::buildStandardAppender(ReConfig* config, const char* prefix, const char* defaultLogfilePrefix) { QByteArray sPrefix(prefix); @@ -427,7 +427,7 @@ void RplLogger::buildStandardAppender(RplConfig* config, int maxCount = config->asInt(sPrefix + "maxfiles", 5); buildStandardAppender(logFilePrefix, maxSize, maxCount); QByteArray sLevel = config->asString(sPrefix + "level", "info"); - RplLoggerLevel level = LOG_INFO; + ReLoggerLevel level = LOG_INFO; if (strcasecmp(sLevel.constData(), "error") == 0) level = LOG_ERROR; else if (strcasecmp(sLevel, "warning") == 0) @@ -444,17 +444,17 @@ void RplLogger::buildStandardAppender(RplConfig* config, * @param maxSize the maximum of the file size * @param maxCount the maximal count of files. If neccessary the oldest file will be deleted */ -void RplLogger::buildStandardAppender(const QByteArray& prefix, int maxSize, +void ReLogger::buildStandardAppender(const QByteArray& prefix, int maxSize, int maxCount) { - RplStreamAppender* streamAppender = new RplStreamAppender(stderr); + ReStreamAppender* streamAppender = new ReStreamAppender(stderr); streamAppender->setAutoDelete(true); - addAppender((RplAppender*) streamAppender); - RplFileAppender* fileAppender = new RplFileAppender(prefix, maxSize, maxCount); + addAppender((ReAppender*) streamAppender); + ReFileAppender* fileAppender = new ReFileAppender(prefix, maxSize, maxCount); fileAppender->setAutoDelete(true); - addAppender((RplAppender*) fileAppender); + addAppender((ReAppender*) fileAppender); } -/** @class RplStreamAppender rpllogger.hpp "rplcore/rpllogger.hpp" +/** @class ReStreamAppender rpllogger.hpp "rplcore/rpllogger.hpp" * * @brief Puts the logging info to a standard output stream. * @@ -465,15 +465,15 @@ void RplLogger::buildStandardAppender(const QByteArray& prefix, int maxSize, /** * @brief Constructor. */ -RplStreamAppender::RplStreamAppender(FILE* file, const char* appenderName) : - RplAppender(QByteArray(appenderName)), +ReStreamAppender::ReStreamAppender(FILE* file, const char* appenderName) : + ReAppender(QByteArray(appenderName)), m_fp(file) { } /** * @brief Destructor. */ -RplStreamAppender::~RplStreamAppender() { +ReStreamAppender::~ReStreamAppender() { fflush(m_fp); } @@ -486,8 +486,8 @@ RplStreamAppender::~RplStreamAppender() { * @param message the logging message * @param logger the calling logger */ -void RplStreamAppender::log(RplLoggerLevel level, int location, - const char* message, RplLogger* logger) { +void ReStreamAppender::log(ReLoggerLevel level, int location, + const char* message, ReLogger* logger) { const QByteArray& prefix = logger->getStdPrefix(level, location); fputs(prefix, m_fp); fputs(message, m_fp); @@ -497,7 +497,7 @@ void RplStreamAppender::log(RplLoggerLevel level, int location, #pragma GCC diagnostic warning "-Wunused-parameter" -/** @class RplFileAppender rpllogger.hpp "rplcore/rpllogger.hpp" +/** @class ReFileAppender rpllogger.hpp "rplcore/rpllogger.hpp" * * @brief Puts the logging info to a file. * @@ -515,11 +515,11 @@ void RplStreamAppender::log(RplLoggerLevel level, int location, * @param prefix the prefix of the log file name, e.g. /var/log/server * @param maxSize the maximum of the file size * @param maxCount the maximal count of files. If neccessary the oldest file will be deleted - * @param appenderName the name of the appender. @see RplLogger::findAppender() + * @param appenderName the name of the appender. @see ReLogger::findAppender() */ -RplFileAppender::RplFileAppender(const QByteArray& prefix, int maxSize, +ReFileAppender::ReFileAppender(const QByteArray& prefix, int maxSize, int maxCount, const char* appenderName) : - RplAppender(QByteArray(appenderName)), + ReAppender(QByteArray(appenderName)), m_prefix(prefix), m_maxSize(maxSize), m_maxCount(maxCount), @@ -532,7 +532,7 @@ RplFileAppender::RplFileAppender(const QByteArray& prefix, int maxSize, /** * @brief Destructor. */ -RplFileAppender::~RplFileAppender() { +ReFileAppender::~ReFileAppender() { if(m_fp != NULL) { fclose(m_fp); m_fp = NULL; @@ -542,7 +542,7 @@ RplFileAppender::~RplFileAppender() { /** * @brief Opens the next log file. */ -void RplFileAppender::open() { +void ReFileAppender::open() { if(m_fp != NULL) fclose(m_fp); char fullName[512]; @@ -566,9 +566,9 @@ void RplFileAppender::open() { * @param logger the calling logger */ #pragma GCC diagnostic ignored "-Wunused-parameter" -void RplFileAppender::log(RplLoggerLevel level, int location, +void ReFileAppender::log(ReLoggerLevel level, int location, const char* message, - RplLogger* logger) { + ReLogger* logger) { if(m_fp != NULL) { const QByteArray& prefix = logger->getStdPrefix(level, location); fputs(prefix, m_fp); @@ -579,7 +579,7 @@ void RplFileAppender::log(RplLoggerLevel level, int location, } #pragma GCC diagnostic warning "-Wunused-parameter" -/** @class RplMemoryAppender rpllogger.hpp "rplcore/rpllogger.hpp" +/** @class ReMemoryAppender rpllogger.hpp "rplcore/rpllogger.hpp" * * @brief Puts the logging info to an internal buffer. * @@ -593,8 +593,8 @@ void RplFileAppender::log(RplLoggerLevel level, int location, * If the buffer is full the oldest lines will be deleted * @param appenderName NULL or the name of the appender */ -RplMemoryAppender::RplMemoryAppender(int maxLines, const char* appenderName) : - RplAppender(appenderName), +ReMemoryAppender::ReMemoryAppender(int maxLines, const char* appenderName) : + ReAppender(appenderName), m_lines(), m_maxLines(maxLines), m_addPrefix(true) @@ -605,7 +605,7 @@ RplMemoryAppender::RplMemoryAppender(int maxLines, const char* appenderName) : /** * @brief Destructor. */ -RplMemoryAppender::~RplMemoryAppender() { +ReMemoryAppender::~ReMemoryAppender() { } /** @@ -617,9 +617,9 @@ RplMemoryAppender::~RplMemoryAppender() { * @param logger the calling logger */ #pragma GCC diagnostic ignored "-Wunused-parameter" -void RplMemoryAppender::log(RplLoggerLevel level, int location, +void ReMemoryAppender::log(ReLoggerLevel level, int location, const char* message, - RplLogger* logger) { + ReLogger* logger) { if(m_lines.size() >= m_maxLines) m_lines.removeFirst(); if (! m_addPrefix) @@ -637,13 +637,13 @@ void RplMemoryAppender::log(RplLoggerLevel level, int location, * * @return the line list */ -const QList& RplMemoryAppender::getLines() const { +const QList& ReMemoryAppender::getLines() const { return m_lines; } /** * @brief Deletes all log lines. */ -void RplMemoryAppender::clear() { +void ReMemoryAppender::clear() { m_lines.clear(); } diff --git a/rplcore/rpllogger.hpp b/base/ReLogger.hpp similarity index 56% rename from rplcore/rpllogger.hpp rename to base/ReLogger.hpp index 791d14c..125a6f6 100644 --- a/rplcore/rpllogger.hpp +++ b/base/ReLogger.hpp @@ -5,14 +5,14 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#ifndef RPLLOGGER_HPP -#define RPLLOGGER_HPP +#ifndef RELOGGER_HPP +#define RELOGGER_HPP /** * */ -class RplLogger; -class RplConfig; +class ReLogger; +class ReConfig; /** * @brief Logging level: for controlling of the logging. * @@ -20,79 +20,79 @@ class RplConfig; * If the level of an appender is lower or equals to this level * the logging is done. */ -enum RplLoggerLevel { +enum ReLoggerLevel { LOG_ERROR = 10, ///< marks an error. LOG_WARNING = 15, ///< marks a warning LOG_INFO = 20, ///< marks an information LOG_DEBUG = 25 ///< for debug purpose only }; -class RplAppender { +class ReAppender { public: - RplAppender(const QByteArray& name); - virtual ~RplAppender(); + ReAppender(const QByteArray& name); + virtual ~ReAppender(); private: // No copy constructor: no implementation! - RplAppender(const RplAppender& source); + ReAppender(const ReAppender& source); // Prohibits assignment operator: no implementation! - RplAppender& operator =(const RplAppender& source); + ReAppender& operator =(const ReAppender& source); public: - virtual void log(RplLoggerLevel level, int location, const char* message, - RplLogger* logger) = 0; - bool isActive(RplLoggerLevel level); - void setLevel(RplLoggerLevel level); + virtual void log(ReLoggerLevel level, int location, const char* message, + ReLogger* logger) = 0; + bool isActive(ReLoggerLevel level); + void setLevel(ReLoggerLevel level); void setAutoDelete(bool onNotOff); bool isAutoDelete() const; - RplLoggerLevel getLevel() const; + ReLoggerLevel getLevel() const; const char* getName() const; private: // Name of the appender. Used to find the appender in a list of appenders QByteArray m_name; // only locations with a lower or equal level will be logged - RplLoggerLevel m_level; + ReLoggerLevel m_level; // true: the logger destroys the instance. false: the deletion must be done outside of the logger bool m_autoDelete; }; -class RplLogger { +class ReLogger { public: - static RplLogger* globalLogger(); + static ReLogger* globalLogger(); static void destroyGlobalLogger(); private: // the standard logger, can be called (with globalLogger()) from each location - static RplLogger* m_globalLogger; + static ReLogger* m_globalLogger; public: - RplLogger(); - virtual ~RplLogger(); + ReLogger(); + virtual ~ReLogger(); private: // No copy constructor: no implementation! - RplLogger(const RplLogger& source); + ReLogger(const ReLogger& source); // Prohibits assignment operator: no implementation! - RplLogger& operator =(const RplLogger& source); + ReLogger& operator =(const ReLogger& source); public: - bool log(RplLoggerLevel level, int location, const char* message); - bool log(RplLoggerLevel level, int location, const QByteArray& message); - bool log(RplLoggerLevel level, int location, const QString& message); - bool logv(RplLoggerLevel level, int location, const char* format, ...); - bool logv(RplLoggerLevel level, int location, const QByteArray& format, ...); - bool log(RplLoggerLevel level, int location, const char* format, + bool log(ReLoggerLevel level, int location, const char* message); + bool log(ReLoggerLevel level, int location, const QByteArray& message); + bool log(ReLoggerLevel level, int location, const ReString& message); + bool logv(ReLoggerLevel level, int location, const char* format, ...); + bool logv(ReLoggerLevel level, int location, const QByteArray& format, ...); + bool log(ReLoggerLevel level, int location, const char* format, va_list& varlist); - void addAppender(RplAppender* appender); - RplAppender* findAppender(const char* name) const; - void buildStandardAppender(RplConfig* config, const char* prefix = "logfile.", + void addAppender(ReAppender* appender); + ReAppender* findAppender(const char* name) const; + void buildStandardAppender(ReConfig* config, const char* prefix = "logfile.", const char* defaultLoggerName = "logger"); void buildStandardAppender(const QByteArray& prefix, int maxSize = 10*1024*1024, int maxCount = 5); - QByteArray buildStdPrefix(RplLoggerLevel level, int location); - const QByteArray& getStdPrefix(RplLoggerLevel level, int location); - char getPrefixOfLevel(RplLoggerLevel level) const; - bool isActive(RplLoggerLevel level) const; - void setLevel(RplLoggerLevel level); + QByteArray buildStdPrefix(ReLoggerLevel level, int location); + const QByteArray& getStdPrefix(ReLoggerLevel level, int location); + char getPrefixOfLevel(ReLoggerLevel level) const; + bool isActive(ReLoggerLevel level) const; + void setLevel(ReLoggerLevel level); void setWithLocking(bool onNotOff); private: // the assigned appenders: - RplAppender* m_appenders[16]; + ReAppender* m_appenders[16]; // the number of appenders in m_appenders: size_t m_countAppenders; // "" or the cache of the prefix of the current logging line: This can be reused by any appender. @@ -104,13 +104,13 @@ private: /** * Implements an appender which puts the messages to a standard stream: stdout or stderr */ -class RplStreamAppender : public RplAppender { +class ReStreamAppender : public ReAppender { public: - RplStreamAppender(FILE* stream, const char* appenderName = "FileAppender"); - virtual ~RplStreamAppender(); + ReStreamAppender(FILE* stream, const char* appenderName = "FileAppender"); + virtual ~ReStreamAppender(); public: - virtual void log(RplLoggerLevel level, int location, const char* message, - RplLogger* logger); + virtual void log(ReLoggerLevel level, int location, const char* message, + ReLogger* logger); private: // stdout or stderr: FILE* m_fp; @@ -119,15 +119,15 @@ private: /** * Implements an appender which puts the messages to a file */ -class RplFileAppender : public RplAppender { +class ReFileAppender : public ReAppender { public: - RplFileAppender(const QByteArray& name, int maxSize, int maxCount, + ReFileAppender(const QByteArray& name, int maxSize, int maxCount, const char* appenderName = "FileAppender"); - virtual ~RplFileAppender(); + virtual ~ReFileAppender(); public: void open(); - virtual void log(RplLoggerLevel level, int location, const char* message, - RplLogger* logger); + virtual void log(ReLoggerLevel level, int location, const char* message, + ReLogger* logger); private: // prefix of the log file name. Will be appended by "..log" @@ -147,14 +147,14 @@ private: /** * Stores the log messages in a list. */ -class RplMemoryAppender : public RplAppender { +class ReMemoryAppender : public ReAppender { public: - RplMemoryAppender(int maxLines = 1024, + ReMemoryAppender(int maxLines = 1024, const char* appenderName = "MemoryAppender"); - ~RplMemoryAppender(); + ~ReMemoryAppender(); public: - virtual void log(RplLoggerLevel level, int location, const char* message, - RplLogger* logger); + virtual void log(ReLoggerLevel level, int location, const char* message, + ReLogger* logger); const QList& getLines() const; void clear(); private: @@ -165,4 +165,4 @@ private: bool m_addPrefix; }; -#endif // RPLLOGGER_HPP +#endif // RELOGGER_HPP diff --git a/rplcore/rplqstring.cpp b/base/ReQString.cpp similarity index 90% rename from rplcore/rplqstring.cpp rename to base/ReQString.cpp index 2cd8995..171401b 100644 --- a/rplcore/rplqstring.cpp +++ b/base/ReQString.cpp @@ -7,13 +7,13 @@ */ /** @file - * @brief Missed operation for QStrings. + * @brief Missed operation for ReStrings. */ /** @file rplcore/rplqstring.hpp * - * @brief Definitions for missed operation for QStrings. + * @brief Definitions for missed operation for ReStrings. */ -#include "rplcore/rplcore.hpp" +#include "base/rebase.hpp" /** @@ -27,11 +27,11 @@ * @return <=0: no integer found * otherwise: the length of the integer */ -int RplQString::lengthOfUInt64(const QString& text, int start, +int ReQString::lengthOfUInt64(const ReString& text, int start, int radix, quint64* pValue) { int inputLength = text.size(); - qint64 value = 0; + int64_t value = 0; int ix = start; int cc; if (radix == 10){ @@ -63,7 +63,7 @@ int RplQString::lengthOfUInt64(const QString& text, int start, ix++; } } else { - throw RplException("RplQString::lengthOfInt(): wrong radix: %d", radix); + throw ReException("ReQString::lengthOfInt(): wrong radix: %d", radix); } if (pValue != NULL) *pValue = value; @@ -80,7 +80,7 @@ int RplQString::lengthOfUInt64(const QString& text, int start, * @return 0: no integer found * otherwise: the length of the integer */ -int RplQString::lengthOfUInt(const QString& text, int start, +int ReQString::lengthOfUInt(const ReString& text, int start, int radix, uint* pValue) { quint64 value; @@ -100,7 +100,7 @@ int RplQString::lengthOfUInt(const QString& text, int start, * @return <=0: no real number found * otherwise: the length of the floating point number */ -int RplQString::lengthOfReal(const QString& text, int start, qreal* pValue) +int ReQString::lengthOfReal(const ReString& text, int start, qreal* pValue) { int inputLength = text.size(); qreal value = 0.0; @@ -161,7 +161,7 @@ int RplQString::lengthOfReal(const QString& text, int start, qreal* pValue) } /** - * @brief Converts a QString into an utf-8 string + * @brief Converts a ReString into an utf-8 string * * The expression qstring.toUtf8().constData() is not allowed * in a variable argument list like sprintf. This is a thread save workaround. @@ -171,7 +171,7 @@ int RplQString::lengthOfReal(const QString& text, int start, qreal* pValue) * @param bufferSize size of the target buffer * @return buffer */ -char*RplQString::utf8(const QString& source, char buffer[], size_t bufferSize) +char*ReQString::utf8(const ReString& source, char buffer[], size_t bufferSize) { QByteArray val = source.toUtf8(); if (val.length() < (int) bufferSize) diff --git a/rplcore/rplqstring.hpp b/base/ReQtring.hpp similarity index 75% rename from rplcore/rplqstring.hpp rename to base/ReQtring.hpp index 780ef24..3a3bcf5 100644 --- a/rplcore/rplqstring.hpp +++ b/base/ReQtring.hpp @@ -10,14 +10,14 @@ #ifndef RPLQSTRING_HPP #define RPLQSTRING_HPP -class RplQString +class ReQString { public: - static int lengthOfUInt64(const QString& text, int start = 0, + static int lengthOfUInt64(const ReString& text, int start = 0, int radix = 10, quint64* value = NULL); - static int lengthOfUInt(const QString& text, int start, int radix, + static int lengthOfUInt(const ReString& text, int start, int radix, uint* pValue); - static int lengthOfReal(const QString& text, int start = 0, + static int lengthOfReal(const ReString& text, int start = 0, qreal* value = NULL); /** * @brief Returns the value of a hexadecimal digit. @@ -31,7 +31,7 @@ public: : digit >= 'A' && digit <= 'F' ? digit - 'A' + 10 : digit >= 'a' && digit <= 'f' ? digit - 'a' + 10 : -1; } - static char* utf8(const QString& source, char buffer[], size_t bufferSize); + static char* utf8(const ReString& source, char buffer[], size_t bufferSize); }; #endif // RPLQSTRING_HPP diff --git a/rplcore/rplstring.cpp b/base/ReStringUtil.cpp similarity index 90% rename from rplcore/rplstring.cpp rename to base/ReStringUtil.cpp index a8bd039..0afebec 100644 --- a/rplcore/rplstring.cpp +++ b/base/ReStringUtil.cpp @@ -8,13 +8,13 @@ /** @file * @brief Missed operations for QByteArrays. */ -/** @file rplcore/rplstring.cpp +/** @file base/ReStringUtil.cpp * * @brief Definitions for missed operations for QByteArrays. */ -#include "rplcore.hpp" +#include "base/rebase.hpp" -/** @class RplString rplstring.hpp "rplcore/rplstring.hpp" +/** @class ReStringUtil ReStringUtil.hpp "base/ReStringUtil.hpp" * * @brief Implements some services around strings. * @@ -28,7 +28,7 @@ * @param cc the char to count * @return the number of cc in the text */ -int RplString::countChar(const char* line, char cc) +int ReStringUtil::countChar(const char* line, char cc) { const char* ptr = line; int rc = 0; @@ -45,7 +45,7 @@ int RplString::countChar(const char* line, char cc) * @param item this item will be searched * @return the count of occurrences */ -int RplString::count(const char* source, const char* item) { +int ReStringUtil::count(const char* source, const char* item) { const char* end = source; int rc = 0; int lengthItem = strlen(item); @@ -73,7 +73,7 @@ int RplString::count(const char* source, const char* item) { * @return source: the source is enough short
* the prefix of source with the given length */ -const QByteArray& RplString::cutString(const QByteArray& source, int maxLength, +const QByteArray& ReStringUtil::cutString(const QByteArray& source, int maxLength, QByteArray& buffer, const char* appendix) { QByteArray& rc = source.length() <= maxLength ? (QByteArray&) source : buffer; if(source.length() > maxLength) { @@ -89,7 +89,7 @@ static char s_fileSeparator = 0; * @brief Returns the os specific file path separator. * @return the file path separator, e.g. "/" for linux */ -const char* RplString::fileSeparator(){ +const char* ReStringUtil::fileSeparator(){ return fileSeparatorChar() == '/' ? "/" : "\\"; } @@ -97,7 +97,7 @@ const char* RplString::fileSeparator(){ * @brief Returns the os specific file path separator. * @return the file path separator, e.g. '/' for linux */ -char RplString::fileSeparatorChar(){ +char ReStringUtil::fileSeparatorChar(){ if (s_fileSeparator == 0){ const char* path = getenv("PATH"); if (path != NULL){ @@ -125,7 +125,7 @@ char RplString::fileSeparatorChar(){ * @param bytesPerLine one line containes so many bytes of data * @return the hex dump */ -QByteArray RplString::hexDump(uint8_t* data, int length, int bytesPerLine) { +QByteArray ReStringUtil::hexDump(uint8_t* data, int length, int bytesPerLine) { QByteArray rc; int fullLines = length / bytesPerLine; int expectedLength = (bytesPerLine * 4 + 2) * (fullLines + 1); @@ -175,7 +175,7 @@ QByteArray RplString::hexDump(uint8_t* data, int length, int bytesPerLine) { * the result will not contain this * @return the file's content */ -QByteArray RplString::read(const char* file, bool removeLastNewline) { +QByteArray ReStringUtil::read(const char* file, bool removeLastNewline) { QByteArray rc; struct stat info; size_t size; @@ -193,7 +193,7 @@ QByteArray RplString::read(const char* file, bool removeLastNewline) { return rc; } -QByteArray RplString::replaceNode(const char* source, const char* newNode){ +QByteArray ReStringUtil::replaceNode(const char* source, const char* newNode){ char sep = fileSeparatorChar(); const char* ptr = strrchr(source, sep); QByteArray rc; @@ -215,7 +215,7 @@ QByteArray RplString::replaceNode(const char* source, const char* newNode){ * @param separator the separator between the items to split * @return an array with the splitted source */ -QList RplString::toArray(const char* source, +QList ReStringUtil::toArray(const char* source, const char* separator) { const char* end = source; QList rc; @@ -234,7 +234,7 @@ QList RplString::toArray(const char* source, return rc; } -QByteArray RplString::toCString(const char* source, int maxLength){ +QByteArray ReStringUtil::toCString(const char* source, int maxLength){ if (maxLength <= 0) maxLength = strlen(source); int binaries = 0; @@ -284,7 +284,7 @@ QByteArray RplString::toCString(const char* source, int maxLength){ * @param format format like in sprintf() * @return the ascii form of the value */ -QByteArray RplString::toNumber(int value, const char* format) { +QByteArray ReStringUtil::toNumber(int value, const char* format) { char buffer[128]; qsnprintf(buffer, sizeof buffer, format, value); return QByteArray(buffer); @@ -299,7 +299,7 @@ QByteArray RplString::toNumber(int value, const char* format) { * @return true: successful
* false: error occurred */ -bool RplString::write(const char* file, const char* content, const char* mode) { +bool ReStringUtil::write(const char* file, const char* content, const char* mode) { FILE* fp = fopen(file, mode); if(fp != NULL) { fputs(content, fp); @@ -316,7 +316,7 @@ bool RplString::write(const char* file, const char* content, const char* mode) { * @return 0: not a number
* otherwise: the length of the number string */ -int RplString::lengthOfNumber(const char* text, bool skipTrailingSpaces){ +int ReStringUtil::lengthOfNumber(const char* text, bool skipTrailingSpaces){ int rc = 0; bool found = false; const char* ptr = text; @@ -367,10 +367,10 @@ int RplString::lengthOfNumber(const char* text, bool skipTrailingSpaces){ static void addSeparators(const char* line, int& commas, int& semicolons, int& pipes, int& blanks) { - commas += RplString::countChar(line, ','); - semicolons += RplString::countChar(line, ';'); - pipes += RplString::countChar(line, '|'); - blanks += RplString::countChar(line, ' '); + commas += ReStringUtil::countChar(line, ','); + semicolons += ReStringUtil::countChar(line, ';'); + pipes += ReStringUtil::countChar(line, '|'); + blanks += ReStringUtil::countChar(line, ' '); } /** @@ -385,7 +385,7 @@ static void addSeparators(const char* line, int& commas, int& semicolons, * @param buffer a line buffer * @param bufferSize the size of buffer[] */ -char RplString::findCsvSeparator(FILE* fp, char* buffer, size_t bufferSize){ +char ReStringUtil::findCsvSeparator(FILE* fp, char* buffer, size_t bufferSize){ char rc = '\0'; int lineNo = 0; int maxLines = 5; @@ -431,9 +431,9 @@ char RplString::findCsvSeparator(FILE* fp, char* buffer, size_t bufferSize){ * @return <=0: no integer found * otherwise: the length of the integer */ -int RplString::lengthOfUInt64(const char* text, int radix, quint64* pValue) +int ReStringUtil::lengthOfUInt64(const char* text, int radix, quint64* pValue) { - qint64 value = 0; + int64_t value = 0; int length = 0; int cc; if (radix == 10){ @@ -462,7 +462,7 @@ int RplString::lengthOfUInt64(const char* text, int radix, quint64* pValue) length++; } } else { - throw RplException("RplString::lengthOfInt(): wrong radix: %d", radix); + throw ReException("ReStringUtil::lengthOfInt(): wrong radix: %d", radix); } if (pValue != NULL) *pValue = value; @@ -478,7 +478,7 @@ int RplString::lengthOfUInt64(const char* text, int radix, quint64* pValue) * @return <=0: no real number found * otherwise: the length of the floating point number */ -int RplString::lengthOfReal(const char* text, qreal* pValue) +int ReStringUtil::lengthOfReal(const char* text, qreal* pValue) { qreal value = 0.0; int cc; diff --git a/rplcore/rplstring.hpp b/base/ReStringUtil.hpp similarity index 98% rename from rplcore/rplstring.hpp rename to base/ReStringUtil.hpp index ee8924c..831503c 100644 --- a/rplcore/rplstring.hpp +++ b/base/ReStringUtil.hpp @@ -8,7 +8,7 @@ #ifndef RPLSTRING_HPP #define RPLSTRING_HPP -class RplString { +class ReStringUtil { public: static int countChar(const char* line, char cc); static int count(const char* source, const char* item); diff --git a/rplcore/rplterminator.cpp b/base/ReTerminator.cpp similarity index 69% rename from rplcore/rplterminator.cpp rename to base/ReTerminator.cpp index 4fab794..45f46d1 100644 --- a/rplcore/rplterminator.cpp +++ b/base/ReTerminator.cpp @@ -11,22 +11,22 @@ /** @file * @brief Definitions for a thread stopper. */ -#include "rplcore.hpp" +#include "base/rebase.hpp" enum { - LOC_CAUSE_TERMINATION_1 = RPL_FIRST_OF(RPLMODULE_TERMINATOR), // 10901 + LOC_CAUSE_TERMINATION_1 = LOC_FIRST_OF(LOC_TERMINATOR), // 10901 }; /** - * @class RplTerminator rplterminator.hpp "rplcore/rplterminator.hpp" + * @class ReTerminator ReTerminator.hpp "rplcore/ReTerminator.hpp" * * @brief Implements a thread stopper. * * Allows to terminate a thread avoiding unfreeing resources, deadlocks etc. * - * The application must create one instance of a RplTerminator. - * All threads gets this instance and call them periodically if the application should stop. - * If yes they finish their work, frees the resources and stop. + * The application must create one instance of a ReTerminator. + * All threads get this instance and call them periodically if the application should stop. + * If yes they finish their work, free the resources and stop. * */ @@ -34,7 +34,7 @@ enum { * @brief Constructor. * @param logger NULL or the logger. Used to protocol the termination */ -RplTerminator::RplTerminator(RplLogger* logger) : +ReTerminator::ReTerminator(ReLogger* logger) : m_stop(false), m_logger(logger) { } @@ -42,7 +42,7 @@ RplTerminator::RplTerminator(RplLogger* logger) : /** * @brief Destructor. */ -RplTerminator::~RplTerminator() { +ReTerminator::~ReTerminator() { } /** @@ -54,8 +54,8 @@ RplTerminator::~RplTerminator() { * @param level log level * @param location 0 or the location of the caller */ -void RplTerminator::causeTermination(const char* reason, const char* file, - int lineNo, RplLoggerLevel level, int location) { +void ReTerminator::causeTermination(const char* reason, const char* file, + int lineNo, ReLoggerLevel level, int location) { if(m_logger != NULL) { QByteArray message(reason); if(file != NULL) { @@ -72,7 +72,7 @@ void RplTerminator::causeTermination(const char* reason, const char* file, * @return true: the thread should be stopped.
* false: otherwise */ -bool RplTerminator::isStopped() const { +bool ReTerminator::isStopped() const { return m_stop; } diff --git a/rplcore/rplterminator.hpp b/base/ReTerminator.hpp similarity index 63% rename from rplcore/rplterminator.hpp rename to base/ReTerminator.hpp index f0e49c1..e96ff27 100644 --- a/rplcore/rplterminator.hpp +++ b/base/ReTerminator.hpp @@ -8,22 +8,22 @@ #ifndef RPLTERMINATOR_HPP #define RPLTERMINATOR_HPP -class RplTerminator { +class ReTerminator { public: - RplTerminator(RplLogger* logger = NULL); - virtual ~RplTerminator(); + ReTerminator(ReLogger* logger = NULL); + virtual ~ReTerminator(); private: // No copy constructor: no implementation! - RplTerminator(const RplTerminator& source); + ReTerminator(const ReTerminator& source); // Prohibits assignment operator: no implementation! - RplTerminator& operator =(const RplTerminator& source); + ReTerminator& operator =(const ReTerminator& source); public: void causeTermination(const char* reason, const char* file = NULL, - int lineNo = 0, RplLoggerLevel level = LOG_ERROR, int location = 0); + int lineNo = 0, ReLoggerLevel level = LOG_ERROR, int location = 0); bool isStopped() const; private: bool m_stop; - RplLogger* m_logger; + ReLogger* m_logger; }; #endif // RPLTERMINATOR_HPP diff --git a/rplcore/rpltest.cpp b/base/ReTest.cpp similarity index 87% rename from rplcore/rpltest.cpp rename to base/ReTest.cpp index ea31b61..1bccfe3 100644 --- a/rplcore/rpltest.cpp +++ b/base/ReTest.cpp @@ -12,10 +12,9 @@ * * @brief Definitions for a testing tool like JUnit. */ -#include "rplcore/rplcore.hpp" -#include "rpltest.hpp" +#include "base/rebase.hpp" -/** @class RplTest rpltest.hpp "rplcore/repltest" +/** @class ReTest rpltest.hpp "rplcore/repltest" * * @brief Implements an unit test base class similar JUnit for java. * @@ -23,14 +22,14 @@ * * @see rplexample.cpp */ -class RplTest; +class ReTest; /** * @brief Constructor. * * @param name */ -RplTest::RplTest(const char* name) : +ReTest::ReTest(const char* name) : m_errors(0), m_name(name), m_logger(), @@ -41,15 +40,9 @@ RplTest::RplTest(const char* name) : m_logger.buildStandardAppender(getTempDir("rpltest")); log(QByteArray("Start of ") + m_name); m_memoryLogger.addAppender(&m_memoryAppender); -} - -/** - * @brief Runs all tests of the test class. - */ -void RplTest::run() { try { - doIt(); - } catch(RplException e) { + run(); + } catch(ReException e) { error("unexpected RplException: %s", e.getMessage().constData()); } catch(...){ error("unknown Exception"); @@ -65,7 +58,7 @@ void RplTest::run() { /** * @brief Destructor. */ -RplTest::~RplTest() { +ReTest::~ReTest() { } /** @@ -79,7 +72,7 @@ RplTest::~RplTest() { * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(int expected, int current, const char* file, +bool ReTest::assertEquals(int expected, int current, const char* file, int lineNo) { if(expected != current) error("%s-%d: error: %d != %d / %x != %x)", file, lineNo, expected, current, @@ -98,7 +91,7 @@ bool RplTest::assertEquals(int expected, int current, const char* file, * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(qint64 expected, qint64 current, const char* file, +bool ReTest::assertEquals(int64_t expected, int64_t current, const char* file, int lineNo) { if(expected != current) error("%s-%d: error: %lld != %lld / %llx != %llx)", file, lineNo, @@ -118,7 +111,7 @@ bool RplTest::assertEquals(qint64 expected, qint64 current, const char* file, * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(qreal expected, qreal current, const char* file, +bool ReTest::assertEquals(qreal expected, qreal current, const char* file, int lineNo) { if(expected != current) error("%s-%d: error: %d != %d / %x != %x)", file, lineNo, expected, current, @@ -137,7 +130,7 @@ bool RplTest::assertEquals(qreal expected, qreal current, const char* file, * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(const char* expected, const QString& current, +bool ReTest::assertEquals(const char* expected, const ReString& current, const char* file, int lineNo) { bool equal = assertEquals(expected, current.toUtf8().constData(), file, lineNo); @@ -155,7 +148,7 @@ bool RplTest::assertEquals(const char* expected, const QString& current, * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(const QString& expected, const QString& current, +bool ReTest::assertEquals(const ReString& expected, const ReString& current, const char* file, int lineNo) { bool equal = assertEquals(expected.toUtf8().constData(), current.toUtf8().constData(), file, lineNo); @@ -174,13 +167,13 @@ bool RplTest::assertEquals(const QString& expected, const QString& current, * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(const char* expected, const char* current, +bool ReTest::assertEquals(const char* expected, const char* current, const char* file, int lineNo) { bool equal = strcmp(expected, current) == 0; if(! equal) { if(strchr(expected, '\n') != NULL || strchr(current, '\n')) { - QList exp = RplString::toArray(expected, "\n"); - QList cur = RplString::toArray(current, "\n"); + QList exp = ReStringUtil::toArray(expected, "\n"); + QList cur = ReStringUtil::toArray(current, "\n"); equal = assertEquals(exp, cur, file, lineNo); } else { int ix = 0; @@ -218,7 +211,7 @@ bool RplTest::assertEquals(const char* expected, const char* current, * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(const QList& expected, +bool ReTest::assertEquals(const QList& expected, const QList& current, const char* file, int lineNo) { int nMax = expected.size(); bool rc = true; @@ -255,7 +248,7 @@ bool RplTest::assertEquals(const QList& expected, * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(const QByteArray& expected, +bool ReTest::assertEquals(const QByteArray& expected, const QByteArray& current, const char* file, int lineNo) { return assertEquals(expected.data(), current.data(), file, lineNo); } @@ -271,7 +264,7 @@ bool RplTest::assertEquals(const QByteArray& expected, * @param lineNo the line number containing the test * @return true: equal */ -bool RplTest::assertEquals(const char* expected, const QByteArray& current, +bool ReTest::assertEquals(const char* expected, const QByteArray& current, const char* file, int lineNo) { return assertEquals(expected, current.constData(), file, lineNo); } @@ -286,7 +279,7 @@ bool RplTest::assertEquals(const char* expected, const QByteArray& current, * @param lineNo the line number containing the test * @return condition */ -bool RplTest::assertTrue(bool condition, const char* file, int lineNo) { +bool ReTest::assertTrue(bool condition, const char* file, int lineNo) { if(! condition) error("%s-%d: not TRUE", file, lineNo); return condition; @@ -302,7 +295,7 @@ bool RplTest::assertTrue(bool condition, const char* file, int lineNo) { * @param lineNo the line number containing the test * @return ! condition */ -bool RplTest::assertFalse(bool condition, const char* file, int lineNo) { +bool ReTest::assertFalse(bool condition, const char* file, int lineNo) { if(condition) error("%s-%d: not FALSE", file, lineNo); return ! condition; @@ -318,7 +311,7 @@ bool RplTest::assertFalse(bool condition, const char* file, int lineNo) { * @param lineNo the line number containing the test * @return true: ptr is NULL */ -bool RplTest::assertNull(const void* ptr, const char* file, int lineNo) { +bool ReTest::assertNull(const void* ptr, const char* file, int lineNo) { if(ptr != NULL) error("%s-%d: not NULL", file, lineNo); return ptr == NULL; @@ -334,7 +327,7 @@ bool RplTest::assertNull(const void* ptr, const char* file, int lineNo) { * @param lineNo the line number containing the test * @return true: ptr is not NULL */ -bool RplTest::assertNotNull(const void* ptr, const char* file, int lineNo) { +bool ReTest::assertNotNull(const void* ptr, const char* file, int lineNo) { if(ptr == NULL) error("%s-%d: is NULL", file, lineNo); return ptr != NULL; @@ -350,12 +343,12 @@ bool RplTest::assertNotNull(const void* ptr, const char* file, int lineNo) { * @return true: the files are equal
* false: otherwise */ -bool RplTest::assertEqualFiles(const char* expected, const char* current, +bool ReTest::assertEqualFiles(const char* expected, const char* current, const char* file, int lineNo) { bool rc = false; - QByteArray expectedContent = RplString::read(expected, true); - QByteArray currentContent = RplString::read(current, true); + QByteArray expectedContent = ReStringUtil::read(expected, true); + QByteArray currentContent = ReStringUtil::read(current, true); if (expectedContent.isEmpty()){ char buffer[512]; qsnprintf(buffer, sizeof buffer, "%s has no content. Does it exist?", @@ -380,7 +373,7 @@ bool RplTest::assertEqualFiles(const char* expected, const char* current, * @param message message to show * @return true (for chaining) */ -bool RplTest::log(const char* message) { +bool ReTest::log(const char* message) { m_logger.log(LOG_INFO, 0, message); return true; } @@ -393,7 +386,7 @@ bool RplTest::log(const char* message) { * @param ... the values for the placeholders in format * @return false (for chaining) */ -bool RplTest::error(const char* format, ...) { +bool ReTest::error(const char* format, ...) { m_errors++; va_list ap; va_start(ap, format); @@ -409,7 +402,7 @@ bool RplTest::error(const char* format, ...) { * @return true: pattern has been found
* false: otherwise */ -bool RplTest::logContains(const char* pattern) +bool ReTest::logContains(const char* pattern) { const QList& lines = m_memoryAppender.getLines(); QRegularExpression rexpr(pattern); @@ -436,7 +429,7 @@ bool RplTest::logContains(const char* pattern) * @param withSeparator true: the result ends with slash/backslash * @return the name of an existing directory */ -QByteArray RplTest::getTempDir(const char* node, const char* parent, +QByteArray ReTest::getTempDir(const char* node, const char* parent, bool withSeparator) { QByteArray temp("c:\\temp"); struct stat info; @@ -475,7 +468,7 @@ QByteArray RplTest::getTempDir(const char* node, const char* parent, * @param deleteIfExists true: if the file exists it will be removed * @return the full name of a temporary file */ -QByteArray RplTest::getTempFile(const char* node, const char* parent, +QByteArray ReTest::getTempFile(const char* node, const char* parent, bool deleteIfExists) { QByteArray dir = getTempDir(parent); QByteArray rc = dir; diff --git a/rplcore/rpltest.hpp b/base/ReTest.hpp similarity index 77% rename from rplcore/rpltest.hpp rename to base/ReTest.hpp index 5c7d3ac..ec04340 100644 --- a/rplcore/rpltest.hpp +++ b/base/ReTest.hpp @@ -5,30 +5,26 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#ifndef RPLTEST_HPP -#define RPLTEST_HPP +#ifndef RETEST_HPP +#define RETEST_HPP // the sources generated from QT include this file directly: -#ifndef RPLCORE_HPP -#include -#endif - -class RplTest { +class ReTest { public: - RplTest(const char* name); - virtual ~RplTest(); + ReTest(const char* name); + virtual ~ReTest(); private: // No copy constructor: no implementation! - RplTest(const RplTest& source); + ReTest(const ReTest& source); // Prohibits assignment operator: no implementation! - RplTest& operator =(const RplTest& source); + ReTest& operator =(const ReTest& source); public: bool assertEquals(int expected, int current, const char* file, int lineNo); - bool assertEquals(qint64 expected, qint64 current, const char* file, int lineNo); + bool assertEquals(int64_t expected, int64_t current, const char* file, int lineNo); bool assertEquals(qreal expected, qreal current, const char* file, int lineNo); - bool assertEquals(const char* expected, const QString& current, + bool assertEquals(const char* expected, const ReString& current, const char* file, int lineNo); - bool assertEquals(const QString& expected, const QString& current, + bool assertEquals(const ReString& expected, const ReString& current, const char* file, int lineNo); bool assertEquals(const char* expected, const char* current, const char* file, int lineNo); @@ -51,23 +47,21 @@ public: QByteArray getTempFile(const char* node, const char* parent = NULL, bool deleteIfExists = true); bool logContains(const char* pattern); - void run(); -protected: - virtual void doIt(void) = 0; + virtual void run(void) = 0; protected: int m_errors; QByteArray m_name; - RplLogger m_logger; + ReLogger m_logger; // for testing of logging code: - RplMemoryAppender m_memoryAppender; - RplLogger m_memoryLogger; + ReMemoryAppender m_memoryAppender; + ReLogger m_memoryLogger; char m_separator; }; -#define checkE(expected, current) assertEquals(expected, current, __FILE__, __LINE__) +#define checkEqu(expected, current) assertEquals(expected, current, __FILE__, __LINE__) #define checkT(current) assertTrue(current, __FILE__, __LINE__) #define checkF(current) assertFalse(current, __FILE__, __LINE__) #define checkN(current) assertNull(current, __FILE__, __LINE__) #define checkNN(current) assertNotNull(current, __FILE__, __LINE__) #define checkFiles(expected, current) assertEqualFiles(expected, current, __FILE__, __LINE__) -#endif // RPLTEST_HPP +#endif // RETEST_HPP diff --git a/rplcore/rplwriter.cpp b/base/ReWriter.cpp similarity index 79% rename from rplcore/rplwriter.cpp rename to base/ReWriter.cpp index 53e018b..ecfb73d 100644 --- a/rplcore/rplwriter.cpp +++ b/base/ReWriter.cpp @@ -9,19 +9,19 @@ /** @file * @brief A writer to an output media. * - * Implementation of the abstract base class RplWriter and - * the concrete derivation RplFileWriter. + * Implementation of the abstract base class ReWriter and + * the concrete derivation ReFileWriter. */ /** @file rplcore/rplwriter.hpp * * @brief Definitions for a writer to an output media. */ -#include "rplcore/rplcore.hpp" +#include "base/rebase.hpp" -const char* RplWriter::m_tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; -int RplWriter::m_maxIndention = strlen(RplWriter::m_tabs); +const char* ReWriter::m_tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; +int ReWriter::m_maxIndention = strlen(ReWriter::m_tabs); -/** @class RplWriter rplwriter.hpp "rplcore/rplwriter.hpp" +/** @class ReWriter ReWriter.hpp "rplcore/ReWriter.hpp" * * @brief Implements an abstract base class for producing text lines. * @@ -33,7 +33,7 @@ int RplWriter::m_maxIndention = strlen(RplWriter::m_tabs); * Closes the output medium. * Ensures that the destructors of the derived classes are virtual. */ -RplWriter::~RplWriter() +ReWriter::~ReWriter() { close(); } @@ -45,7 +45,7 @@ RplWriter::~RplWriter() * * @note The method must be designed so that it can be called multiple times. */ -void RplWriter::close() +void ReWriter::close() { } /** @@ -53,7 +53,7 @@ void RplWriter::close() * * @param indent indention level, number of "\t" */ -void RplWriter::indent(int indent) +void ReWriter::indent(int indent) { if (indent > m_maxIndention) indent = m_maxIndention; @@ -66,7 +66,7 @@ void RplWriter::indent(int indent) * @param format format string with placeholders like sprintf() * @param ... variable arguments, values for the placeholders */ -void RplWriter::format(const char* format, ...) +void ReWriter::format(const char* format, ...) { va_list ap; va_start(ap, format); @@ -79,7 +79,7 @@ void RplWriter::format(const char* format, ...) * @param format format string with placeholders like sprintf() * @param ... variable arguments, values for the placeholders */ -void RplWriter::formatLine(const char* format, ...) +void ReWriter::formatLine(const char* format, ...) { char buffer[64000]; va_list ap; @@ -95,7 +95,7 @@ void RplWriter::formatLine(const char* format, ...) * @param ap variable argument list (like in vsprintf) * @param format format string with placeholders */ -void RplWriter::write(va_list ap, const char* format) +void ReWriter::write(va_list ap, const char* format) { char buffer[64000]; qvsnprintf(buffer, sizeof buffer, format, ap); @@ -108,9 +108,9 @@ void RplWriter::write(va_list ap, const char* format) * @param indent indention level. Indention is limited to 20 * @param line the line to write */ -void RplWriter::writeIndented(int indent, const char* line) +void ReWriter::writeIndented(int indent, const char* line) { - RplWriter::indent(indent); + ReWriter::indent(indent); writeLine(line); } @@ -121,9 +121,9 @@ void RplWriter::writeIndented(int indent, const char* line) * @param format format string with placeholders like sprintf * @param ... the values for the placeholders (variable arguments) */ -void RplWriter::formatIndented(int indent, const char* format, ...) +void ReWriter::formatIndented(int indent, const char* format, ...) { - RplWriter::indent(indent); + ReWriter::indent(indent); char buffer[64000]; va_list ap; @@ -133,7 +133,7 @@ void RplWriter::formatIndented(int indent, const char* format, ...) writeLine(buffer); } -/** @class RplWriter rplwriter.hpp "rplcore/rplwriter.hpp" +/** @class ReWriter rplwriter.hpp "rplcore/rplwriter.hpp" * * @brief Implements a class which writes lines into a file. */ @@ -148,7 +148,7 @@ void RplWriter::formatIndented(int indent, const char* format, ...) * stderr * @param eoln line end: "\n" or "\r\n" */ -RplFileWriter::RplFileWriter(const char* filename, const char* mode, +ReFileWriter::ReFileWriter(const char* filename, const char* mode, FILE* additionalStream, const char* eoln) : m_fp(fopen(filename, mode)), m_name(filename), @@ -161,7 +161,7 @@ RplFileWriter::RplFileWriter(const char* filename, const char* mode, * @brief Writes a string to the file. * @param message the string to write */ -void RplFileWriter::write(const char* message) +void ReFileWriter::write(const char* message) { if (m_fp != NULL) fputs(message, m_fp); @@ -173,7 +173,7 @@ void RplFileWriter::write(const char* message) * @brief Writes a line to the file. * @param line the line to write. If NULL an empty line will be written */ -void RplFileWriter::writeLine(const char* line) +void ReFileWriter::writeLine(const char* line) { if (m_fp != NULL){ if (line != NULL) @@ -190,7 +190,7 @@ void RplFileWriter::writeLine(const char* line) /** * @brief Closes the output file. */ -void RplFileWriter::close() +void ReFileWriter::close() { if (m_fp != NULL){ fclose(m_fp); diff --git a/rplcore/rplwriter.hpp b/base/ReWriter.hpp similarity index 86% rename from rplcore/rplwriter.hpp rename to base/ReWriter.hpp index 7b661e3..a53120b 100644 --- a/rplcore/rplwriter.hpp +++ b/base/ReWriter.hpp @@ -7,13 +7,13 @@ */ -#ifndef RPLWRITER_HPP -#define RPLWRITER_HPP +#ifndef REWRITER_HPP +#define REWRITER_HPP -class RplWriter +class ReWriter { public: - virtual ~RplWriter(); + virtual ~ReWriter(); public: /** * @brief Writes a text to the output medium. @@ -40,10 +40,10 @@ protected: static int m_maxIndention; }; -class RplFileWriter : public RplWriter +class ReFileWriter : public ReWriter { public: - RplFileWriter(const char* filename, const char* mode = "w", + ReFileWriter(const char* filename, const char* mode = "w", FILE* additionalStream = NULL, const char* eoln = "\n"); public: virtual void write(const char* line); @@ -56,4 +56,4 @@ protected: FILE* m_additionalStream; }; -#endif // RPLWRITER_HPP +#endif // REWRITER_HPP diff --git a/rplcore/rplcore.hpp b/base/rebase.hpp similarity index 52% rename from rplcore/rplcore.hpp rename to base/rebase.hpp index 8df4f75..a415c98 100644 --- a/rplcore/rplcore.hpp +++ b/base/rebase.hpp @@ -5,8 +5,8 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#ifndef RPLCORE_HPP -#define RPLCORE_HPP +#ifndef RECORE_HPP +#define RECORE_HPP #include #include @@ -28,22 +28,29 @@ #include #include #include -#include +#include typedef unsigned char uint8_t; +//typedef qint64 int64_t; +typedef quint64 uint64_t; +typedef qint32 int32_t; +typedef quint32 uint32_t; +typedef qreal real_t; +typedef QString ReString; #define RPL_UNUSED(x) (void)(x) -#include "rplmodules.hpp" -#include "rplcore/rplbytestorage.hpp" -#include "rplcore/rplcharptrmap.hpp" -#include "rplcore/rplwriter.hpp" -#include "rplcore/rpllogger.hpp" -#include "rplcore/rplexception.hpp" -#include "rplcore/rplcontainer.hpp" -#include "rplcore/rplstring.hpp" -#include "rplcore/rplqstring.hpp" -#include "rplcore/rplconfigurator.hpp" -#include "rplcore/rplconfig.hpp" -#include "rplcore/rplterminator.hpp" +#include "remodules.hpp" +#include "base/ReByteStorage.hpp" +#include "base/ReCharPtrMap.hpp" +#include "base/ReWriter.hpp" +#include "base/ReLogger.hpp" +#include "base/ReException.hpp" +#include "base/ReContainer.hpp" +#include "base/ReStringUtil.hpp" +#include "base/ReQtring.hpp" +#include "base/ReConfigurator.hpp" +#include "base/ReConfig.hpp" +#include "base/ReTerminator.hpp" +#include "base/ReTest.hpp" -#endif // RPLCORE_HPP +#endif // RECORE_HPP diff --git a/rplcore/testrplexample.cpp b/base/testrplexample.cpp similarity index 78% rename from rplcore/testrplexample.cpp rename to base/testrplexample.cpp index 695fbae..0c89591 100644 --- a/rplcore/testrplexample.cpp +++ b/base/testrplexample.cpp @@ -7,7 +7,7 @@ */ include "project.hpp" -#include "rplcore/rpltest.hpp" +#include "base/base.hpp" // Code to test: int add(int a, int b) { return a+b; @@ -19,21 +19,21 @@ const char* firstDot(const char* s) { return strchr(s, '.'); } /** - * @brief Example for usage of the class RplTest. + * @brief Example for usage of the class ReTest. */ -class TestRplExample : public RplTest { +class TestRplExample : public ReTest { public: - TestRplExample() : RplTest("RplExample") {} + TestRplExample() : ReTest("RplExample") {} public: void testInt() { log("testing add..."); // compare 2 integers: - checkE(2, add(1, 1)); + checkEqu(2, add(1, 1)); } void testString() { // compare 2 strings: - checkE("Be good", concat("Be", "good")); + checkEqu("Be good", concat("Be", "good")); // test for not NULL: checkN(firstDot("Hi.")); // test for NULL: diff --git a/cunit/cuReConfig.cpp b/cunit/cuReConfig.cpp new file mode 100644 index 0000000..76fa172 --- /dev/null +++ b/cunit/cuReConfig.cpp @@ -0,0 +1,60 @@ +/* + * cuReConfig.cpp + * + * 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 "base/rebase.hpp" +/** + * @brief Unit test of ReConfig. + */ +class TestReConfig: public ReTest { +public: + TestReConfig() : + ReTest("ReConfig") { + } + +public: + void testBasic() { + QByteArray fn = getTempFile("test.data", "config"); + ReStringUtil::write(fn, "#comment\na=1\nb.1==x\n#=\nB=zzz"); + ReConfig config(fn.constData()); + checkEqu(3, config.size()); + checkEqu("1", config["a"]); + checkEqu("=x", config["b.1"]); + checkEqu("zzz", config["B"]); + } + void testAsX() { + QByteArray fn = getTempFile("test.data", "config"); + ReStringUtil::write(fn, "i=123\nb=1\nb2=true\nb3=yes\ns=abc"); + ReConfig config(fn.constData()); + checkEqu(5, config.size()); + checkEqu(123, config.asInt("i", -1)); + checkEqu(-1, config.asInt("I", -1)); + checkT(config.asBool("b", false)); + checkT(config.asBool("b2", false)); + checkT(config.asBool("b3", false)); + checkT(config.asBool("-", true)); + checkF(config.asBool("-", false)); + checkEqu("abc", config.asString("s", "x")); + checkEqu("x", config.asString("S", "x")); + } + + virtual void run() { + testAsX(); + testBasic(); + + } +}; + +void testReConfig() { + TestReConfig test; +} + + + + diff --git a/cunit/cuReContainer.cpp b/cunit/cuReContainer.cpp new file mode 100644 index 0000000..8b3b38e --- /dev/null +++ b/cunit/cuReContainer.cpp @@ -0,0 +1,58 @@ +/* + * cuReContainer.cpp + * + * 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 "base/rebase.hpp" +/** + * @brief Unit test for ReContainer + */ +class TestRplContainer : public ReTest { +public: + TestRplContainer() : ReTest("RplContainer") {} + +public: + void testBasic() { + ReContainer container(256); + // Rpl&1 09 36[2]cis:!7b Nirwana <0> Y -ab34 A long string with an trailing '0' <0>
+ container.startBag(); + container.addChar('!'); + container.addInt(123); + container.addString("Nirwana"); + container.startBag(); + container.addChar('Y'); + container.addInt(-0xab34); + container.addString("A long string with an trailing '0'"); + + QByteArray data = container.getData(); + + ReContainer container2(256); + container2.fill(data); + checkEqu(2, container2.getCountBags()); + checkEqu('!', container2.nextChar()); + checkEqu(123, container2.nextInt()); + checkEqu("Nirwana", container2.nextString()); + container2.nextBag(); + checkEqu('Y', container2.nextChar()); + checkEqu(-0xab34, container2.nextInt()); + checkEqu("A long string with an trailing '0'", container2.nextString()); + + log(("Example: " + data).constData()); + } + + virtual void run() { + testBasic(); + } +}; + +void testRplContainer() { + TestRplContainer test; +} + + + + diff --git a/cunit/cuReEnigma.cpp b/cunit/cuReEnigma.cpp new file mode 100644 index 0000000..6688df5 --- /dev/null +++ b/cunit/cuReEnigma.cpp @@ -0,0 +1,112 @@ +/* + * 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 "base/rebase.hpp" +/** + * @brief Unit test for ReEnigma. + */ +class TestReEnigma : public ReTest { +public: + TestReEnigma() : ReTest("ReEnigma") {} + +public: + void testOneCharset(const char* value, const char* charSet, + const char* expected) { + ReEnigma enigma; + enigma.addByteSecret(QByteArray("Geheim")); + enigma.setSeed(0); + QByteArray encoded = value; + QByteArray booster; + enigma.encode(encoded.data(), encoded.length(), charSet, booster); + //printString(encoded.constData()); + QByteArray decoded = encoded; + enigma.setSeed(0); + enigma.decode(decoded.data(), decoded.length(), charSet, booster); + checkEqu(value, decoded.constData()); + checkEqu(expected, encoded); + } + + void printCharSets() { + QByteArray value; + value.reserve(256); + unsigned char cc; + for(cc = ' '; cc <= 127; cc++) { + if(cc == '"' || cc == '\\') + value.append('\\'); + value.append(cc); + } + printf("%s\n", value.constData()); + value.resize(0); + for(cc = 128; cc >= 128; cc++) { + char buf[10]; + if(cc % 32 == 0) + value.append("\n"); + sprintf(buf, "\\x%02x", cc); + value.append(buf); + } + printf("%s\n", value.constData()); + } + void printString(const char* value) { + QByteArray v; + unsigned char cc; + while((cc = (unsigned char) *value++) != 0) { + if(cc == '\\' || cc == '"') { + v.append('\\'); + v.append(cc); + } else if(cc >= 127) { + char buffer[10]; + sprintf(buffer, "\\x%02x", cc); + v.append(buffer); + } else { + v.append(cc); + } + } + printf("%s\n", v.constData()); + } + void testOneBytes(const char* bytes) { + ReEnigma enigma; + enigma.addByteSecret("Hello World"); + enigma.setSeed(0x1234); + + QByteArray encoded(bytes); + enigma.change(encoded); + + enigma.setSeed(0x1234); + QByteArray decoded(encoded); + enigma.change(decoded); + checkEqu(bytes, decoded); + } + + void testBytes() { + testOneBytes("abcdefg"); + testOneBytes("01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); + } + + void testCharSet() { + //testOneCharset("&()[]{}Weiß der Geier/Kuckuck?", ReEnigma::SET_32_255, "2Kc\x9a\xfeQ\xd7\xa84sx)*\xfb\xd2z\xf4\"W\xb0\xee\xb0\xd1\x84\xace\xf8_u*T"); + testOneCharset("\\Weiß der Geier/Kuckuck?", ReEnigma::SET_32_127, + "(Z?hßaZ_#/QZ+Oi|SI^=<,)A"); + testOneCharset("01234567890abcdef", ReEnigma::SET_HEXDIGITS, + "c4c25b08735c53a63"); + testOneCharset("data$1%3.^~", ReEnigma::SET_FILENAME, "^voazo-n%$b"); + testOneCharset("Weiß der Geier!", ReEnigma::SET_ALPHANUM, "weyß BCk 19NoO!"); + testOneCharset("12345678901234567890", ReEnigma::SET_DECIMALS, + "97394833084815683977"); + testOneCharset("000000000000000000000000000", ReEnigma::SET_DECIMALS, + "850592651836811261879625929"); + } + + virtual void doIt() { + testBytes(); + testCharSet(); + } +}; + +void testReEnigma() { + TestReEnigma test; + test.run(); +} diff --git a/unittests/main.cpp b/cunit/main.cpp similarity index 75% rename from unittests/main.cpp rename to cunit/main.cpp index 588f9e8..56bafc5 100644 --- a/unittests/main.cpp +++ b/cunit/main.cpp @@ -11,11 +11,11 @@ #include void testCore(){ - extern void testRplString(); - testRplString(); + extern void testReString(); + testReString(); - extern void testRplCharPtrMap(); - testRplCharPtrMap(); + extern void testReCharPtrMap(); + testReCharPtrMap(); extern void testRplWriter(); testRplWriter(); @@ -26,8 +26,8 @@ void testCore(){ extern void testRplQString(); testRplQString(); - extern void testRplString(); - testRplString(); + extern void testReString(); + testReString(); extern void testRplException(); testRplException(); @@ -40,11 +40,11 @@ void testExpr(){ extern void testRplBenchmark(); //testRplBenchmark(); - extern void testRplVM(); - testRplVM(); + extern void testReVM(); + testReVM(); - extern void testRplSource(); - testRplSource(); + extern void testReSource(); + testReSource(); extern void testRplLexer(); testRplLexer(); @@ -52,11 +52,11 @@ void testExpr(){ extern void testRplMFParser(); testRplMFParser(); - extern void testRplASTree(); - testRplASTree(); + extern void testReASTree(); + testReASTree(); - extern void testRplVM(); - testRplVM(); + extern void testReVM(); + testReVM(); } diff --git a/cunit/rplastree_test.cpp b/cunit/rplastree_test.cpp new file mode 100644 index 0000000..2f03043 --- /dev/null +++ b/cunit/rplastree_test.cpp @@ -0,0 +1,103 @@ +/* + * 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. +*/ + +/** @file + * @brief Unit test of the abstract syntax tree. + */ + + +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" +#include "rplcore/rpltest.hpp" + +class TestReASTree : public ReTest{ +private: + ReSource m_source; + ReStringReader m_reader; + ReStringSourceUnit m_unit; + ReASTree m_tree; +public: + TestReASTree() : + ReTest("ReASTree"), + m_source(), + m_reader(m_source), + m_unit("
", "", &m_reader), + m_tree() + {} +public: + void testReASException() { + try{ + m_reader.addSource("
", "12"); + m_source.addReader(&m_reader); + m_source.addSourceUnit(m_reader.currentSourceUnit()); + const ReSourcePosition* pos = m_source.newPosition(2); + throw ReASException(pos, "simple string: %s", "Hi"); + checkF(true); + } catch (ReASException exc){ + checkEqu("
:0:2: simple string: Hi", exc.getMessage().constData()); + } + } + void testReASVariant(){ + ReASVariant val1; + val1.setFloat(2.5E-2); + checkEqu(2.5E-2, val1.asFloat()); + ReASVariant val2(val1); + checkEqu(2.5E-2, val2.asFloat()); + + val1.setInt(4321); + checkEqu(4321, val1.asInt()); + val2 = val1; + checkEqu(4321, val2.asInt()); + + val1.setBool(false); + checkF(val1.asBool()); + val2 = val1; + checkF(val2.asBool()); + + val1.setBool(true); + checkT(val1.asBool()); + val2 = val1; + checkT(val2.asBool()); + + val1.setString("High noon!"); + checkEqu("High noon!", *val1.asString()); + val2 = val1; + val1.setString("Bye"); + checkEqu("High noon!", *val2.asString()); + ReASVariant val3(val1); + checkEqu("Bye", *val3.asString()); + } + void testReASConstant(){ + ReASConstant constant; + //constant.value().setString("Jonny"); + ReASVariant value; + //constant.calc(value); + //checkEqu("Jonny", *value.asString()); + } + void testReASNamedValue(){ + ReASNamedValue value(NULL, m_tree.symbolSpaces()[0], "gugo", + ReASNamedValue::A_GLOBAL); + checkEqu("gugo", value.name()); + } + virtual void doIt() { + testReASNamedValue(); + testReASConstant(); + testReASException(); + testReASVariant(); + } +}; +void testReASTree() { + TestReASTree test; + test.run(); +} + + + + + + diff --git a/unittests/rplbench.cpp b/cunit/rplbench.cpp similarity index 72% rename from unittests/rplbench.cpp rename to cunit/rplbench.cpp index 86b6674..74dc740 100644 --- a/unittests/rplbench.cpp +++ b/cunit/rplbench.cpp @@ -11,19 +11,19 @@ */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" #include "rplcore/rpltest.hpp" -class TestRplBenchmark : public RplTest{ +class TestRplBenchmark : public ReTest{ private: const char* m_filename; - RplSource m_source; - RplFileReader m_reader; - RplASTree m_tree; + ReSource m_source; + ReFileReader m_reader; + ReASTree m_tree; public: TestRplBenchmark() : - RplTest("RplBenchmark"), + ReTest("RplBenchmark"), m_filename("/home/ws/qt/rplqt/bench/mfbench.mf"), m_source(), m_reader(m_source), @@ -35,19 +35,19 @@ public: public: void benchmark() { time_t start = time(NULL); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); time_t end = time(NULL); printf("compilation: %d sec\n", int(end - start)); } virtual void doIt() { try{ - RplFileSourceUnit* unit = dynamic_cast + ReFileSourceUnit* unit = dynamic_cast (m_reader.currentSourceUnit()); if (unit != NULL && ! unit->isOpen()) - throw RplException("file not found: %s", m_filename); + throw ReException("file not found: %s", m_filename); benchmark(); - } catch(RplException ex){ + } catch(ReException ex){ printf("%s\n", ex.getMessage().constData()); } } diff --git a/unittests/rplbytestorage_test.cpp b/cunit/rplbytestorage_test.cpp similarity index 79% rename from unittests/rplbytestorage_test.cpp rename to cunit/rplbytestorage_test.cpp index 1245694..52437d2 100644 --- a/unittests/rplbytestorage_test.cpp +++ b/cunit/rplbytestorage_test.cpp @@ -9,24 +9,24 @@ * @brief Unit test of the byte and C string storage. */ -#include "rplcore/rplcore.hpp" -#include "rplcore/rpltest.hpp" +#include "../base/rebase.hpp" +#include "../base/ReTest.hpp" -class TestRplByteStorage : public RplTest{ +class TestRplByteStorage : public ReTest{ public: TestRplByteStorage() : - RplTest("RplByteStorage") + ReTest("RplByteStorage") {} private: void testChars(){ - RplByteStorage store(100); + ReByteStorage store(100); char* s1 = store.allocateChars(4); memcpy((void*) s1, "123", 4); const char* s2 = store.allocateChars("abc"); const char* s3 = store.allocateChars("defghij", 3); - checkE(s1, "123"); - checkE(s2, "abc"); - checkE(s3, "def"); + checkEqu(s1, "123"); + checkEqu(s2, "abc"); + checkEqu(s3, "def"); const char* ptr = s1 + 4; checkT(ptr == s2); ptr += 4; @@ -34,14 +34,14 @@ private: } void testBytes(){ - RplByteStorage store(100); + ReByteStorage store(100); uint8_t* s1 = store.allocateBytes(4); memcpy((void*) s1, "1234", 4); uint8_t* s2 = store.allocateBytes((void*) "abcd", 4); uint8_t* s3 = store.allocateBytes((void*) "efghij", 4); uint8_t* s4 = store.allocateZeros(4); - checkE("1234abcdefgh", (const char*) s1); + checkEqu("1234abcdefgh", (const char*) s1); uint8_t* ptr = s1 + 4; checkT(ptr == s2); ptr += 4; @@ -49,10 +49,10 @@ private: ptr += 4; checkT(ptr == s4); for (int ii = 0; ii < 4; ii++) - checkE(0, (int) s4[ii]); + checkEqu(0, (int) s4[ii]); } void testBufferChange(){ - RplByteStorage store(10); + ReByteStorage store(10); char buffer[2]; buffer[1] = '\0'; for (int ii = 0; ii < 10000; ii++){ diff --git a/unittests/rplcharptrmap_test.cpp b/cunit/rplcharptrmap_test.cpp similarity index 65% rename from unittests/rplcharptrmap_test.cpp rename to cunit/rplcharptrmap_test.cpp index 3600efb..8ad1d78 100644 --- a/unittests/rplcharptrmap_test.cpp +++ b/cunit/rplcharptrmap_test.cpp @@ -6,29 +6,29 @@ * The original sources can be found on https://github.com/republib. */ -#include "rplcore/rplcore.hpp" +#include "base/rebase.hpp" #include "rplcore/rpltest.hpp" -class TestRplCharPtrMap : public RplTest{ +class TestReCharPtrMap : public ReTest{ public: - TestRplCharPtrMap() : - RplTest("RplCharPtrMap") + TestReCharPtrMap() : + ReTest("ReCharPtrMap") { } protected: void testBasic(){ - RplCharPtrMap map; + ReCharPtrMap map; map["x"] = "x1"; checkT(map.contains("x")); checkF(map.contains("y")); - checkE("x1", map["x"]); + checkEqu("x1", map["x"]); } virtual void doIt(void) { testBasic(); } }; -void testRplCharPtrMap() { - TestRplCharPtrMap test; +void testReCharPtrMap() { + TestReCharPtrMap test; test.run(); } diff --git a/unittests/rplexception_test.cpp b/cunit/rplexception_test.cpp similarity index 59% rename from unittests/rplexception_test.cpp rename to cunit/rplexception_test.cpp index 39e124a..57293cb 100644 --- a/unittests/rplexception_test.cpp +++ b/cunit/rplexception_test.cpp @@ -5,35 +5,35 @@ * 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 "base/rebase.hpp" #include "rplcore/rpltest.hpp" /** @file * @brief Unit test of the basic exceptions. */ -class TestRplException : public RplTest{ +class TestRplException : public ReTest{ public: - TestRplException() : RplTest("RplException") {} + TestRplException() : ReTest("RplException") {} public: void testBasic() { try{ - throw RplException("simple"); + throw ReException("simple"); checkF(true); - } catch (RplException exc){ - checkE("simple", exc.getMessage().constData()); + } catch (ReException exc){ + checkEqu("simple", exc.getMessage().constData()); } try{ - throw RplException("String: %s and int %d", "Hi", -333); + throw ReException("String: %s and int %d", "Hi", -333); checkF(true); - } catch (RplException exc){ - checkE("String: Hi and int -333", exc.getMessage().constData()); + } catch (ReException exc){ + checkEqu("String: Hi and int -333", exc.getMessage().constData()); } try{ - throw RplException(LOG_INFO, 1234, &m_memoryLogger, + throw ReException(LOG_INFO, 1234, &m_memoryLogger, "String: %s and int %d", "Hi", -333); checkF(true); - } catch (RplException exc){ + } catch (ReException exc){ checkT(logContains("^ .*\\(1234\\): String: Hi and int -333")); } log("ok"); diff --git a/unittests/rpllexer_test.cpp b/cunit/rpllexer_test.cpp similarity index 69% rename from unittests/rpllexer_test.cpp rename to cunit/rpllexer_test.cpp index 3d9696e..060e824 100644 --- a/unittests/rpllexer_test.cpp +++ b/cunit/rpllexer_test.cpp @@ -10,53 +10,53 @@ * @brief Unit test of the syntax symbol extractor. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" #include "rplcore/rpltest.hpp" -class TestRplLexer : public RplTest, public RplToken{ +class TestRplLexer : public ReTest, public ReToken{ public: TestRplLexer() : - RplTest("RplLexer"), - RplToken(TOKEN_ID) + ReTest("ReLexer"), + ReToken(TOKEN_ID) {} public: void testRplToken(){ // test constructor values: - checkE(TOKEN_ID, tokenType()); - checkE(0, m_value.m_id); + checkEqu(TOKEN_ID, tokenType()); + checkEqu(0, m_value.m_id); checkT(m_string.isEmpty()); checkT(m_printableString.isEmpty()); m_value.m_id = 7422; - checkE(7422, RplToken::id()); + checkEqu(7422, ReToken::id()); m_string = "Wow!"; - checkE("Wow!", RplToken::toString()); + checkEqu("Wow!", ReToken::toString()); m_printableString = "GooGoo"; - checkE("GooGoo", rawString()); + checkEqu("GooGoo", rawString()); m_tokenType = TOKEN_NUMBER; - checkE(TOKEN_NUMBER, tokenType()); + checkEqu(TOKEN_NUMBER, tokenType()); clear(); - checkE(TOKEN_UNDEF, tokenType()); - checkE(0, m_value.m_id); + checkEqu(TOKEN_UNDEF, tokenType()); + checkEqu(0, m_value.m_id); checkT(m_string.isEmpty()); checkT(m_printableString.isEmpty()); m_value.m_integer = 773322; - checkE(773322, asInteger()); + checkEqu(773322, asInteger()); m_value.m_real = 0.25; - checkE(0.25, asReal()); + checkEqu(0.25, asReal()); } - RplToken* checkToken(RplToken* token, RplTokenType type, int id = 0, + ReToken* checkToken(ReToken* token, RplTokenType type, int id = 0, const char* string = NULL){ - checkE(type, token->tokenType()); + checkEqu(type, token->tokenType()); if (id != 0) - checkE(id, token->id()); + checkEqu(id, token->id()); if (string != NULL) - checkE(string, token->toString()); + checkEqu(string, token->toString()); return token; } enum { KEY_UNDEF, KEY_IF, KEY_THEN, KEY_ELSE, KEY_FI @@ -71,52 +71,52 @@ public: }; # define COMMENTS "/* */ // \n" void testSpace(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); # define BLANKS1 "\t\t \n" # define BLANKS2 " \n" reader.addSource("
", BLANKS1 BLANKS2); source.addReader(&reader); - RplLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, + ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_DECIMAL, - RplLexer::SF_TICK, RplLexer::STORE_ALL); + ReLexer::NUMTYPE_DECIMAL, + ReLexer::SF_TICK, ReLexer::STORE_ALL); checkToken(lex.nextToken(), TOKEN_SPACE, 0, BLANKS1); checkToken(lex.nextToken(), TOKEN_SPACE, 0, BLANKS2); } void testNumeric(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); const char* blanks = "321 0x73 7.8e+5"; reader.addSource("
", blanks); source.addReader(&reader); - RplLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, + ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_ALL, - RplLexer::SF_TICK, RplLexer::STORE_ALL); - RplToken* token = checkToken(lex.nextToken(), TOKEN_NUMBER); - checkE(321, token->asInteger()); + ReLexer::NUMTYPE_ALL, + ReLexer::SF_TICK, ReLexer::STORE_ALL); + ReToken* token = checkToken(lex.nextToken(), TOKEN_NUMBER); + checkEqu(321, token->asInteger()); token = checkToken(lex.nextNonSpaceToken(), TOKEN_NUMBER); - checkE(0x73, token->asInteger()); + checkEqu(0x73, token->asInteger()); token = checkToken(lex.nextNonSpaceToken(), TOKEN_REAL); - checkE(7.8e+5, token->asReal()); + checkEqu(7.8e+5, token->asReal()); } void testOperators(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); const char* ops = "<< < <<< <= == = ( ) [ ]"; reader.addSource("
", ops); source.addReader(&reader); enum { UNDEF, SHIFT, LT, SHIFT2, LE, EQ, ASSIGN, LPARENT, RPARENT, LBRACKET, RBRACKET }; - RplLexer lex(&source, KEYWORDS, ops, "=", COMMENTS, + ReLexer lex(&source, KEYWORDS, ops, "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_ALL, - RplLexer::SF_TICK, RplLexer::STORE_ALL); + ReLexer::NUMTYPE_ALL, + ReLexer::SF_TICK, ReLexer::STORE_ALL); checkToken(lex.nextNonSpaceToken(), TOKEN_OPERATOR, SHIFT); checkToken(lex.nextNonSpaceToken(), TOKEN_OPERATOR, LT); checkToken(lex.nextNonSpaceToken(), TOKEN_OPERATOR, SHIFT2); @@ -138,19 +138,19 @@ public: } void testComments(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); reader.addSource("
", "/**/9//\n8/***/7// wow\n/*\n*\n*\n**/"); source.addReader(&reader); enum { COMMENT_UNDEF, COMMENT_MULTILINE, COMMENT_1 }; - RplLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, + ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_ALL, - RplLexer::SF_LIKE_C, RplLexer::STORE_ALL); + ReLexer::NUMTYPE_ALL, + ReLexer::SF_LIKE_C, ReLexer::STORE_ALL); checkToken(lex.nextToken(), TOKEN_COMMENT_START, COMMENT_MULTILINE, "/**/"); checkToken(lex.nextToken(), TOKEN_NUMBER); @@ -166,32 +166,32 @@ public: "/*\n*\n*\n**/"); } void testStrings(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); reader.addSource("
", "\"abc\\t\\r\\n\\a\\v\"'1\\x9Z\\x21A\\X9'"); source.addReader(&reader); - RplLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, + ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_ALL, - RplLexer::SF_LIKE_C, RplLexer::STORE_ALL); + ReLexer::NUMTYPE_ALL, + ReLexer::SF_LIKE_C, ReLexer::STORE_ALL); checkToken(lex.nextToken(), TOKEN_STRING, '"', "abc\t\r\n\a\v"); checkToken(lex.nextToken(), TOKEN_STRING, '\'', "1\tZ!A\t"); } void testKeywords(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); reader.addSource("
", "if\n\tthen else\nfi"); source.addReader(&reader); - RplLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, + ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_ALL, - RplLexer::SF_LIKE_C, RplLexer::STORE_ALL); + ReLexer::NUMTYPE_ALL, + ReLexer::SF_LIKE_C, ReLexer::STORE_ALL); checkToken(lex.nextToken(), TOKEN_KEYWORD, KEY_IF); checkToken(lex.nextNonSpaceToken(), TOKEN_KEYWORD, KEY_THEN); checkToken(lex.nextNonSpaceToken(), TOKEN_KEYWORD, KEY_ELSE); @@ -200,18 +200,18 @@ public: } void testIds(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); reader.addSource("
", "i\n\tifs\n" "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); source.addReader(&reader); - RplLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, + ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_ALL, - RplLexer::SF_LIKE_C, RplLexer::STORE_ALL); + ReLexer::NUMTYPE_ALL, + ReLexer::SF_LIKE_C, ReLexer::STORE_ALL); checkToken(lex.nextToken(), TOKEN_ID, 0, "i"); checkToken(lex.nextNonSpaceToken(), TOKEN_ID, 0, "ifs"); @@ -220,45 +220,45 @@ public: } void testBasic(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); source.addReader(&reader); reader.addSource("
", "if i>1 then i=1+2*_x9 fi"); - RplLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, + ReLexer lex(&source, KEYWORDS, OPERATORS, "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_ALL, - RplLexer::SF_LIKE_C, RplLexer::STORE_ALL); - RplToken* token; + ReLexer::NUMTYPE_ALL, + ReLexer::SF_LIKE_C, ReLexer::STORE_ALL); + ReToken* token; checkToken(lex.nextToken(), TOKEN_KEYWORD, KEY_IF); checkToken(lex.nextToken(), TOKEN_SPACE, 0); checkToken(lex.nextToken(), TOKEN_ID, 0, "i"); checkToken(lex.nextToken(), TOKEN_OPERATOR, OP_GT); token = checkToken(lex.nextToken(), TOKEN_NUMBER); - checkE(1, token->asInteger()); + checkEqu(1, token->asInteger()); checkToken(lex.nextToken(), TOKEN_SPACE, 0); checkToken(lex.nextToken(), TOKEN_KEYWORD, KEY_THEN); checkToken(lex.nextToken(), TOKEN_SPACE, 0); } void testPrio(){ - RplSource source; - RplStringReader reader(source); + ReSource source; + ReStringReader reader(source); source.addReader(&reader); reader.addSource("x", ""); enum { O_UNDEF, O_ASSIGN, O_PLUS, O_MINUS, O_TIMES, O_DIV }; - RplLexer lex(&source, KEYWORDS, + ReLexer lex(&source, KEYWORDS, "=\n+ -\n* /", "=", COMMENTS, "A-Za-z_", "A-Za-z0-9_", - RplLexer::NUMTYPE_ALL, - RplLexer::SF_LIKE_C, RplLexer::STORE_ALL); + ReLexer::NUMTYPE_ALL, + ReLexer::SF_LIKE_C, ReLexer::STORE_ALL); checkT(lex.prioOfOp(O_ASSIGN) < lex.prioOfOp(O_PLUS)); - checkE(lex.prioOfOp(O_PLUS), lex.prioOfOp(O_MINUS)); + checkEqu(lex.prioOfOp(O_PLUS), lex.prioOfOp(O_MINUS)); checkT(lex.prioOfOp(O_MINUS) < lex.prioOfOp(O_TIMES)); - checkE(lex.prioOfOp(O_TIMES), lex.prioOfOp(O_DIV)); + checkEqu(lex.prioOfOp(O_TIMES), lex.prioOfOp(O_DIV)); } virtual void doIt(void) { diff --git a/unittests/rplmatrix_test.cpp b/cunit/rplmatrix_test.cpp similarity index 71% rename from unittests/rplmatrix_test.cpp rename to cunit/rplmatrix_test.cpp index b9a651d..d1507e4 100644 --- a/unittests/rplmatrix_test.cpp +++ b/cunit/rplmatrix_test.cpp @@ -9,13 +9,13 @@ * @brief Unit test of the matrices. */ -#include "rplcore/rplcore.hpp" +#include "base/rebase.hpp" #include "rplmath/rplmath.hpp" #include "rplcore/rpltest.hpp" -class TestRplMatrix : public RplTest{ +class TestRplMatrix : public ReTest{ public: - TestRplMatrix() : RplTest("RplMatrix") {} + TestRplMatrix() : ReTest("RplMatrix") {} public: void fillMatrix(RplMatrix& mx, MatVal offset = 0){ @@ -29,11 +29,11 @@ public: int count = 0; for(int row = 0; row < mx.getRows(); row++){ for (int col = 0; col < mx.getCols(); col++){ - checkE(100.0*row + col + offset, mx.get(row, col)); + checkEqu(100.0*row + col + offset, mx.get(row, col)); count++; } } - checkE(mx.getCols()*mx.getRows(), count); + checkEqu(mx.getCols()*mx.getRows(), count); } void fillConst(RplMatrix& mx, MatVal value){ for(int row = 0; row < mx.getRows(); row++){ @@ -46,52 +46,52 @@ public: int count = 0; for(int row = 0; row < mx.getRows(); row++){ for (int col = 0; col < mx.getCols(); col++){ - checkE(value, mx.get(row, col)); + checkEqu(value, mx.get(row, col)); count++; } } - checkE(mx.getCols()*mx.getRows(), count); + checkEqu(mx.getCols()*mx.getRows(), count); } void testBasic() { Tuple2 tuple(-2.0, 0.5); - checkE(-2.0, tuple.m_value1); - checkE(0.5, tuple.m_value2); + checkEqu(-2.0, tuple.m_value1); + checkEqu(0.5, tuple.m_value2); RplMatrix mat("mx"); try{ throw RplMatrixException(mat, "String: %s and int %d", "Hi", -333); checkF(true); } catch (RplMatrixException exc){ - checkE("mx: String: Hi and int -333", exc.getMessage()); + checkEqu("mx: String: Hi and int -333", exc.getMessage()); } RplMatrix mat2; try{ throw RplMatrixException(mat2, "String: %s and int %d", "Hi", -333); checkF(true); } catch (RplMatrixException exc){ - checkE("String: Hi and int -333", exc.getMessage()); + checkEqu("String: Hi and int -333", exc.getMessage()); } - checkE("mx", mat.getName()); - checkE("", mat2.getName()); + checkEqu("mx", mat.getName()); + checkEqu("", mat2.getName()); RplMatrix m2x3(2, 3, "m2x3"); - checkE("m2x3", m2x3.getName()); - checkE(2, m2x3.getRows()); - checkE(3, m2x3.getCols()); + checkEqu("m2x3", m2x3.getName()); + checkEqu(2, m2x3.getRows()); + checkEqu(3, m2x3.getCols()); fillMatrix(m2x3); checkMatrix(m2x3); RplMatrix mxCopy(m2x3); - checkE("m2x3-copy", mxCopy.getName()); - checkE(2, mxCopy.getRows()); - checkE(3, mxCopy.getCols()); + checkEqu("m2x3-copy", mxCopy.getName()); + checkEqu(2, mxCopy.getRows()); + checkEqu(3, mxCopy.getCols()); checkMatrix(mxCopy); RplMatrix mxCopy2("mxCopy2"); mxCopy2 = m2x3; - checkE("mxCopy2", mxCopy2.getName()); - checkE(2, mxCopy2.getRows()); - checkE(3, mxCopy2.getCols()); + checkEqu("mxCopy2", mxCopy2.getName()); + checkEqu(2, mxCopy2.getRows()); + checkEqu(3, mxCopy2.getCols()); checkMatrix(mxCopy2); } void testAddOperators(){ @@ -168,13 +168,13 @@ public: m1.checkDefinition(-1, 1); checkT(false); } catch(RplMatrixException exc){ - checkE("m1: row number negative: -1", exc.getMessage()); + checkEqu("m1: row number negative: -1", exc.getMessage()); } try { m1.checkDefinition(1, -1); checkT(false); } catch(RplMatrixException exc){ - checkE("m1: column number negative: -1", exc.getMessage()); + checkEqu("m1: column number negative: -1", exc.getMessage()); } } @@ -189,25 +189,25 @@ public: m1.check(-1, 1); checkT(false); } catch(RplMatrixException exc){ - checkE("m1: invalid row: -1 not in [0,3[", exc.getMessage()); + checkEqu("m1: invalid row: -1 not in [0,3[", exc.getMessage()); } try { m1.check(3, 1); checkT(false); } catch(RplMatrixException exc){ - checkE("m1: invalid row: 3 not in [0,3[", exc.getMessage()); + checkEqu("m1: invalid row: 3 not in [0,3[", exc.getMessage()); } try { m1.check(1, -1); checkT(false); } catch(RplMatrixException exc){ - checkE("m1: invalid column: -1 not in [0,2[", exc.getMessage()); + checkEqu("m1: invalid column: -1 not in [0,2[", exc.getMessage()); } try { m1.check(1, 2); checkT(false); } catch(RplMatrixException exc){ - checkE("m1: invalid column: 2 not in [0,2[", exc.getMessage()); + checkEqu("m1: invalid column: 2 not in [0,2[", exc.getMessage()); } } void testCheckSameDimension(){ @@ -221,14 +221,14 @@ public: m1.checkSameDimension(m2); checkT(false); } catch(RplMatrixException exc){ - checkE("m1: m2 has a different row count: 3 / 2", exc.getMessage()); + checkEqu("m1: m2 has a different row count: 3 / 2", exc.getMessage()); } m2.resize(3, 3); try { m1.checkSameDimension(m2); checkT(false); } catch(RplMatrixException exc){ - checkE("m1: m2 has a different column count: 2 / 3", exc.getMessage()); + checkEqu("m1: m2 has a different column count: 2 / 3", exc.getMessage()); } } void testResize(){ @@ -240,8 +240,8 @@ public: checkConst(m2, 0); m1.resize(2, 4); - checkE(2, m1.getRows()); - checkE(4, m1.getCols()); + checkEqu(2, m1.getRows()); + checkEqu(4, m1.getCols()); checkT(m1 == m2); } @@ -252,16 +252,16 @@ public: m1.set(0, 0, -98); m1.set(3, 4, 9999); Tuple2 miniMax = m1.minMax(); - checkE(-98.0, miniMax.m_value1); - checkE(9999.0, miniMax.m_value2); + checkEqu(-98.0, miniMax.m_value1); + checkEqu(9999.0, miniMax.m_value2); fillMatrix(m1); checkMatrix(m1); m1.set(1, 1, 7777); m1.set(3, 4, -987); miniMax = m1.minMax(); - checkE(-987.0, miniMax.m_value1); - checkE(7777.0, miniMax.m_value2); + checkEqu(-987.0, miniMax.m_value1); + checkEqu(7777.0, miniMax.m_value2); } void testTranspose() @@ -270,43 +270,43 @@ public: fillMatrix(m1); RplMatrix m2(m1.transpose()); - checkE(5, m2.getRows()); - checkE(1, m2.getCols()); + checkEqu(5, m2.getRows()); + checkEqu(1, m2.getCols()); int row, col; col = 0; for (row = 0; row < 5; row++){ - checkE(qreal(col*100+row), m2.get(row, 0)); + checkEqu(qreal(col*100+row), m2.get(row, 0)); } m1.resize(35, 73); fillMatrix(m1); m2 = m1.transpose(); - checkE(73, m2.getRows()); - checkE(35, m2.getCols()); + checkEqu(73, m2.getRows()); + checkEqu(35, m2.getCols()); int count = 0; for (row = 0; row < m2.getRows(); row++){ for (col = 0; col < m2.getCols(); col++){ - checkE(qreal(col*100+row), m2.get(row, col)); + checkEqu(qreal(col*100+row), m2.get(row, col)); count++; } } - checkE(73*35, count); + checkEqu(73*35, count); } void testToString(){ RplMatrix m1(1, 1, "m1"); m1.set(0, 0, 2.34); - checkE("[2.340000,\n]", m1.toString().constData()); - checkE("jonny[2.34000 |]", m1.toString("jonny", "%.5f", "|", " ").constData()); + checkEqu("[2.340000,\n]", m1.toString().constData()); + checkEqu("jonny[2.34000 |]", m1.toString("jonny", "%.5f", "|", " ").constData()); m1.resize(2, 1); m1.set(0, 0, 2.34); m1.set(1, 0, 55.5); - checkE("[2.340000,\n55.500000,\n]", m1.toString().constData()); - checkE("jonny[2.34000 |55.50000 |]", m1.toString("jonny", "%.5f", "|", " ").constData()); + checkEqu("[2.340000,\n55.500000,\n]", m1.toString().constData()); + checkEqu("jonny[2.34000 |55.50000 |]", m1.toString("jonny", "%.5f", "|", " ").constData()); log(""); } void testReadCsv(){ @@ -320,29 +320,29 @@ public: "element2,7,-22.3,44\n" "\n" "2 Elements, 3, Ports"; - RplString::write(fn, content); + ReStringUtil::write(fn, content); m1.readFromCvs(fn, 256); - checkE(2, m1.getRows()); - checkE(3, m1.getCols()); + checkEqu(2, m1.getRows()); + checkEqu(3, m1.getCols()); - checkE(5.0, m1.get(0, 0)); - checkE(-3.0E-99, m1.get(0, 1)); - checkE(0.5, m1.get(0, 2)); + checkEqu(5.0, m1.get(0, 0)); + checkEqu(-3.0E-99, m1.get(0, 1)); + checkEqu(0.5, m1.get(0, 2)); - checkE(7.0, m1.get(1, 0)); - checkE(-22.3, m1.get(1, 1)); - checkE(44.0, m1.get(1, 2)); + checkEqu(7.0, m1.get(1, 0)); + checkEqu(-22.3, m1.get(1, 1)); + checkEqu(44.0, m1.get(1, 2)); fillMatrix(m1); content = "Port0,Port1,Port2\n" "5, -3E-99 , 0.5\n"; - RplString::write(fn, content); + ReStringUtil::write(fn, content); m1.readFromCvs(fn, 256); - checkE(1, m1.getRows()); - checkE(3, m1.getCols()); - checkE(5.0, m1.get(0, 0)); - checkE(-3.0E-99, m1.get(0, 1)); - checkE(0.5, m1.get(0, 2)); + checkEqu(1, m1.getRows()); + checkEqu(3, m1.getCols()); + checkEqu(5.0, m1.get(0, 0)); + checkEqu(-3.0E-99, m1.get(0, 1)); + checkEqu(0.5, m1.get(0, 2)); /* diff --git a/unittests/rplmfparser_test.cpp b/cunit/rplmfparser_test.cpp similarity index 82% rename from unittests/rplmfparser_test.cpp rename to cunit/rplmfparser_test.cpp index 6266a48..6cb4ede 100644 --- a/unittests/rplmfparser_test.cpp +++ b/cunit/rplmfparser_test.cpp @@ -9,20 +9,20 @@ * @brief Unit test of the parser for the language "MF". */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" #include "rplcore/rpltest.hpp" -class TestRplMFParser : public RplTest{ +class TestRplMFParser : public ReTest{ private: - RplSource m_source; - RplASTree m_tree; - RplStringReader m_reader; - RplFileReader m_fileReader; + ReSource m_source; + ReASTree m_tree; + ReStringReader m_reader; + ReFileReader m_fileReader; QByteArray m_currentSource; public: TestRplMFParser() : - RplTest("RplMFParser"), + ReTest("ReMFParser"), m_source(), m_tree(), m_reader(m_source), @@ -32,7 +32,7 @@ public: } protected: void setSource(const char* content){ - RplASItem::reset(); + ReASItem::reset(); m_currentSource = content; m_tree.clear(); m_source.clear(); @@ -42,8 +42,8 @@ protected: m_source.addSourceUnit(m_reader.currentSourceUnit()); } void setFileSource(const char* filename){ - RplASItem::reset(); - m_currentSource = RplString::read(filename); + ReASItem::reset(); + m_currentSource = ReStringUtil::read(filename); m_tree.clear(); m_source.clear(); m_fileReader.clear(); @@ -60,7 +60,7 @@ private: fnExpected += (char) QDir::separator().toLatin1(); fnExpected += fileExpected; QByteArray fnCurrent = getTempFile(fileExpected, "rplmfparser"); - m_tree.dump(fnCurrent, RplASTree::DMP_NO_GLOBALS, m_currentSource); + m_tree.dump(fnCurrent, ReASTree::DMP_NO_GLOBALS, m_currentSource); assertEqualFiles(fnExpected.constData(), fnCurrent.constData(), __FILE__, lineNo); } @@ -68,21 +68,21 @@ private: public: void fileClassTest(){ setFileSource("test/rplmfparser/string1.mf"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("string1.txt", __LINE__); } void baseTest(){ setSource("2+3*4"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("baseTest.txt", __LINE__); } void varDefTest(){ setSource("const lazy Str s = 'Hi';\nconst List l;\nInt i = 3;"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("varDefTest.txt", __LINE__); } @@ -90,7 +90,7 @@ public: void ifTest(){ setSource("Int a;\nInt b;\na = b = 2;\nif 11 < 12\nthen a = 13 * 14\nelse a = 15 / 16\nfi"); // setSource("Int a; if 11 < 12 then a = 13 * 14 else a = 15 / 16 fi"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("ifTest1.txt", __LINE__); setSource("Str x;\nif 7 < 6\nthen x = '123';\nfi"); @@ -99,20 +99,20 @@ public: } void whileTest(){ setSource("Int a = 20;\nwhile 3 < 5 do\n a = 7\nod"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("whileTest.txt", __LINE__); } void repeatTest(){ setSource("Int a;\nrepeat\na++;\nuntil a != 2 * 3;"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("repeatTest.txt", __LINE__); } void forCTest(){ setSource("Int a;\nfor b from 10 to 1 step -2 do\na += 1;\nod"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("forC1.txt", __LINE__); setSource("Int a; for to 10 do a += 1 od"); @@ -120,23 +120,23 @@ public: checkAST("forC2.txt", __LINE__); } void opTest(){ - checkE(25, RplMFParser::O_QUESTION); - checkE(37, RplMFParser::O_RSHIFT2); - checkE(41, RplMFParser::O_DEC); - checkE(48, RplMFParser::O_RBRACE); + checkEqu(25, ReMFParser::O_QUESTION); + checkEqu(37, ReMFParser::O_RSHIFT2); + checkEqu(41, ReMFParser::O_DEC); + checkEqu(48, ReMFParser::O_RBRACE); setSource("Int a = 1;\nInt b = 100;\n--a;\nb++;\na--*++b**(8-3);\na=b=(a+(b-2)*3)"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("opTest1.txt", __LINE__); } void forItTest(){ setSource("Map a;\nfor x in a do\na += 1;\nod"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("forIt1.txt", __LINE__); } void listTest(){ - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); setSource("List b = [];"); parser.parse(); checkAST("list1.txt", __LINE__); @@ -146,7 +146,7 @@ public: } void mapTest(){ setSource("Map a = {};"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("map1.txt", __LINE__); setSource("Map a = {'a': 2+3,'bcd':3.14,'ccc':7, 'hi':'world'};\nMap b = {};"); @@ -156,20 +156,20 @@ public: void methodCallTest(){ //setSource("max(4,3.14);"); setSource("rand();\nsin(a);\nmax(1+2*3,4**(5-4));"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("methc1.txt", __LINE__); } void fieldTest(){ setSource("file.find('*.c')[0].name;\n[1,2,3].join(' ');\n3.14.trunc;"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("field1.txt", __LINE__); } void methodTest(){ setSource("func Float pi: 3.1415; endf func Str delim(): '/' endf;"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("meth1.txt", __LINE__); setSource("func Int fac(const Int n):\n" @@ -196,7 +196,7 @@ public: } void mainTest(){ setSource("Int a=2+3*4;\nfunc Void main():\na;\nendf"); - RplMFParser parser(m_source, m_tree); + ReMFParser parser(m_source, m_tree); parser.parse(); checkAST("main1.txt", __LINE__); } diff --git a/cunit/rplqstring_test.cpp b/cunit/rplqstring_test.cpp new file mode 100644 index 0000000..8f9db55 --- /dev/null +++ b/cunit/rplqstring_test.cpp @@ -0,0 +1,125 @@ +/* + * 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. +*/ +/** @file + * @brief Unit test of the ReString tools. + */ + +#include "base/rebase.hpp" +#include "rplcore/rpltest.hpp" + +class TestRplQString : public ReTest { +public: + TestRplQString() : + ReTest("ReQString") + {} + +public: + void testLengthOfUInt64(){ + quint64 value = -3; + checkEqu(1, ReQString::lengthOfUInt64(ReString("0"), 0, 10, &value)); + checkEqu(0LL, value); + checkEqu(3, ReQString::lengthOfUInt64("x432", 1, 10, &value)); + checkEqu(432LL, value); + checkEqu(3, ReQString::lengthOfUInt64("x432 x", 1, 10, &value)); + checkEqu(432LL, value); + checkEqu(3, ReQString::lengthOfUInt64("x432fabc x", 1, 10, &value)); + checkEqu(432LL, value); + checkEqu(16, ReQString::lengthOfUInt64("a1234567890123567", 1, 10, &value)); + checkEqu(1234567890123567LL, value); + checkEqu(10, ReQString::lengthOfUInt64("x1234abcdef", 1, 16, &value)); + checkEqu(0x1234abcdefLL, value); + checkEqu(3, ReQString::lengthOfUInt64("432", 0, 8, &value)); + checkEqu(0432LL, value); + checkEqu(6, ReQString::lengthOfUInt64(" 765432 ", 1, 8, &value)); + checkEqu(0765432LL, value); + + checkEqu(0, ReQString::lengthOfUInt64("1 ", 1, 8, &value)); + checkEqu(0, ReQString::lengthOfUInt64("", 1, 8, &value)); + } + void testLengthOfUInt(){ + uint value = 3; + checkEqu(1, ReQString::lengthOfUInt(ReString("0"), 0, 10, &value)); + checkEqu(0, value); + checkEqu(3, ReQString::lengthOfUInt("x432", 1, 10, &value)); + checkEqu(432, value); + checkEqu(3, ReQString::lengthOfUInt("x432 x", 1, 10, &value)); + checkEqu(432, value); + checkEqu(3, ReQString::lengthOfUInt("x432fabc x", 1, 10, &value)); + checkEqu(432, value); + checkEqu(3, ReQString::lengthOfUInt("432", 0, 8, &value)); + checkEqu(0432, value); + checkEqu(6, ReQString::lengthOfUInt(" 765432 ", 1, 8, &value)); + checkEqu(0765432, value); + + checkEqu(0, ReQString::lengthOfUInt("1 ", 1, 8, &value)); + checkEqu(0, ReQString::lengthOfUInt("", 1, 8, &value)); + } + void testLengthOfReal(){ + qreal value; + checkEqu(4, ReQString::lengthOfReal(ReString("0.25"), 0, &value)); + checkEqu(0.25, value); + checkEqu(3, ReQString::lengthOfReal(ReString("X.25"), 1, &value)); + checkEqu(0.25, value); + checkEqu(1, ReQString::lengthOfReal(ReString(" 0"), 1, &value)); + checkEqu(0.0, value); + checkEqu(17, ReQString::lengthOfReal(ReString("X12345678901234567"), 1, &value)); + checkEqu(12345678901234567.0, value); + checkEqu(2, ReQString::lengthOfReal(ReString(".5"), 0, &value)); + checkEqu(0.5, value); + checkEqu(5, ReQString::lengthOfReal(ReString("2.5e2x"), 0, &value)); + checkEqu(250.0, value); + checkEqu(6, ReQString::lengthOfReal(ReString("2.5e+2"), 0, &value)); + checkEqu(250.0, value); + checkEqu(7, ReQString::lengthOfReal(ReString("2.5E-33"), 0, &value)); + checkEqu(2.5e-33, value); + + checkEqu(3, ReQString::lengthOfReal(ReString("2.5E"), 0, &value)); + checkEqu(2.5, value); + checkEqu(3, ReQString::lengthOfReal(ReString("2.5E+"), 0, &value)); + checkEqu(2.5, value); + checkEqu(3, ReQString::lengthOfReal(ReString("2.5E-a"), 0, &value)); + checkEqu(2.5, value); + } + + void testValueOfHexDigit(){ + checkEqu(0, ReQString::valueOfHexDigit('0')); + checkEqu(9, ReQString::valueOfHexDigit('9')); + checkEqu(10, ReQString::valueOfHexDigit('a')); + checkEqu(15, ReQString::valueOfHexDigit('f')); + checkEqu(10, ReQString::valueOfHexDigit('A')); + checkEqu(15, ReQString::valueOfHexDigit('F')); + + checkEqu(-1, ReQString::valueOfHexDigit('0' - 1)); + checkEqu(-1, ReQString::valueOfHexDigit('9' + 1)); + checkEqu(-1, ReQString::valueOfHexDigit('A' - 1)); + checkEqu(-1, ReQString::valueOfHexDigit('F' + 1)); + checkEqu(-1, ReQString::valueOfHexDigit('a' - 1)); + checkEqu(-1, ReQString::valueOfHexDigit('f' + 1)); + } + void testUtf8(){ + ReString name = "Heinz Müller"; + char buffer[32]; + checkEqu("Heinz Müller", ReQString::utf8(name, buffer, sizeof buffer)); + memset(buffer, 'x', sizeof buffer); + checkEqu("Heinz", ReQString::utf8(name, buffer, (size_t) (5+1))); + checkEqu(buffer[6], 'x'); + } + + virtual void doIt(void) { + testUtf8(); + testLengthOfUInt64(); + testLengthOfUInt(); + testLengthOfReal(); + testValueOfHexDigit(); + } +}; +void testRplQString() { + TestRplQString test; + test.run(); +} + diff --git a/unittests/rplsource_test.cpp b/cunit/rplsource_test.cpp similarity index 68% rename from unittests/rplsource_test.cpp rename to cunit/rplsource_test.cpp index 49eeeae..e78a9c3 100644 --- a/unittests/rplsource_test.cpp +++ b/cunit/rplsource_test.cpp @@ -10,19 +10,19 @@ * @brief Unit test of the input media reader. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" #include "rplcore/rpltest.hpp" -class TestRplSource : public RplTest{ +class TestReSource : public ReTest{ public: - TestRplSource() : RplTest("TestRplSource") {} + TestReSource() : ReTest("TestReSource") {} private: QByteArray m_content1_1; QByteArray m_content1_2; QByteArray m_content2; - RplSource m_source; + ReSource m_source; protected: void init(){ @@ -31,15 +31,15 @@ protected: m_content2 = "x=2"; } - void testRplStringSourceUnit(){ - RplStringReader reader(m_source); + void testReStringSourceUnit(){ + ReStringReader reader(m_source); QByteArray content("a=1;\nveeeeeeeeery looooooooooooooong\n"); - RplStringSourceUnit unit("test", content, &reader); + ReStringSourceUnit unit("test", content, &reader); unit.setLineNo(144); - checkE(144, unit.lineNo()); - checkE("test", unit.name()); + checkEqu(144, unit.lineNo()); + checkEqu("test", unit.name()); } - void checkOne(int maxSize, RplReader& reader){ + void checkOne(int maxSize, ReReader& reader){ QByteArray total; QByteArray buffer; int lineNo = 0; @@ -57,7 +57,7 @@ protected: bool isImport = total.endsWith("source2\n"); if (isImport){ reader.openSourceUnit("source2"); - checkE("source2", reader.currentSourceUnit()->name()); + checkEqu("source2", reader.currentSourceUnit()->name()); while(reader.nextLine(maxSize, buffer, hasMore)){ lineNo++; while(hasMore && reader.fillBuffer(maxSize, buffer, hasMore)){ @@ -65,22 +65,22 @@ protected: buffer.clear(); } } - checkE("source1", reader.currentSourceUnit()->name()); + checkEqu("source1", reader.currentSourceUnit()->name()); } } - checkE(5, lineNo); - checkE(m_content1_1 + m_content2 + m_content1_2, total); + checkEqu(5, lineNo); + checkEqu(m_content1_1 + m_content2 + m_content1_2, total); } - void testRplStringReader(){ - RplStringReader reader(m_source); + void testReStringReader(){ + ReStringReader reader(m_source); reader.addSource("source1", m_content1_1 + m_content1_2); reader.addSource("source2", m_content2); - RplSourceUnit* unit = reader.openSourceUnit("source1"); + ReSourceUnit* unit = reader.openSourceUnit("source1"); checkNN(unit); - checkE("source1", unit->name()); - checkE(0, unit->lineNo()); + checkEqu("source1", unit->name()); + checkEqu(0, unit->lineNo()); checkOne(6, reader); checkOne(100, reader); reader.replaceSource("source2", "content2"); @@ -89,19 +89,19 @@ protected: QByteArray buffer; bool hasMore; checkT(reader.nextLine(50, buffer, hasMore)); - checkE("content2", buffer); + checkEqu("content2", buffer); checkF(hasMore); } public: virtual void doIt(void) { init(); - testRplStringSourceUnit(); - testRplStringReader(); + testReStringSourceUnit(); + testReStringReader(); } }; -void testRplSource() { - TestRplSource test; +void testReSource() { + TestReSource test; test.run(); } diff --git a/cunit/rplstring_test.cpp b/cunit/rplstring_test.cpp new file mode 100644 index 0000000..313ae58 --- /dev/null +++ b/cunit/rplstring_test.cpp @@ -0,0 +1,196 @@ +/* + * 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. +*/ + +/** @file + * @brief Unit test of the QByteArray tools. + */ +#include "base/rebase.hpp" +#include "rplcore/rpltest.hpp" +/** + * @brief Unit test for ReStringUtil. + */ +class TestReString : public ReTest { +public: + TestReString() : ReTest("ReStringUtil") {} + +public: + void testCountChar(){ + checkEqu(1, ReStringUtil::countChar("x", 'x')); + checkEqu(0, ReStringUtil::countChar("X", 'x')); + checkEqu(2, ReStringUtil::countChar("xbxxbxx", 'b')); + } + + void testCount() { + checkEqu(0, ReStringUtil::count("abc", " ")); + checkEqu(1, ReStringUtil::count("abc", "b")); + checkEqu(2, ReStringUtil::count("axx", "x")); + + checkEqu(0, ReStringUtil::count("abbc", "bbb")); + checkEqu(1, ReStringUtil::count("\n\n", "\n\n")); + checkEqu(2, ReStringUtil::count(" a ", " ")); + } + + void testCutString() { + QByteArray source("123"); + QByteArray buffer; + checkEqu(QByteArray("123"), ReStringUtil::cutString(source, 4, buffer)); + checkEqu(QByteArray("123"), ReStringUtil::cutString(source, 3, buffer)); + checkEqu(QByteArray("12..."), ReStringUtil::cutString(source, 2, buffer)); + checkEqu(QByteArray("12"), ReStringUtil::cutString(source, 2, buffer, "")); + } + + void testHexDump() { + QByteArray data("abc123\nxyz"); + checkEqu(QByteArray("61 62 63 31 abc1\n" + "32 33 0a 78 23.x\n" + "79 7a yz\n"), + ReStringUtil::hexDump((uint8_t*) data.constData(), data.length(), 4)); + checkEqu(QByteArray("61 62 63 31 32 33 0a 78 79 7a abc123.xyz"), + ReStringUtil::hexDump((uint8_t*) data.constData(), data.length(), 10)); + checkEqu(QByteArray("61 62 63 31 32 33 0a 78 79 7a abc123.xyz"), + ReStringUtil::hexDump((uint8_t*) data.constData(), data.length(), 12)); + } + + void testReadWrite() { + QByteArray fn = getTempFile("test.dat"); + const char* content = "Hello world\nLine2\n"; + checkT(ReStringUtil::write(fn, content)); + checkEqu(content, ReStringUtil::read(fn, false)); + checkEqu(content, ReStringUtil::read(fn, true) + "\n"); + } + + void testToArray() { + QList array = ReStringUtil::toArray("1 abc 3", " "); + checkEqu(3, array.size()); + checkEqu("1", array.at(0)); + checkEqu("abc", array.at(1)); + checkEqu("3", array.at(2)); + } + + void testToNumber() { + checkEqu("3", ReStringUtil::toNumber(3)); + checkEqu("-33", ReStringUtil::toNumber(-33)); + checkEqu("003", ReStringUtil::toNumber(3, "%03d")); + } + + void testLengthOfNumber(){ + checkEqu(3, ReStringUtil::lengthOfNumber("0.3xxx")); + checkEqu(5, ReStringUtil::lengthOfNumber(" \t0.3xxx")); + checkEqu(3, ReStringUtil::lengthOfNumber("-.3xxx")); + checkEqu(2, ReStringUtil::lengthOfNumber(".3exxx")); + checkEqu(2, ReStringUtil::lengthOfNumber(".3e+xxx")); + checkEqu(16, ReStringUtil::lengthOfNumber("1234567.9012E+77")); + checkEqu(17, ReStringUtil::lengthOfNumber("-1234567.9012E+77 ")); + checkEqu(18, ReStringUtil::lengthOfNumber("-1234567.9012E+77 ", true)); + checkEqu(18, ReStringUtil::lengthOfNumber("-1234567.9012E+77 x", true)); + checkEqu(20, ReStringUtil::lengthOfNumber(" -1234567.9012E+77 x", true)); + } + + void checkCsv(const char* content, char expected){ + QByteArray fn = getTempFile("testrplstring.csv"); + ReStringUtil::write(fn, content); + FILE* fp = fopen(fn, "r"); + checkNN(fp); + char buffer[256]; + checkEqu(expected, ReStringUtil::findCsvSeparator(fp, buffer, sizeof buffer)); + fclose(fp); + } + + void testFindCsvSeparator(){ + const char* content = ",,,\t;;;||||"; + checkCsv(content, '\t'); + + content = "col1,col2\n1.5,3,5\n"; + checkCsv(content, ','); + + content = "col1;col2\n1,50;3.5\n" + "7;8\n10;12\n13;14"; + checkCsv(content, ';'); + + content = "0.3 7.8 8.9\n7.8 9.4 8.3"; + checkCsv(content, ' '); + + content = "0.3|7.8|8.9\n7.8| 9.4|8.3"; + checkCsv(content, '|'); + + content = "0,3;7.8;8.9"; + checkCsv(content, ';'); + } + void testLengthOfUInt64(){ + quint64 value = -3; + checkEqu(1, ReStringUtil::lengthOfUInt64("0", 10, &value)); + checkEqu(0LL, value); + checkEqu(3, ReStringUtil::lengthOfUInt64("432", 10, &value)); + checkEqu(432LL, value); + checkEqu(3, ReStringUtil::lengthOfUInt64("432 x", 10, &value)); + checkEqu(432LL, value); + checkEqu(3, ReStringUtil::lengthOfUInt64("432fabc x", 10, &value)); + checkEqu(432LL, value); + checkEqu(16, ReStringUtil::lengthOfUInt64("1234567890123567", 10, &value)); + checkEqu(1234567890123567LL, value); + checkEqu(10, ReStringUtil::lengthOfUInt64("1234abcdef", 16, &value)); + checkEqu(0x1234abcdefLL, value); + checkEqu(3, ReStringUtil::lengthOfUInt64("432", 8, &value)); + checkEqu(0432LL, value); + checkEqu(6, ReStringUtil::lengthOfUInt64("765432 ", 8, &value)); + checkEqu(0765432LL, value); + + checkEqu(0, ReStringUtil::lengthOfUInt64(" ", 8, &value)); + checkEqu(0, ReStringUtil::lengthOfUInt64("", 8, &value)); + } + void testLengthOfReal(){ + qreal value; + checkEqu(1, ReStringUtil::lengthOfReal("0", &value)); + checkEqu(0.0, value); + checkEqu(1, ReStringUtil::lengthOfReal("0%", &value)); + checkEqu(0.0, value); + checkEqu(4, ReStringUtil::lengthOfReal("0.25", &value)); + checkEqu(0.25, value); + checkEqu(3, ReStringUtil::lengthOfReal(".25", &value)); + checkEqu(0.25, value); + checkEqu(17, ReStringUtil::lengthOfReal("12345678901234567", &value)); + checkEqu(12345678901234567.0, value); + checkEqu(2, ReStringUtil::lengthOfReal(".5", &value)); + checkEqu(0.5, value); + checkEqu(5, ReStringUtil::lengthOfReal("2.5e2x", &value)); + checkEqu(250.0, value); + checkEqu(6, ReStringUtil::lengthOfReal("2.5e+2", &value)); + checkEqu(250.0, value); + checkEqu(7, ReStringUtil::lengthOfReal("2.5E-33", &value)); + checkEqu(2.5e-33, value); + + checkEqu(3, ReStringUtil::lengthOfReal("2.5E", &value)); + checkEqu(2.5, value); + checkEqu(3, ReStringUtil::lengthOfReal("2.5E+", &value)); + checkEqu(2.5, value); + checkEqu(3, ReStringUtil::lengthOfReal("2.5E-a", &value)); + checkEqu(2.5, value); + } + + virtual void doIt() { + testLengthOfReal(); + testLengthOfUInt64(); + testCountChar(); + testCount(); + testCutString(); + testToNumber(); + testToArray(); + testHexDump(); + testReadWrite(); + testLengthOfNumber(); + testFindCsvSeparator(); + } +}; + +void testReString() { + TestReString test; + test.run(); +} + + + diff --git a/unittests/rplvm_test.cpp b/cunit/rplvm_test.cpp similarity index 71% rename from unittests/rplvm_test.cpp rename to cunit/rplvm_test.cpp index 244058e..bb58cd2 100644 --- a/unittests/rplvm_test.cpp +++ b/cunit/rplvm_test.cpp @@ -6,19 +6,19 @@ * The original sources can be found on https://github.com/republib. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" #include "rplcore/rpltest.hpp" -class TestRplVM : public RplTest{ +class TestReVM : public ReTest{ private: - RplSource m_source; - RplASTree m_tree; - RplStringReader m_reader; + ReSource m_source; + ReASTree m_tree; + ReStringReader m_reader; const char* m_currentSource; public: - TestRplVM() : - RplTest("RplVM"), + TestReVM() : + ReTest("ReVM"), m_source(), m_tree(), m_reader(m_source) @@ -27,7 +27,7 @@ public: } protected: void setSource(const char* content){ - RplASItem::reset(); + ReASItem::reset(); m_currentSource = content; m_tree.clear(); m_source.clear(); @@ -41,15 +41,15 @@ private: void checkAST(const char* fileExpected, int lineNo){ QByteArray fnExpected = "test"; fnExpected += QDir::separator().toLatin1(); - fnExpected += "rplvm"; + fnExpected += "ReVM"; fnExpected += (char) QDir::separator().toLatin1(); fnExpected += fileExpected; - QByteArray fnCurrent = getTempFile(fileExpected, "rplvm"); - RplMFParser parser(m_source, m_tree); + QByteArray fnCurrent = getTempFile(fileExpected, "ReVM"); + ReMFParser parser(m_source, m_tree); parser.parse(); - RplVirtualMachine vm(m_tree, m_source); - vm.setFlag(RplVirtualMachine::VF_TRACE_STATEMENTS); - RplFileWriter writer(fnCurrent); + ReVirtualMachine vm(m_tree, m_source); + vm.setFlag(ReVirtualMachine::VF_TRACE_STATEMENTS); + ReFileWriter writer(fnCurrent); vm.setTraceWriter(&writer); writer.write(m_currentSource); vm.executeModule(""); @@ -65,8 +65,8 @@ public: baseTest(); } }; -void testRplVM() { - TestRplVM test; +void testReVM() { + TestReVM test; test.run(); } diff --git a/unittests/rplwriter_test.cpp b/cunit/rplwriter_test.cpp similarity index 72% rename from unittests/rplwriter_test.cpp rename to cunit/rplwriter_test.cpp index b348982..0922749 100644 --- a/unittests/rplwriter_test.cpp +++ b/cunit/rplwriter_test.cpp @@ -11,19 +11,19 @@ * @brief Unit test of the output media writers. */ -#include "rplcore/rplcore.hpp" +#include "base/rebase.hpp" #include "rplcore/rpltest.hpp" /** - * @brief Unit test for RplString. + * @brief Unit test for ReStringUtil. */ -class TestRplWriter : public RplTest { +class TestRplWriter : public ReTest { public: - TestRplWriter() : RplTest("RplWriter") {} + TestRplWriter() : ReTest("ReWriter") {} private: void testFileWriter(){ QByteArray fn = getTempFile("rplwriter.txt"); - RplFileWriter writer(fn); + ReFileWriter writer(fn); writer.writeLine("abc"); writer.formatLine("%04d", 42); writer.writeIndented(3, "123"); @@ -32,8 +32,8 @@ private: writer.format("%3c%.2f", ':', 3.1415); writer.writeLine(); writer.close(); - QByteArray current = RplString::read(fn, false); - checkE("abc\n0042\n\t\t\t123\n\t\tpi :3.14\n", current); + QByteArray current = ReStringUtil::read(fn, false); + checkEqu("abc\n0042\n\t\t\t123\n\t\tpi :3.14\n", current); } public: diff --git a/unittests/unittests.pro b/cunit/unittests.pro similarity index 100% rename from unittests/unittests.pro rename to cunit/unittests.pro diff --git a/rplexpr/rplastree.cpp b/expr/ReASTree.cpp similarity index 76% rename from rplexpr/rplastree.cpp rename to expr/ReASTree.cpp index de8e3e5..593a67a 100644 --- a/rplexpr/rplastree.cpp +++ b/expr/ReASTree.cpp @@ -16,11 +16,11 @@ * */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "../base/rebase.hpp" +#include "expr/reexpr.hpp" enum { - LOC_VARDEF_EXEC_1 = RPL_FIRST_OF(RPL_MODULE_ASTREE), // 11001 + LOC_VARDEF_EXEC_1 = LOC_FIRST_OF(LOC_ASTREE), // 11001 LOC_UNOP_CALC_1, LOC_UNARY_CHECK_1, LOC_UNARY_CHECK_2, @@ -59,7 +59,7 @@ enum { LOC_COUNT }; -unsigned int RplASItem::m_nextId = 1; +unsigned int ReASItem::m_nextId = 1; #define DEFINE_TABS(indent) \ char tabs[32]; \ @@ -75,11 +75,11 @@ unsigned int RplASItem::m_nextId = 1; * @param map map to dump * @param withEndOfLine true: '\n' will be written at the end */ -void dumpMap(RplWriter& writer, RplASMapOfVariants& map, bool withEndOfLine) +void dumpMap(ReWriter& writer, ReASMapOfVariants& map, bool withEndOfLine) { QList sorted; sorted.reserve(map.size()); - RplASMapOfVariants::iterator it; + ReASMapOfVariants::iterator it; for (it = map.begin(); it != map.end(); it++){ sorted.append(it.key()); } @@ -87,7 +87,7 @@ void dumpMap(RplWriter& writer, RplASMapOfVariants& map, bool withEndOfLine) QList::iterator it2; bool first = true; for (it2 = sorted.begin(); it2 != sorted.end(); it2++){ - RplASVariant* value = map[*it2]; + ReASVariant* value = map[*it2]; writer.format("%c'%s':%s", first ? '{' : ',', (*it2).constData(), value->toString().constData()); first = false; @@ -99,7 +99,7 @@ void dumpMap(RplWriter& writer, RplASMapOfVariants& map, bool withEndOfLine) writer.writeLine(); } -/** @class RplASException rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASException rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a specific exception for the Abstract Syntax Tree. */ @@ -111,7 +111,7 @@ void dumpMap(RplWriter& writer, RplASMapOfVariants& map, bool withEndOfLine) * @param format the reason of the exception * @param varList the values for the placeholders in the format. */ -void RplASException::build(const RplSourcePosition* position, +void ReASException::build(const ReSourcePosition* position, const char* format, va_list varList) { char buffer[64000]; @@ -130,9 +130,9 @@ void RplASException::build(const RplSourcePosition* position, * @param format the reason of the exception * @param ... the values for the placeholders in the format. */ -RplASException::RplASException(const RplSourcePosition* position, +ReASException::ReASException(const ReSourcePosition* position, const char* format, ...) : - RplException("") + ReException("") { va_list ap; va_start(ap, format); @@ -143,12 +143,12 @@ RplASException::RplASException(const RplSourcePosition* position, /** * @brief Constructor. */ -RplASException::RplASException() : - RplException("") +ReASException::ReASException() : + ReException("") { } -/** @class RplASVariant rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASVariant rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a class which can hold the value of any type. * @@ -158,7 +158,7 @@ RplASException::RplASException() : /** * @brief Constructor. */ -RplASVariant::RplASVariant() : +ReASVariant::ReASVariant() : m_variantType(VT_UNDEF), m_flags(VF_UNDEF), // m_value(), @@ -168,7 +168,7 @@ RplASVariant::RplASVariant() : /** * @brief Destructor. */ -RplASVariant::~RplASVariant() +ReASVariant::~ReASVariant() { destroyValue(); m_variantType = VT_UNDEF; @@ -178,7 +178,7 @@ RplASVariant::~RplASVariant() * @brief Copy constructor. * @param source the source to copy */ -RplASVariant::RplASVariant(const RplASVariant& source): +ReASVariant::ReASVariant(const ReASVariant& source): m_variantType(source.m_variantType), m_flags(source.m_flags), // m_value @@ -193,7 +193,7 @@ RplASVariant::RplASVariant(const RplASVariant& source): * @param source the source to copy * @return the instance itself */ -RplASVariant&RplASVariant::operator=(const RplASVariant& source) +ReASVariant&ReASVariant::operator=(const ReASVariant& source) { destroyValue(); m_variantType = source.m_variantType; @@ -207,7 +207,7 @@ RplASVariant&RplASVariant::operator=(const RplASVariant& source) * @brief Copies the value. * @param source the source to copy */ -void RplASVariant::copyValue(const RplASVariant& source) +void ReASVariant::copyValue(const ReASVariant& source) { destroyValue(); m_variantType = source.m_variantType; @@ -236,7 +236,7 @@ void RplASVariant::copyValue(const RplASVariant& source) /** * @brief Frees the resources of the instance. */ -void RplASVariant::destroyValue() +void ReASVariant::destroyValue() { switch(m_variantType) { @@ -258,7 +258,7 @@ void RplASVariant::destroyValue() * * @return the variant type */ -RplASVariant::VariantType RplASVariant::variantType() const +ReASVariant::VariantType ReASVariant::variantType() const { return m_variantType; } @@ -268,7 +268,7 @@ RplASVariant::VariantType RplASVariant::variantType() const * * @return the type as string */ -const char*RplASVariant::nameOfType() const +const char*ReASVariant::nameOfType() const { const char* rc = "?"; switch(m_variantType){ @@ -298,7 +298,7 @@ const char*RplASVariant::nameOfType() const * * @return the variant type */ -const RplASClass* RplASVariant::getClass() const +const ReASClass* ReASVariant::getClass() const { return m_class; } @@ -311,10 +311,10 @@ const RplASClass* RplASVariant::getClass() const * @throw RplException the instance is not a numberic value * */ -qreal RplASVariant::asFloat() const +qreal ReASVariant::asFloat() const { if (m_variantType != VT_FLOAT) - throw RplException("RplASVariant::asNumber: not a number: %d", + throw ReException("ReASVariant::asNumber: not a number: %d", m_variantType); return m_value.m_float; } @@ -325,10 +325,10 @@ qreal RplASVariant::asFloat() const * @throw RplException the instance is not a numberic value * */ -int RplASVariant::asInt() const +int ReASVariant::asInt() const { if (m_variantType != VT_INTEGER) - throw RplException("RplASVariant::asInt: not an integer: %d", + throw ReException("ReASVariant::asInt: not an integer: %d", m_variantType); return m_value.m_int; } @@ -340,10 +340,10 @@ int RplASVariant::asInt() const * @throw RplException the instance is not a boolean value * */ -bool RplASVariant::asBool() const +bool ReASVariant::asBool() const { if (m_variantType != VT_BOOL) - throw RplException("RplASVariant::asBool: not a boolean: %d", + throw ReException("ReASVariant::asBool: not a boolean: %d", m_variantType); return m_value.m_bool; } @@ -356,10 +356,10 @@ bool RplASVariant::asBool() const * @throw RplException the instance is not a boolean value * */ -void* RplASVariant::asObject(const RplASClass** clazz) const +void* ReASVariant::asObject(const ReASClass** clazz) const { if (m_variantType != VT_OBJECT) - throw RplException("RplASVariant::asObject: not an object: %d", + throw ReException("ReASVariant::asObject: not an object: %d", m_variantType); if (clazz != NULL) *clazz = m_class; @@ -372,13 +372,13 @@ void* RplASVariant::asObject(const RplASClass** clazz) const * @return the value as string * @throw RplException the instance is not a string value */ -const QByteArray* RplASVariant::asString() const +const QByteArray* ReASVariant::asString() const { - const RplASClass* clazz; + const ReASClass* clazz; const QByteArray* rc = static_cast(asObject(&clazz)); - if (clazz != RplASString::m_instance){ + if (clazz != ReASString::m_instance){ const QByteArray& name = clazz->name(); - throw RplException("RplASVariant::asString: not a string: %s", + throw ReException("ReASVariant::asString: not a string: %s", name.constData()); } return rc; @@ -389,12 +389,12 @@ const QByteArray* RplASVariant::asString() const * * @param number the numeric value. */ -void RplASVariant::setFloat(qreal number) +void ReASVariant::setFloat(qreal number) { destroyValue(); m_variantType = VT_FLOAT; m_value.m_float = number; - m_class = RplASFloat::m_instance; + m_class = ReASFloat::m_instance; } /** @@ -402,12 +402,12 @@ void RplASVariant::setFloat(qreal number) * * @param integer the numeric value. */ -void RplASVariant::setInt(int integer) +void ReASVariant::setInt(int integer) { destroyValue(); m_variantType = VT_INTEGER; m_value.m_int = integer; - m_class = RplASInteger::m_instance; + m_class = ReASInteger::m_instance; } /** @@ -415,12 +415,12 @@ void RplASVariant::setInt(int integer) * * @param value the boolean value. */ -void RplASVariant::setBool(bool value) +void ReASVariant::setBool(bool value) { destroyValue(); m_variantType = VT_BOOL; m_value.m_bool = value; - m_class = RplASBoolean::m_instance; + m_class = ReASBoolean::m_instance; } /** @@ -428,10 +428,10 @@ void RplASVariant::setBool(bool value) * * @param string the string value. */ -void RplASVariant::setString(const QByteArray& string) +void ReASVariant::setString(const QByteArray& string) { - // deletion in RplASVariant::destroyValue(): - setObject(new QByteArray(string), RplASString::m_instance); + // deletion in ReASVariant::destroyValue(): + setObject(new QByteArray(string), ReASString::m_instance); } /** @@ -440,7 +440,7 @@ void RplASVariant::setString(const QByteArray& string) * @param maxLength the maximum length of the result * @return the value as string */ -QByteArray RplASVariant::toString(int maxLength) const +QByteArray ReASVariant::toString(int maxLength) const { QByteArray rc; char buffer[256]; @@ -474,7 +474,7 @@ QByteArray RplASVariant::toString(int maxLength) const * @param object the class specific value object. * @param clazz the data type of the object */ -void RplASVariant::setObject(void* object, const RplASClass* clazz) +void ReASVariant::setObject(void* object, const ReASClass* clazz) { destroyValue(); m_variantType = VT_OBJECT; @@ -483,7 +483,7 @@ void RplASVariant::setObject(void* object, const RplASClass* clazz) } -/** @class RplASItem rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASItem rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the abstract base class of all entries of an AST. * @@ -494,7 +494,7 @@ void RplASVariant::setObject(void* object, const RplASClass* clazz) * * @param type the type of the instance */ -RplASItem::RplASItem(RplASItemType type) : +ReASItem::ReASItem(ReASItemType type) : m_id(m_nextId++), m_nodeType(type), m_flags(0), @@ -505,7 +505,7 @@ RplASItem::RplASItem(RplASItemType type) : * @brief Destructor. */ -RplASItem::~RplASItem() +ReASItem::~ReASItem() { } @@ -518,18 +518,18 @@ RplASItem::~RplASItem() * @return true: instance and children are correct
* false: otherwise */ -bool RplASItem::checkAsCalculable(const char* description, - RplASClass* expectedClass, RplParser& parser) +bool ReASItem::checkAsCalculable(const char* description, + ReASClass* expectedClass, ReParser& parser) { bool rc = true; if (! check(parser)) rc = false; if (rc){ - RplASCalculable* expr = dynamic_cast(this); + ReASCalculable* expr = dynamic_cast(this); if (expr == NULL) rc = error(LOC_ITEM_AS_INT_1, parser, "%s not calculable: %s", description, nameOfItemType()); - else if (expr->clazz() != RplASInteger::m_instance) + else if (expr->clazz() != ReASInteger::m_instance) rc = error(LOC_ITEM_AS_INT_2, parser, "%s: wrong type %s instead of integer", description, expr->clazz()->name().constData()); @@ -542,7 +542,7 @@ bool RplASItem::checkAsCalculable(const char* description, * * @return the position of the item */ -const RplSourcePosition* RplASItem::position() const +const ReSourcePosition* ReASItem::position() const { return m_position; } @@ -552,7 +552,7 @@ const RplSourcePosition* RplASItem::position() const * * @param position the position to store */ -void RplASItem::setPosition(const RplSourcePosition* position) +void ReASItem::setPosition(const ReSourcePosition* position) { m_position = position; } @@ -562,7 +562,7 @@ void RplASItem::setPosition(const RplSourcePosition* position) * * @return the id */ -unsigned int RplASItem::id() const +unsigned int ReASItem::id() const { return m_id; } @@ -574,7 +574,7 @@ unsigned int RplASItem::id() const * @param bufferSize size of the target buffer * @return buffer */ -char* RplASItem::positionStr(char buffer[], size_t bufferSize) const +char* ReASItem::positionStr(char buffer[], size_t bufferSize) const { char* rc = (char*) ""; if (m_position != NULL) @@ -590,7 +590,7 @@ char* RplASItem::positionStr(char buffer[], size_t bufferSize) const * @param format string with placeholders (optional) like sprintf() * @param ... values for the placeholders */ -void RplASItem::error(RplLogger* logger, int location, const char* format, ...) +void ReASItem::error(ReLogger* logger, int location, const char* format, ...) { char buffer[1024]; int halfBufferSize = (sizeof buffer) / 2; @@ -607,7 +607,7 @@ void RplASItem::error(RplLogger* logger, int location, const char* format, ...) /** * @brief Resets the static id counter. */ -void RplASItem::reset() +void ReASItem::reset() { m_nextId = 1; } @@ -618,11 +618,11 @@ void RplASItem::reset() * @param thread the execution unit * @return the value described by the node expr */ -int RplASItem::calcAsInteger(RplASItem* expr, RplVMThread& thread) +int ReASItem::calcAsInteger(ReASItem* expr, ReVMThread& thread) { - RplASCalculable* expr2 = dynamic_cast(expr); + ReASCalculable* expr2 = dynamic_cast(expr); expr2->calc(thread); - RplASVariant& value = thread.popValue(); + ReASVariant& value = thread.popValue(); int rc = value.asInt(); return rc; } @@ -634,11 +634,11 @@ int RplASItem::calcAsInteger(RplASItem* expr, RplVMThread& thread) * @param thread the execution unit * @return the value described by the node expr */ -bool RplASItem::calcAsBoolean(RplASItem* expr, RplVMThread& thread) +bool ReASItem::calcAsBoolean(ReASItem* expr, ReVMThread& thread) { - RplASCalculable* expr2 = dynamic_cast(expr); + ReASCalculable* expr2 = dynamic_cast(expr); expr2->calc(thread); - RplASVariant& value = thread.popValue(); + ReASVariant& value = thread.popValue(); bool rc = value.asBool(); return rc; } @@ -650,17 +650,17 @@ bool RplASItem::calcAsBoolean(RplASItem* expr, RplVMThread& thread) * @return true: all statements are correct
* false: otherwise */ -bool RplASItem::checkStatementList(RplASItem* list, RplParser& parser) +bool ReASItem::checkStatementList(ReASItem* list, ReParser& parser) { bool rc = true; while(list != NULL){ if (! list->check(parser)) rc = false; - if (dynamic_cast(list) == NULL) + if (dynamic_cast(list) == NULL) rc = list->error(LOC_ITEM_STATEM_LIST_1, parser, "not a statement: %s", list->nameOfItemType()); - RplASNode1* node = dynamic_cast(list); + ReASNode1* node = dynamic_cast(list); if (node == NULL){ list->error(LOC_ITEM_STATEM_LIST_1, parser, "not a node: %s", list->nameOfItemType()); @@ -676,7 +676,7 @@ bool RplASItem::checkStatementList(RplASItem* list, RplParser& parser) * * @return the node type */ -RplASItemType RplASItem::nodeType() const +ReASItemType ReASItem::nodeType() const { return m_nodeType; } @@ -686,7 +686,7 @@ RplASItemType RplASItem::nodeType() const * * @return the node type as string */ -const char*RplASItem::nameOfItemType() const +const char*ReASItem::nameOfItemType() const { const char* rc = "?"; switch(m_nodeType){ @@ -778,7 +778,7 @@ const char*RplASItem::nameOfItemType() const * * @return the bitmask with the flags */ -int RplASItem::flags() const +int ReASItem::flags() const { return m_flags; } @@ -787,7 +787,7 @@ int RplASItem::flags() const * * @param flags the new value of the bitmask */ -void RplASItem::setFlags(int flags) +void ReASItem::setFlags(int flags) { m_flags = flags; } @@ -799,7 +799,7 @@ void RplASItem::setFlags(int flags) * @return true: classes are compatible
* false: otherwise */ -bool RplASItem::typeCheck(RplASClass* class1, RplASClass* class2){ +bool ReASItem::typeCheck(ReASClass* class1, ReASClass* class2){ bool rc; if (class1 == NULL || class2 == NULL) rc = false; @@ -818,11 +818,11 @@ bool RplASItem::typeCheck(RplASClass* class1, RplASClass* class2){ * @param ... the values for the placeholders * @return false (for chaining) */ -bool RplASItem::error(int location, RplParser& parser, const char* format, ...) +bool ReASItem::error(int location, ReParser& parser, const char* format, ...) { va_list varList; va_start(varList, format); - parser.addMessage(RplParser::LT_ERROR, location, m_position, format, varList); + parser.addMessage(ReParser::LT_ERROR, location, m_position, format, varList); va_end(varList); return false; } @@ -837,14 +837,14 @@ bool RplASItem::error(int location, RplParser& parser, const char* format, ...) * @param info additional info * @return false (for chaining) */ -bool RplASItem::ensureError(RplParser& parser, const char* info) +bool ReASItem::ensureError(ReParser& parser, const char* info) { if (parser.errors() == 0) error(LOC_ITEM_FORCE_ERROR_1, parser, "lost error (internal error): %s"); return false; } -/** @class RplASCalculable rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASCalculable rplastree.hpp "rplexpr/rplastree.hpp" * * @brief An abstract base class for items which calculates a value. * @@ -852,7 +852,7 @@ bool RplASItem::ensureError(RplParser& parser, const char* info) /** * @brief Constructor. */ -RplASCalculable::RplASCalculable() : +ReASCalculable::ReASCalculable() : m_class(NULL) { } @@ -861,7 +861,7 @@ RplASCalculable::RplASCalculable() : * @return the class */ -RplASClass* RplASCalculable::clazz() const +ReASClass* ReASCalculable::clazz() const { return m_class; } @@ -869,18 +869,18 @@ RplASClass* RplASCalculable::clazz() const * @brief Sets the class of the node. * @param clazz the new class */ -void RplASCalculable::setClass(RplASClass* clazz) +void ReASCalculable::setClass(ReASClass* clazz) { m_class = clazz; } -/** @class RplASStorable rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASStorable rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the abstract base class of value containing items. * */ -/** @class RplASConstant rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASConstant rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a constant for the Abstract Syntax Tree. * @@ -890,8 +890,8 @@ void RplASCalculable::setClass(RplASClass* clazz) * @brief Constructor. * */ -RplASConstant::RplASConstant() : - RplASItem(AST_CONSTANT), +ReASConstant::ReASConstant() : + ReASItem(AST_CONSTANT), m_value() { } @@ -901,9 +901,9 @@ RplASConstant::RplASConstant() : * * @param thread IN/OUT: the execution unit, a VM thread */ -void RplASConstant::calc(RplVMThread& thread) +void ReASConstant::calc(ReVMThread& thread) { - RplASVariant& value = thread.reserveValue(); + ReASVariant& value = thread.reserveValue(); value.copyValue(m_value); } @@ -913,7 +913,7 @@ void RplASConstant::calc(RplVMThread& thread) * @param parser for error processing * @return true: a constant is always correct */ -bool RplASConstant::check(RplParser& parser) +bool ReASConstant::check(ReParser& parser) { return true; } @@ -924,7 +924,7 @@ bool RplASConstant::check(RplParser& parser) * @param writer writes to output * @param indent nesting level */ -void RplASConstant::dump(RplWriter& writer, int indent) +void ReASConstant::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "const id: %d value: %s %s", m_id, @@ -936,18 +936,18 @@ void RplASConstant::dump(RplWriter& writer, int indent) * @brief Returns the value of the constant. * * This method will be used to set the value of the constant: - *
RplASConstant constant;
+ * 
ReASConstant constant;
  * constant.value().setString("Jonny");
  *
* * @return the internal value */ -RplASVariant& RplASConstant::value() +ReASVariant& ReASConstant::value() { return m_value; } -/** @class RplASListConstant rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASListConstant rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a container for constant list entries. * @@ -956,20 +956,20 @@ RplASVariant& RplASConstant::value() /** * @brief Constructor. */ -RplASListConstant::RplASListConstant() : - RplASNode1(AST_LIST_CONSTANT), - RplASCalculable() +ReASListConstant::ReASListConstant() : + ReASNode1(AST_LIST_CONSTANT), + ReASCalculable() { - m_value.setObject(RplASList::m_instance->newValueInstance(), - RplASList::m_instance); + m_value.setObject(ReASList::m_instance->newValueInstance(), + ReASList::m_instance); } /** * @brief Returns the list. * * @return the list */ -RplASListOfVariants* RplASListConstant::list(){ - RplASListOfVariants* rc = static_cast +ReASListOfVariants* ReASListConstant::list(){ + ReASListOfVariants* rc = static_cast (m_value.asObject(NULL)); return rc; } @@ -979,9 +979,9 @@ RplASListOfVariants* RplASListConstant::list(){ * * @param thread IN/OUT: the execution unit, a VM thread */ -void RplASListConstant::calc(RplVMThread& thread) +void ReASListConstant::calc(ReVMThread& thread) { - RplASVariant& value = thread.reserveValue(); + ReASVariant& value = thread.reserveValue(); value.copyValue(m_value); } @@ -991,7 +991,7 @@ void RplASListConstant::calc(RplVMThread& thread) * @param parser for error processing * @return true: a constant is always correct */ -bool RplASListConstant::check(RplParser& parser) +bool ReASListConstant::check(ReParser& parser) { return true; } @@ -1002,7 +1002,7 @@ bool RplASListConstant::check(RplParser& parser) * @param writer writes to output * @param indent nesting level */ -void RplASListConstant::dump(RplWriter& writer, int indent) +void ReASListConstant::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "listConst id: %d %s", m_id, @@ -1016,31 +1016,31 @@ void RplASListConstant::dump(RplWriter& writer, int indent) * @brief Returns the value of the constant. * * This method will be used to set the value of the constant: - *
RplASConstant constant;
+ * 
ReASConstant constant;
  * constant.value().setString("Jonny");
  *
* * @return the internal value */ -RplASVariant& RplASListConstant::value() +ReASVariant& ReASListConstant::value() { return m_value; } -/** @class RplASMapConstant rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASMapConstant rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a hash map for constant list entries. * */ /** - * @brief RplASMapConstant::RplASMapConstant + * @brief ReASMapConstant::ReASMapConstant */ -RplASMapConstant::RplASMapConstant() : - RplASNode1(AST_MAP_CONSTANT), - RplASCalculable(), +ReASMapConstant::ReASMapConstant() : + ReASNode1(AST_MAP_CONSTANT), + ReASCalculable(), m_value() { - m_value.setObject(new RplASMapOfVariants, RplASMap::m_instance); + m_value.setObject(new ReASMapOfVariants, ReASMap::m_instance); } /** @@ -1048,9 +1048,9 @@ RplASMapConstant::RplASMapConstant() : * * @param thread IN/OUT: the execution unit, a VM thread */ -void RplASMapConstant::calc(RplVMThread& thread) +void ReASMapConstant::calc(ReVMThread& thread) { - RplASVariant& value = thread.reserveValue(); + ReASVariant& value = thread.reserveValue(); value.copyValue(m_value); } @@ -1060,7 +1060,7 @@ void RplASMapConstant::calc(RplVMThread& thread) * @param parser for error processing * @return true: a constant is always correct */ -bool RplASMapConstant::check(RplParser& parser) +bool ReASMapConstant::check(ReParser& parser) { return true; } @@ -1070,7 +1070,7 @@ bool RplASMapConstant::check(RplParser& parser) * @param writer writes to output * @param indent nesting level */ -void RplASMapConstant::dump(RplWriter& writer, int indent) +void ReASMapConstant::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "mapConst id: %d %s", @@ -1085,7 +1085,7 @@ void RplASMapConstant::dump(RplWriter& writer, int indent) * * @return the variant value */ -RplASVariant& RplASMapConstant::value() +ReASVariant& ReASMapConstant::value() { return m_value; } @@ -1095,14 +1095,14 @@ RplASVariant& RplASMapConstant::value() * * @return the map of the constant */ -RplASMapOfVariants* RplASMapConstant::map() +ReASMapOfVariants* ReASMapConstant::map() { - RplASMapOfVariants* rc = static_cast( + ReASMapOfVariants* rc = static_cast( m_value.asObject(NULL)); return rc; } -/** @class RplASNamedValue rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASNamedValue rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a named values, a constant or a variable */ @@ -1115,9 +1115,9 @@ RplASMapOfVariants* RplASMapConstant::map() * @param name the name of the variable * @param attributes the attributes of the variable */ -RplASNamedValue::RplASNamedValue(RplASClass* clazz,RplSymbolSpace* space, +ReASNamedValue::ReASNamedValue(ReASClass* clazz,ReSymbolSpace* space, const QByteArray& name, int attributes) : - RplASItem(AST_NAMED_VALUE), + ReASItem(AST_NAMED_VALUE), m_name(name), m_attributes(attributes), m_symbolSpace(space), @@ -1131,7 +1131,7 @@ RplASNamedValue::RplASNamedValue(RplASClass* clazz,RplSymbolSpace* space, * * @return the name */ -const QByteArray& RplASNamedValue::name() const +const QByteArray& ReASNamedValue::name() const { return m_name; } @@ -1141,7 +1141,7 @@ const QByteArray& RplASNamedValue::name() const * @param space * @param variableNo */ -void RplASNamedValue::setSymbolSpace(RplSymbolSpace* space, int variableNo) +void ReASNamedValue::setSymbolSpace(ReSymbolSpace* space, int variableNo) { m_symbolSpace = space; m_variableNo = variableNo; @@ -1151,7 +1151,7 @@ void RplASNamedValue::setSymbolSpace(RplSymbolSpace* space, int variableNo) * * @param thread IN/OUT: the execution unit, a VM thread */ -void RplASNamedValue::calc(RplVMThread& thread) +void ReASNamedValue::calc(ReVMThread& thread) { thread.valueToTop(m_symbolSpace, m_variableNo); if (thread.tracing()) @@ -1167,7 +1167,7 @@ void RplASNamedValue::calc(RplVMThread& thread) * @return true: node is correct
* false: otherwise */ -bool RplASNamedValue::check(RplParser& parser) +bool ReASNamedValue::check(ReParser& parser) { return true; } @@ -1177,7 +1177,7 @@ bool RplASNamedValue::check(RplParser& parser) * @param writer writes to output * @param indent nesting level */ -void RplASNamedValue::dump(RplWriter& writer, int indent) +void ReASNamedValue::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "namedValue %s id: %d attr: 0x%x %s", @@ -1190,7 +1190,7 @@ void RplASNamedValue::dump(RplWriter& writer, int indent) * * @return the symbol space */ -RplSymbolSpace*RplASNamedValue::symbolSpace() const +ReSymbolSpace*ReASNamedValue::symbolSpace() const { return m_symbolSpace; } @@ -1200,7 +1200,7 @@ RplSymbolSpace*RplASNamedValue::symbolSpace() const * * @param variableNo the variable number */ -void RplASNamedValue::setVariableNo(int variableNo) +void ReASNamedValue::setVariableNo(int variableNo) { m_variableNo = variableNo; } @@ -1211,12 +1211,12 @@ void RplASNamedValue::setVariableNo(int variableNo) * * @return the current number of the variable in the symbol space */ -int RplASNamedValue::variableNo() const +int ReASNamedValue::variableNo() const { return m_variableNo; } -/** @class RplASConversion rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASConversion rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a data type conversion. * @@ -1226,8 +1226,8 @@ int RplASNamedValue::variableNo() const * @brief Constructor. * @param expression the expression to convert */ -RplASConversion::RplASConversion(RplASItem* expression) : - RplASNode1(AST_CONVERSION), +ReASConversion::ReASConversion(ReASItem* expression) : + ReASNode1(AST_CONVERSION), m_conversion(C_UNDEF) { m_child = expression; @@ -1237,15 +1237,15 @@ RplASConversion::RplASConversion(RplASItem* expression) : /** * @brief Convert an expression to another data type. * - * Possible conversions: @see RplASConversion::Conversion + * Possible conversions: @see ReASConversion::Conversion * * @param thread execution value */ -void RplASConversion::calc(RplVMThread& thread) +void ReASConversion::calc(ReVMThread& thread) { - RplASCalculable* expr = dynamic_cast(m_child); + ReASCalculable* expr = dynamic_cast(m_child); expr->calc(thread); - RplASVariant& value = thread.topOfValues(); + ReASVariant& value = thread.topOfValues(); switch(m_conversion){ case C_INT_TO_FLOAT: @@ -1278,22 +1278,22 @@ void RplASConversion::calc(RplVMThread& thread) * @return C_UNDEF: not convertable
* otherwise: the conversion type */ -RplASConversion::Conversion RplASConversion::findConversion(RplASClass* from, - RplASClass* to) +ReASConversion::Conversion ReASConversion::findConversion(ReASClass* from, + ReASClass* to) { Conversion rc = C_UNDEF; - if (from == RplASFloat::m_instance){ - if (to == RplASInteger::m_instance) + if (from == ReASFloat::m_instance){ + if (to == ReASInteger::m_instance) rc = C_FLOAT_TO_INT; - } else if (from == RplASInteger::m_instance){ - if (to == RplASFloat::m_instance) + } else if (from == ReASInteger::m_instance){ + if (to == ReASFloat::m_instance) rc = C_INT_TO_FLOAT; - } else if (from == RplASBoolean::m_instance){ - if (to == RplASInteger::m_instance) + } else if (from == ReASBoolean::m_instance){ + if (to == ReASInteger::m_instance) rc = C_BOOL_TO_INT; - else if (to == RplASInteger::m_instance) + else if (to == ReASInteger::m_instance) rc = C_BOOL_TO_INT; - else if (to == RplASFloat::m_instance) + else if (to == ReASFloat::m_instance) rc = C_BOOL_TO_FLOAT; } return rc; @@ -1306,14 +1306,14 @@ RplASConversion::Conversion RplASConversion::findConversion(RplASClass* from, * @return true: node is correct
* false: otherwise */ -bool RplASConversion::check(RplParser& parser) +bool ReASConversion::check(ReParser& parser) { bool rc = m_child != NULL && m_child->check(parser); - RplASCalculable* expr = dynamic_cast(m_child); + ReASCalculable* expr = dynamic_cast(m_child); if (! rc || expr == NULL) - ensureError(parser, "RplASConversion::check"); + ensureError(parser, "ReASConversion::check"); else { - RplASClass* from = expr->clazz(); + ReASClass* from = expr->clazz(); m_conversion = findConversion(from, m_class); if (m_conversion != C_UNDEF) rc = true; @@ -1332,7 +1332,7 @@ bool RplASConversion::check(RplParser& parser) * @param writer writes to output * @param indent nesting level */ -void RplASConversion::dump(RplWriter& writer, int indent) +void ReASConversion::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "conversion %s id: %d expr: %d %s", @@ -1356,14 +1356,14 @@ void RplASConversion::dump(RplWriter& writer, int indent) * @return NULL: no conversion necessary
* otherwise: a converter to the given type */ -RplASConversion* RplASConversion::tryConversion(RplASClass* expected, - RplASItem* expr, RplParser& parser, bool& isCorrect) +ReASConversion* ReASConversion::tryConversion(ReASClass* expected, + ReASItem* expr, ReParser& parser, bool& isCorrect) { - RplASConversion* rc = NULL; + ReASConversion* rc = NULL; if (! expr->check(parser)) isCorrect = false; else { - RplASCalculable* expr2 = dynamic_cast(expr); + ReASCalculable* expr2 = dynamic_cast(expr); if (expr2 != NULL){ Conversion type = findConversion(expr2->clazz(), expected); if (type == C_UNDEF){ @@ -1372,7 +1372,7 @@ RplASConversion* RplASConversion::tryConversion(RplASClass* expected, expr2->clazz()->name().constData(), expected->name().constData()); } else if (expr2->clazz() != expected){ - rc = new RplASConversion(expr); + rc = new ReASConversion(expr); rc->m_conversion = type; rc->setClass(expected); } @@ -1381,15 +1381,15 @@ RplASConversion* RplASConversion::tryConversion(RplASClass* expected, return rc; } -/** @class RplASIndexedValue rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASIndexedValue rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an indexed values (member of a list) * * m_child: the parent: a list/map expression * m_child2: the index expression */ -RplASIndexedValue::RplASIndexedValue() : - RplASNode2(AST_INDEXED_VALUE) +ReASIndexedValue::ReASIndexedValue() : + ReASNode2(AST_INDEXED_VALUE) { } @@ -1400,15 +1400,15 @@ RplASIndexedValue::RplASIndexedValue() : * * @param thread execution value */ -void RplASIndexedValue::calc(RplVMThread& thread) +void ReASIndexedValue::calc(ReVMThread& thread) { - RplASCalculable* expr = dynamic_cast(m_child2); + ReASCalculable* expr = dynamic_cast(m_child2); expr->calc(thread); - RplASVariant& ixValue = thread.popValue(); + ReASVariant& ixValue = thread.popValue(); int ix = ixValue.asInt(); - RplASCalculable* list = dynamic_cast(m_child); + ReASCalculable* list = dynamic_cast(m_child); list->calc(thread); - RplASVariant& listValue = thread.popValue(); + ReASVariant& listValue = thread.popValue(); //@ToDo: access to the lists element: assignment or to stack if (thread.tracing()) thread.vm()->traceWriter()->format("[%d]: %.80s", @@ -1422,23 +1422,23 @@ void RplASIndexedValue::calc(RplVMThread& thread) * @return true: node is correct
* false: otherwise */ -bool RplASIndexedValue::check(RplParser& parser) +bool ReASIndexedValue::check(ReParser& parser) { - RplASCalculable* list = dynamic_cast(m_child); + ReASCalculable* list = dynamic_cast(m_child); bool rc = m_child != NULL && m_child->check(parser); if (! rc || list == NULL) - ensureError(parser, "RplASIndexedValue::check"); + ensureError(parser, "ReASIndexedValue::check"); else { // index value: // tryConversion() calls m_child2->check()! - RplASConversion* converter = RplASConversion::tryConversion( - RplASInteger::m_instance, m_child2, parser, rc); + ReASConversion* converter = ReASConversion::tryConversion( + ReASInteger::m_instance, m_child2, parser, rc); if (rc && converter != NULL) m_child = converter; if (rc){ //@ToDo: dynamic subclass of list / map - m_class = RplASString::m_instance; - rc = m_class != NULL && m_class == RplASInteger::m_instance; + m_class = ReASString::m_instance; + rc = m_class != NULL && m_class == ReASInteger::m_instance; } } return rc; @@ -1450,7 +1450,7 @@ bool RplASIndexedValue::check(RplParser& parser) * @param writer writes to output * @param indent nesting level */ -void RplASIndexedValue::dump(RplWriter& writer, int indent) +void ReASIndexedValue::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "indexedValue id: %d index: %d parent: %d %s", @@ -1472,9 +1472,9 @@ void RplASIndexedValue::dump(RplWriter& writer, int indent) /** * @brief Constructor. */ -RplASVarDefinition::RplASVarDefinition() : - RplASNode3(AST_VAR_DEFINITION), - RplASStatement(), +ReASVarDefinition::ReASVarDefinition() : + ReASNode3(AST_VAR_DEFINITION), + ReASStatement(), m_endOfScope(0) { m_flags |= NF_STATEMENT; @@ -1486,9 +1486,9 @@ RplASVarDefinition::RplASVarDefinition() : * @param writer writes to output * @param indent nesting level */ -void RplASVarDefinition::dump(RplWriter& writer, int indent) +void ReASVarDefinition::dump(ReWriter& writer, int indent) { - RplASNamedValue* namedValue = dynamic_cast(m_child2); + ReASNamedValue* namedValue = dynamic_cast(m_child2); QByteArray name = namedValue->name(); char endOfScope[32]; endOfScope[0] = '\0'; @@ -1514,9 +1514,9 @@ void RplASVarDefinition::dump(RplWriter& writer, int indent) * * @return the name */ -const QByteArray& RplASVarDefinition::name() const +const QByteArray& ReASVarDefinition::name() const { - RplASNamedValue* namedValue = dynamic_cast(m_child2); + ReASNamedValue* namedValue = dynamic_cast(m_child2); const QByteArray& rc = namedValue->name(); return rc; } @@ -1526,10 +1526,10 @@ const QByteArray& RplASVarDefinition::name() const * * @return the data type */ -RplASClass* RplASVarDefinition::clazz() const +ReASClass* ReASVarDefinition::clazz() const { - RplASNamedValue* namedValue = dynamic_cast(m_child2); - RplASClass* rc = namedValue == NULL ? NULL : namedValue->clazz(); + ReASNamedValue* namedValue = dynamic_cast(m_child2); + ReASClass* rc = namedValue == NULL ? NULL : namedValue->clazz(); return rc; } /** @@ -1539,7 +1539,7 @@ RplASClass* RplASVarDefinition::clazz() const * * @return 0 or the column of the scope end */ -int RplASVarDefinition::endOfScope() const +int ReASVarDefinition::endOfScope() const { return m_endOfScope; } @@ -1549,7 +1549,7 @@ int RplASVarDefinition::endOfScope() const * * @param endOfScope the column of the scope end */ -void RplASVarDefinition::setEndOfScope(int endOfScope) +void ReASVarDefinition::setEndOfScope(int endOfScope) { m_endOfScope = endOfScope; } @@ -1562,17 +1562,17 @@ void RplASVarDefinition::setEndOfScope(int endOfScope) * @return true: node is correct
* false: otherwise */ -bool RplASVarDefinition::check(RplParser& parser) +bool ReASVarDefinition::check(ReParser& parser) { - RplASNamedValue* var = dynamic_cast(m_child2); + ReASNamedValue* var = dynamic_cast(m_child2); bool rc = var != NULL && (m_child3 == NULL || m_child3->check(parser)); if (! rc) - ensureError(parser, "RplASVarDefinition::check"); + ensureError(parser, "ReASVarDefinition::check"); else { if (m_child3 != NULL){ // with initialization: - RplASCalculable* expr = dynamic_cast(m_child3); + ReASCalculable* expr = dynamic_cast(m_child3); if (expr == NULL) rc = error(LOC_VARDEF_CHECK_1, parser, "Not a calculable expression: %s", @@ -1593,15 +1593,15 @@ bool RplASVarDefinition::check(RplParser& parser) * * @return 0: continue the current statement list
*/ -int RplASVarDefinition::execute(RplVMThread& thread) +int ReASVarDefinition::execute(ReVMThread& thread) { if (m_child3 != NULL){ // has an initialization: - RplASNamedValue* var = dynamic_cast(m_child2); - RplASCalculable* expr = dynamic_cast(m_child3); + ReASNamedValue* var = dynamic_cast(m_child2); + ReASCalculable* expr = dynamic_cast(m_child3); expr->calc(thread); - RplASVariant& value = thread.popValue(); - RplASVariant& destination = thread.valueOfVariable( + ReASVariant& value = thread.popValue(); + ReASVariant& destination = thread.valueOfVariable( var->m_symbolSpace, var->m_variableNo); if (thread.tracing()) thread.vm()->traceWriter()->format("%s = %.80s [%.80s]", @@ -1613,7 +1613,7 @@ int RplASVarDefinition::execute(RplVMThread& thread) return 0; } -/** @class RplASExprStatement rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASExprStatement rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an statement consisting of an expression. * @@ -1624,9 +1624,9 @@ int RplASVarDefinition::execute(RplVMThread& thread) /** * @brief Constructor. */ -RplASExprStatement::RplASExprStatement() : - RplASNode2(AST_EXPR_STATEMENT), - RplASStatement() +ReASExprStatement::ReASExprStatement() : + ReASNode2(AST_EXPR_STATEMENT), + ReASStatement() { m_flags |= NF_STATEMENT; } @@ -1638,13 +1638,13 @@ RplASExprStatement::RplASExprStatement() : * @return true: node is correct
* false: otherwise */ -bool RplASExprStatement::check(RplParser& parser) +bool ReASExprStatement::check(ReParser& parser) { bool rc = m_child2->check(parser); if (rc){ - RplASCalculable* expr = dynamic_cast (m_child2); + ReASCalculable* expr = dynamic_cast (m_child2); if (expr == NULL) - rc = ensureError(parser, "RplASExprStatement::check"); + rc = ensureError(parser, "ReASExprStatement::check"); } return rc; } @@ -1653,11 +1653,11 @@ bool RplASExprStatement::check(RplParser& parser) * * @return 0: continue the current statement list
*/ -int RplASExprStatement::execute(RplVMThread& thread) +int ReASExprStatement::execute(ReVMThread& thread) { - RplASCalculable* expr = dynamic_cast (m_child2); + ReASCalculable* expr = dynamic_cast (m_child2); expr->calc(thread); - RplASVariant& value = thread.popValue(); + ReASVariant& value = thread.popValue(); if (thread.tracing()) thread.vm()->traceWriter()->format("expr: %s", value.toString().constData()); @@ -1672,7 +1672,7 @@ int RplASExprStatement::execute(RplVMThread& thread) * @param indent nesting level */ -void RplASExprStatement::dump(RplWriter& writer, int indent) +void ReASExprStatement::dump(ReWriter& writer, int indent) { char buffer[256]; if (m_id == 40) @@ -1685,7 +1685,7 @@ void RplASExprStatement::dump(RplWriter& writer, int indent) m_child2->dump(writer, indent + 1); } -/** @class RplASNode1 rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASNode1 rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an inner node of the abstract syntax tree with one child. * @@ -1693,11 +1693,11 @@ void RplASExprStatement::dump(RplWriter& writer, int indent) */ /** - * @brief RplASNode1::RplASNode1 + * @brief ReASNode1::ReASNode1 * @param type */ -RplASNode1::RplASNode1(RplASItemType type) : - RplASItem(type), +ReASNode1::ReASNode1(ReASItemType type) : + ReASItem(type), m_child(NULL) { } @@ -1705,7 +1705,7 @@ RplASNode1::RplASNode1(RplASItemType type) : /** * @brief Destructor. */ -RplASNode1::~RplASNode1() +ReASNode1::~ReASNode1() { delete m_child; m_child = NULL; @@ -1715,14 +1715,14 @@ RplASNode1::~RplASNode1() * * @return the child of the instance */ -RplASItem* RplASNode1::child() const +ReASItem* ReASNode1::child() const { return m_child; } /** * @brief Sets the child. */ -void RplASNode1::setChild(RplASItem* child) +void ReASNode1::setChild(ReASItem* child) { m_child = child; } @@ -1734,18 +1734,18 @@ void RplASNode1::setChild(RplASItem* child) * @param indent the indent level of the statement list * @param statements the chain of statements to dump */ -void RplASNode1::dumpStatements(RplWriter& writer, int indent, - RplASItem* statements) +void ReASNode1::dumpStatements(ReWriter& writer, int indent, + ReASItem* statements) { - RplASNode1* chain = dynamic_cast(statements); + ReASNode1* chain = dynamic_cast(statements); while (chain != NULL){ chain->dump(writer, indent); - chain = dynamic_cast(chain->m_child); + chain = dynamic_cast(chain->m_child); } } -/** @class RplASNode2 rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASNode2 rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an inner node of the abstract syntax tree with two childs. * @@ -1753,11 +1753,11 @@ void RplASNode1::dumpStatements(RplWriter& writer, int indent, */ /** - * @brief RplASNode2::RplASNode2 + * @brief ReASNode2::ReASNode2 * @param type */ -RplASNode2::RplASNode2(RplASItemType type) : - RplASNode1(type), +ReASNode2::ReASNode2(ReASItemType type) : + ReASNode1(type), m_child2(NULL) { } @@ -1765,23 +1765,23 @@ RplASNode2::RplASNode2(RplASItemType type) : /** * @brief Destructor. */ -RplASNode2::~RplASNode2() +ReASNode2::~ReASNode2() { delete m_child2; m_child2 = NULL; } -RplASItem* RplASNode2::child2() const +ReASItem* ReASNode2::child2() const { return m_child2; } -void RplASNode2::setChild2(RplASItem* child2) +void ReASNode2::setChild2(ReASItem* child2) { m_child2 = child2; } -/** @class RplASNode3 rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASNode3 rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an inner node of the abstract syntax tree with 3 childs. * @@ -1789,11 +1789,11 @@ void RplASNode2::setChild2(RplASItem* child2) */ /** - * @brief RplASNode3::RplASNode3 + * @brief ReASNode3::ReASNode3 * @param type */ -RplASNode3::RplASNode3(RplASItemType type) : - RplASNode2(type), +ReASNode3::ReASNode3(ReASItemType type) : + ReASNode2(type), m_child3(NULL) { } @@ -1801,7 +1801,7 @@ RplASNode3::RplASNode3(RplASItemType type) : /** * @brief Destructor. */ -RplASNode3::~RplASNode3() +ReASNode3::~ReASNode3() { delete m_child3; m_child3 = NULL; @@ -1811,7 +1811,7 @@ RplASNode3::~RplASNode3() * * @return the child 3 */ -RplASItem* RplASNode3::child3() const +ReASItem* ReASNode3::child3() const { return m_child3; } @@ -1821,13 +1821,13 @@ RplASItem* RplASNode3::child3() const * * @param child3 the new child3 */ -void RplASNode3::setChild3(RplASItem* child3) +void ReASNode3::setChild3(ReASItem* child3) { m_child3 = child3; } -/** @class RplASNode4 rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASNode4 rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an inner node of the abstract syntax tree with 3 childs. * @@ -1835,11 +1835,11 @@ void RplASNode3::setChild3(RplASItem* child3) */ /** - * @brief RplASNode4::RplASNode4 + * @brief ReASNode4::ReASNode4 * @param type */ -RplASNode4::RplASNode4(RplASItemType type) : - RplASNode3(type), +ReASNode4::ReASNode4(ReASItemType type) : + ReASNode3(type), m_child4(NULL) { } @@ -1847,7 +1847,7 @@ RplASNode4::RplASNode4(RplASItemType type) : /** * @brief Destructor. */ -RplASNode4::~RplASNode4() +ReASNode4::~ReASNode4() { delete m_child4; m_child4 = NULL; @@ -1858,7 +1858,7 @@ RplASNode4::~RplASNode4() * * @return the child 4 */ -RplASItem* RplASNode4::child4() const +ReASItem* ReASNode4::child4() const { return m_child4; } @@ -1868,13 +1868,13 @@ RplASItem* RplASNode4::child4() const * * @param child4 the new child3 */ -void RplASNode4::setChild4(RplASItem* child4) +void ReASNode4::setChild4(ReASItem* child4) { m_child4 = child4; } -/** @class RplASNode5 rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASNode5 rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an inner node of the abstract syntax tree with 4 childs. * @@ -1882,11 +1882,11 @@ void RplASNode4::setChild4(RplASItem* child4) */ /** - * @brief RplASNode5::RplASNode5 + * @brief ReASNode5::ReASNode5 * @param type */ -RplASNode5::RplASNode5(RplASItemType type) : - RplASNode4(type), +ReASNode5::ReASNode5(ReASItemType type) : + ReASNode4(type), m_child5(NULL) { } @@ -1894,7 +1894,7 @@ RplASNode5::RplASNode5(RplASItemType type) : /** * @brief Destructor. */ -RplASNode5::~RplASNode5() +ReASNode5::~ReASNode5() { delete m_child5; m_child5 = NULL; @@ -1905,7 +1905,7 @@ RplASNode5::~RplASNode5() * * @return the child 5 */ -RplASItem* RplASNode5::child5() const +ReASItem* ReASNode5::child5() const { return m_child5; } @@ -1915,12 +1915,12 @@ RplASItem* RplASNode5::child5() const * * @param child5 the new child3 */ -void RplASNode5::setChild5(RplASItem* child5) +void ReASNode5::setChild5(ReASItem* child5) { m_child5 = child5; } -/** @class RplASNode6 rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASNode6 rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an inner node of the abstract syntax tree with 4 childs. * @@ -1928,11 +1928,11 @@ void RplASNode5::setChild5(RplASItem* child5) */ /** - * @brief RplASNode6::RplASNode6 + * @brief ReASNode6::ReASNode6 * @param type */ -RplASNode6::RplASNode6(RplASItemType type) : - RplASNode5(type), +ReASNode6::ReASNode6(ReASItemType type) : + ReASNode5(type), m_child6(NULL) { } @@ -1940,7 +1940,7 @@ RplASNode6::RplASNode6(RplASItemType type) : /** * @brief Destructor. */ -RplASNode6::~RplASNode6() +ReASNode6::~ReASNode6() { delete m_child6; m_child6 = NULL; @@ -1951,7 +1951,7 @@ RplASNode6::~RplASNode6() * * @return the child 5 */ -RplASItem* RplASNode6::child6() const +ReASItem* ReASNode6::child6() const { return m_child6; } @@ -1961,12 +1961,12 @@ RplASItem* RplASNode6::child6() const * * @param child6 the new child6 */ -void RplASNode6::setChild6(RplASItem* child6) +void ReASNode6::setChild6(ReASItem* child6) { m_child6 = child6; } -/** @class RplASUnaryOp rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASUnaryOp rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an unary operation. * @@ -1981,8 +1981,8 @@ void RplASNode6::setChild6(RplASItem* child6) * @param op the operator id * @param type the node type */ -RplASUnaryOp::RplASUnaryOp(UnaryOp op, RplASItemType type) : - RplASNode1(type), +ReASUnaryOp::ReASUnaryOp(UnaryOp op, ReASItemType type) : + ReASNode1(type), m_operator(op) { } @@ -1992,9 +1992,9 @@ RplASUnaryOp::RplASUnaryOp(UnaryOp op, RplASItemType type) : * * @param thread IN/OUT: the execution unit, a VM thread */ -void RplASUnaryOp::calc(RplVMThread& thread) +void ReASUnaryOp::calc(ReVMThread& thread) { - RplASVariant& value = thread.topOfValues(); + ReASVariant& value = thread.topOfValues(); switch(m_operator){ case UOP_PLUS: break; @@ -2029,39 +2029,39 @@ void RplASUnaryOp::calc(RplVMThread& thread) * @return true: node is correct
* false: otherwise */ -bool RplASUnaryOp::check(RplParser& parser) +bool ReASUnaryOp::check(ReParser& parser) { bool rc = m_child->check(parser); if (rc){ - RplASCalculable* expr = dynamic_cast(m_child); - RplASClass* clazz = expr == NULL ? NULL : expr->clazz(); + ReASCalculable* expr = dynamic_cast(m_child); + ReASClass* clazz = expr == NULL ? NULL : expr->clazz(); if (clazz == NULL){ - rc = ensureError(parser, "RplASUnaryOp::check"); + rc = ensureError(parser, "ReASUnaryOp::check"); } else { switch(m_operator){ case UOP_PLUS: - if (clazz != RplASInteger::m_instance - && clazz != RplASFloat::m_instance) + if (clazz != ReASInteger::m_instance + && clazz != ReASFloat::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) + if (clazz != ReASFloat::m_instance) m_operator = UOP_MINUS_FLOAT; - else if (clazz != RplASInteger::m_instance) + else if (clazz != ReASInteger::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) + if (clazz != ReASBoolean::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) + if (clazz != ReASInteger::m_instance) rc = error(LOC_UNARY_CHECK_4, parser, "wrong data type for unary operator '!': %s", clazz->name().constData()); @@ -2071,7 +2071,7 @@ bool RplASUnaryOp::check(RplParser& parser) case UOP_INC: break; default: - throw RplASException(position(), "unknown operator: %d", m_operator); + throw ReASException(position(), "unknown operator: %d", m_operator); break; } } @@ -2084,7 +2084,7 @@ bool RplASUnaryOp::check(RplParser& parser) * * @return the operator */ -int RplASUnaryOp::getOperator() const +int ReASUnaryOp::getOperator() const { return m_operator; } @@ -2095,7 +2095,7 @@ int RplASUnaryOp::getOperator() const * @param writer writes to output * @param indent nesting level */ -void RplASUnaryOp::dump(RplWriter& writer, int indent) +void ReASUnaryOp::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "Unary %d op: %s (%d) expr: %d %s", @@ -2113,7 +2113,7 @@ void RplASUnaryOp::dump(RplWriter& writer, int indent) * @param op the operand to convert * @return the name of the operator */ -const char*RplASUnaryOp::nameOfOp(RplASUnaryOp::UnaryOp op) +const char*ReASUnaryOp::nameOfOp(ReASUnaryOp::UnaryOp op) { const char* rc; switch (op){ @@ -2137,25 +2137,25 @@ const char*RplASUnaryOp::nameOfOp(RplASUnaryOp::UnaryOp op) rc="--"; break; default: - throw RplException("unknown unary operator: %d", (int) op); + throw ReException("unknown unary operator: %d", (int) op); break; } return rc; } -/** @class RplASStatement rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASStatement rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a base class for all statements. * - * @note statements are always RplASNode1 and m_child is used + * @note statements are always ReASNode1 and m_child is used * for the successors (next statement). */ /** * @brief Constructor. */ -RplASStatement::RplASStatement() +ReASStatement::ReASStatement() { } /** @@ -2167,18 +2167,18 @@ RplASStatement::RplASStatement() * n > 0: stop the n most inner statement lists (initialized by leave) * n < 0: stop the -n most inner statement lists (initialized by continue) */ -int RplASStatement::executeStatementList(RplASItem* list, RplVMThread& thread) +int ReASStatement::executeStatementList(ReASItem* list, ReVMThread& thread) { int rc = 0; while(rc == 0 && list != NULL){ - RplASStatement* statement = dynamic_cast(list); + ReASStatement* statement = dynamic_cast(list); rc =statement->execute(thread); } return rc; } -/** @class RplASIf rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASIf rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an if statement. * @@ -2192,8 +2192,8 @@ int RplASStatement::executeStatementList(RplASItem* list, RplVMThread& thread) * m_child4: else part or NULL
*/ -RplASIf::RplASIf() : - RplASNode4(AST_IF) +ReASIf::ReASIf() : + ReASNode4(AST_IF) { m_flags |= NF_STATEMENT; } @@ -2205,12 +2205,12 @@ RplASIf::RplASIf() : * @return true: node is correct
* false: otherwise */ -bool RplASIf::check(RplParser& parser) +bool ReASIf::check(ReParser& parser) { bool rc = true; if (m_child2 == NULL) rc = ensureError(parser, "'if' misses condition"); - else if (m_child2->checkAsCalculable("condition", RplASBoolean::m_instance, + else if (m_child2->checkAsCalculable("condition", ReASBoolean::m_instance, parser)) rc = false; if (m_child3 != NULL && ! checkStatementList(m_child3, parser)) @@ -2227,14 +2227,14 @@ bool RplASIf::check(RplParser& parser) * n > 0: stop the n most inner statement lists (initialized by leave) * n < 0: stop the -n most inner statement lists (initialized by continue) */ -int RplASIf::execute(RplVMThread& thread) +int ReASIf::execute(ReVMThread& thread) { int rc = 0; bool condition = calcAsBoolean(m_child2, thread); if (thread.tracing()) thread.vm()->traceWriter()->format("if %s", condition ? "true" : "false"); - RplASItem* list = condition ? m_child3 : m_child4; + ReASItem* list = condition ? m_child3 : m_child4; if (list != NULL){ if ( (rc = executeStatementList(list, thread)) != 0){ if (rc < 0) @@ -2252,7 +2252,7 @@ int RplASIf::execute(RplVMThread& thread) * @param writer writes to output * @param indent nesting level */ -void RplASIf::dump(RplWriter& writer, int indent) +void ReASIf::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, @@ -2270,7 +2270,7 @@ void RplASIf::dump(RplWriter& writer, int indent) m_child4->dump(writer, indent + 1); } -/** @class RplASFor rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASFor rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a for statement. * @@ -2291,9 +2291,9 @@ void RplASIf::dump(RplWriter& writer, int indent) * * @param variable NULL or the iterator variable */ -RplASForIterated::RplASForIterated(RplASVarDefinition* variable) : - RplASNode4(AST_ITERATED_FOR), - RplASStatement() +ReASForIterated::ReASForIterated(ReASVarDefinition* variable) : + ReASNode4(AST_ITERATED_FOR), + ReASStatement() { m_flags |= NF_STATEMENT; m_child2 = variable; @@ -2306,7 +2306,7 @@ RplASForIterated::RplASForIterated(RplASVarDefinition* variable) : * @return true: node is correct
* false: otherwise */ -bool RplASForIterated::check(RplParser& parser) +bool ReASForIterated::check(ReParser& parser) { return false; } @@ -2318,7 +2318,7 @@ bool RplASForIterated::check(RplParser& parser) * n > 0: stop the n most inner statement lists (initialized by leave) * n < 0: stop the -n most inner statement lists (initialized by continue) */ -int RplASForIterated::execute(RplVMThread& thread) +int ReASForIterated::execute(ReVMThread& thread) { return 0; } @@ -2329,7 +2329,7 @@ int RplASForIterated::execute(RplVMThread& thread) * @param writer writes to output * @param indent nesting level */ -void RplASForIterated::dump(RplWriter& writer, int indent) +void ReASForIterated::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "forIt id: %d var: %d set: %d body: %d succ: %d %s", @@ -2346,7 +2346,7 @@ void RplASForIterated::dump(RplWriter& writer, int indent) dumpStatements(writer, indent + 1, m_child2); } -/** @class RplASForCounted rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASForCounted rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a for statement. * @@ -2370,9 +2370,9 @@ void RplASForIterated::dump(RplWriter& writer, int indent) * * @param variable NULL or the counter variable */ -RplASForCounted::RplASForCounted(RplASVarDefinition* variable) : - RplASNode6(AST_ITERATED_FOR), - RplASStatement() +ReASForCounted::ReASForCounted(ReASVarDefinition* variable) : + ReASNode6(AST_ITERATED_FOR), + ReASStatement() { m_flags |= NF_STATEMENT; m_child3 = variable; @@ -2385,27 +2385,27 @@ RplASForCounted::RplASForCounted(RplASVarDefinition* variable) : * @return true: node is correct
* false: otherwise */ -bool RplASForCounted::check(RplParser& parser) +bool ReASForCounted::check(ReParser& parser) { bool rc = true; - RplASNamedValue* var = NULL; + ReASNamedValue* var = NULL; if (m_child3 != NULL){ - var = dynamic_cast(m_child3); + var = dynamic_cast(m_child3); if (! m_child3->check(parser)) rc = false; if (var == NULL) rc = error(LOC_FORC_CHECK_1, parser, "not a variable: %s", m_child3->nameOfItemType()); } - RplASCalculable* expr; + ReASCalculable* expr; if (m_child4 != NULL && ! m_child4->checkAsCalculable("start value", - RplASInteger::m_instance, parser)) + ReASInteger::m_instance, parser)) rc = false; if (m_child5 != NULL && ! m_child5->checkAsCalculable("end value", - RplASInteger::m_instance, parser)) + ReASInteger::m_instance, parser)) rc = false; if (m_child6 != NULL && ! m_child6->checkAsCalculable("step value", - RplASInteger::m_instance, parser)) + ReASInteger::m_instance, parser)) rc = false; if (m_child2 != NULL && ! checkStatementList(m_child2, parser)) rc = false; @@ -2419,18 +2419,18 @@ bool RplASForCounted::check(RplParser& parser) * n > 0: stop the n most inner statement lists (initialized by leave) * n < 0: stop the -n most inner statement lists (initialized by continue) */ -int RplASForCounted::execute(RplVMThread& thread) +int ReASForCounted::execute(ReVMThread& thread) { int rc = 0; - RplASStatement* body = dynamic_cast(m_child2); + ReASStatement* body = dynamic_cast(m_child2); if (body == NULL) - throw RplASException(m_child2 == NULL ? m_position : m_child2->position(), + throw ReASException(m_child2 == NULL ? m_position : m_child2->position(), "forc statement: body is not a statement"); int start = m_child4 == NULL ? 1 : calcAsInteger(m_child4, thread); int end = m_child5 == NULL ? 0 : calcAsInteger(m_child5, thread); int step = m_child6 == NULL ? 1 : calcAsInteger(m_child6, thread); - RplASNamedValue* var = m_child3 == NULL - ? NULL : dynamic_cast(m_child3); + ReASNamedValue* var = m_child3 == NULL + ? NULL : dynamic_cast(m_child3); if (thread.tracing()) thread.vm()->traceWriter()->format("for %s from %d to %d step %d", var == NULL ? "?" : var->name().constData(), @@ -2462,7 +2462,7 @@ int RplASForCounted::execute(RplVMThread& thread) * @param writer writes to output * @param indent nesting level */ -void RplASForCounted::dump(RplWriter& writer, int indent) +void ReASForCounted::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "forC id: %d var: %d from: %d to: %d step: %d body: %d succ: %d %s", @@ -2485,7 +2485,7 @@ void RplASForCounted::dump(RplWriter& writer, int indent) dumpStatements(writer, indent + 1, m_child2); } -/** @class RplASWhile rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASWhile rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a while statement. * @@ -2497,9 +2497,9 @@ void RplASForCounted::dump(RplWriter& writer, int indent) * m_child3: body
*/ -RplASWhile::RplASWhile() : - RplASNode3(AST_WHILE), - RplASStatement() +ReASWhile::ReASWhile() : + ReASNode3(AST_WHILE), + ReASStatement() { m_flags |= NF_STATEMENT; } @@ -2511,13 +2511,13 @@ RplASWhile::RplASWhile() : * @return true: node is correct
* false: otherwise */ -bool RplASWhile::check(RplParser& parser) +bool ReASWhile::check(ReParser& parser) { bool rc = true; if (m_child2 == NULL) ensureError(parser, "missing condition for 'while''"); else - rc = m_child2->checkAsCalculable("condition", RplASBoolean::m_instance, + rc = m_child2->checkAsCalculable("condition", ReASBoolean::m_instance, parser); if (m_child3 != NULL && ! checkStatementList(m_child3, parser)) rc = false; @@ -2531,10 +2531,10 @@ bool RplASWhile::check(RplParser& parser) * n > 0: stop the n most inner statement lists (initialized by leave) * n < 0: stop the -n most inner statement lists (initialized by continue) */ -int RplASWhile::execute(RplVMThread& thread) +int ReASWhile::execute(ReVMThread& thread) { int rc = 0; - RplASStatement* body = dynamic_cast(m_child3); + ReASStatement* body = dynamic_cast(m_child3); if (thread.tracing()) thread.vm()->traceWriter()->write("while"); while(calcAsBoolean(m_child2, thread)){ @@ -2562,7 +2562,7 @@ int RplASWhile::execute(RplVMThread& thread) * @param writer writes to output * @param indent nesting level */ -void RplASWhile::dump(RplWriter& writer, int indent) +void ReASWhile::dump(ReWriter& writer, int indent) { char buffer[256]; @@ -2577,7 +2577,7 @@ void RplASWhile::dump(RplWriter& writer, int indent) dumpStatements(writer, indent + 1, m_child3); } -/** @class RplASRepeat rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASRepeat rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a while statement. * @@ -2589,9 +2589,9 @@ void RplASWhile::dump(RplWriter& writer, int indent) * m_child3: body
*/ -RplASRepeat::RplASRepeat() : - RplASNode3(AST_REPEAT), - RplASStatement() +ReASRepeat::ReASRepeat() : + ReASNode3(AST_REPEAT), + ReASStatement() { m_flags |= NF_STATEMENT; } @@ -2603,14 +2603,14 @@ RplASRepeat::RplASRepeat() : * @return true: node is correct
* false: otherwise */ -bool RplASRepeat::check(RplParser& parser) +bool ReASRepeat::check(ReParser& parser) { bool rc = true; if (m_child3 != NULL && ! checkStatementList(m_child3, parser)) rc = false; if (m_child2 == NULL) ensureError(parser, "missing condition for 'repeat''"); - else if (! m_child2->checkAsCalculable("condition", RplASBoolean::m_instance, + else if (! m_child2->checkAsCalculable("condition", ReASBoolean::m_instance, parser)) rc = false; return rc; @@ -2623,10 +2623,10 @@ bool RplASRepeat::check(RplParser& parser) * m_child: body * m_child2: condition */ -int RplASRepeat::execute(RplVMThread& thread) +int ReASRepeat::execute(ReVMThread& thread) { int rc = 0; - RplASStatement* body = dynamic_cast(m_child3); + ReASStatement* body = dynamic_cast(m_child3); if (thread.tracing()) thread.vm()->traceWriter()->write("repeat"); do { @@ -2654,7 +2654,7 @@ int RplASRepeat::execute(RplVMThread& thread) * @param writer writes to output * @param indent nesting level */ -void RplASRepeat::dump(RplWriter& writer, int indent) +void ReASRepeat::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "repeat id: %d condition: %d body: %d succ: %d %s", @@ -2668,7 +2668,7 @@ void RplASRepeat::dump(RplWriter& writer, int indent) dumpStatements(writer, indent + 1, m_child3); } -/** @class RplASClass rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASClass rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the base class of an Abstract Syntax Tree class. * @@ -2677,7 +2677,7 @@ void RplASRepeat::dump(RplWriter& writer, int indent) /** * @brief Constructor. */ -RplASClass::RplASClass(const QByteArray& name, RplASTree& tree) : +ReASClass::ReASClass(const QByteArray& name, ReASTree& tree) : m_name(name), m_symbols(NULL), m_superClass(NULL), @@ -2691,7 +2691,7 @@ RplASClass::RplASClass(const QByteArray& name, RplASTree& tree) : * Does nothing but forces a virtual destructor of all derived classes. * */ -RplASClass::~RplASClass() +ReASClass::~ReASClass() { } @@ -2701,7 +2701,7 @@ RplASClass::~RplASClass() * * @return the class name */ -const QByteArray& RplASClass::name() const +const QByteArray& ReASClass::name() const { return m_name; } @@ -2712,7 +2712,7 @@ const QByteArray& RplASClass::name() const * @param writer writes to output * @param indent nesting level */ -void RplASClass::dump(RplWriter& writer, int indent) +void ReASClass::dump(ReWriter& writer, int indent) { writer.formatIndented(indent, "class %s super: %s", m_name.constData(), m_superClass == NULL @@ -2723,12 +2723,12 @@ void RplASClass::dump(RplWriter& writer, int indent) /** * @brief Sets the symbol space from the current in the tree. */ -void RplASClass::setSymbols() +void ReASClass::setSymbols() { m_symbols = m_tree.currentSpace(); } -/** @class RplASTree rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASTree rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a manager for all parts of an Abstract Syntax Tree. * @@ -2738,7 +2738,7 @@ void RplASClass::setSymbols() /** * @brief Constructor. */ -RplASTree::RplASTree() : +ReASTree::ReASTree() : m_global(NULL), m_modules(), m_symbolSpaces(), @@ -2751,7 +2751,7 @@ RplASTree::RplASTree() : /** * @brief Destructor. */ -RplASTree::~RplASTree() +ReASTree::~ReASTree() { destroy(); } @@ -2761,9 +2761,9 @@ RplASTree::~RplASTree() * * Used in the constructor and in clear. */ -void RplASTree::init() +void ReASTree::init() { - m_global = RplSymbolSpace::createGlobal(*this); + m_global = ReSymbolSpace::createGlobal(*this); m_symbolSpaces.append(m_global); m_currentSpace = m_global; } @@ -2771,7 +2771,7 @@ void RplASTree::init() /** * @brief Frees the resources of the instance. */ -void RplASTree::destroy() +void ReASTree::destroy() { SymbolSpaceMap::iterator it; for (it = m_symbolSpaceHeap.begin(); it != m_symbolSpaceHeap.end(); it++){ @@ -2784,7 +2784,7 @@ void RplASTree::destroy() * * @return the efficient allocator for C strings */ -RplByteStorage& RplASTree::store() +ReByteStorage& ReASTree::store() { return m_store; } @@ -2796,12 +2796,12 @@ RplByteStorage& RplASTree::store() * @return true: the module is new
* false: the module is yet known */ -bool RplASTree::startModule(RplSourceUnitName name) +bool ReASTree::startModule(ReSourceUnitName name) { bool rc = m_modules.contains(name); if (! rc){ - // freed in ~RplASTree() - RplSymbolSpace* space = new RplSymbolSpace(RplSymbolSpace::SST_MODULE, + // freed in ~ReASTree() + ReSymbolSpace* space = new ReSymbolSpace(ReSymbolSpace::SST_MODULE, name, m_global); m_symbolSpaceHeap[name] = space; m_modules[name] = space; @@ -2817,9 +2817,9 @@ bool RplASTree::startModule(RplSourceUnitName name) * @return NULL: not found
* otherwise: the symbol space of the module */ -RplSymbolSpace* RplASTree::findmodule(const QByteArray& name) +ReSymbolSpace* ReASTree::findmodule(const QByteArray& name) { - RplSymbolSpace* rc = m_modules.contains(name) ? m_modules[name] : NULL; + ReSymbolSpace* rc = m_modules.contains(name) ? m_modules[name] : NULL; return rc; } @@ -2827,11 +2827,11 @@ RplSymbolSpace* RplASTree::findmodule(const QByteArray& name) * @brief Handles the end of a module. * @param name the module's name */ -void RplASTree::finishModule(RplSourceUnitName name) +void ReASTree::finishModule(ReSourceUnitName name) { - RplSymbolSpace* top = m_symbolSpaces.at(m_symbolSpaces.size() - 1); + ReSymbolSpace* top = m_symbolSpaces.at(m_symbolSpaces.size() - 1); if (top->name() != name) - throw RplException("RplASTree::finishModule(): module is not top: %s", + throw ReException("ReASTree::finishModule(): module is not top: %s", name); else { m_symbolSpaces.removeLast(); @@ -2846,14 +2846,14 @@ void RplASTree::finishModule(RplSourceUnitName name) * @param type the symbol space type * @return the new symbol space */ -RplSymbolSpace* RplASTree::startClassOrMethod(const QByteArray& name, - RplSymbolSpace::SymbolSpaceType type) +ReSymbolSpace* ReASTree::startClassOrMethod(const QByteArray& name, + ReSymbolSpace::SymbolSpaceType type) { // the stack m_modules is never empty because of "global" and modules. - RplSymbolSpace* parent = m_symbolSpaces[m_symbolSpaces.size() - 1]; + ReSymbolSpace* parent = m_symbolSpaces[m_symbolSpaces.size() - 1]; QByteArray fullName = parent->name() + "." + name; - // freed in ~RplASTree() - RplSymbolSpace* space = new RplSymbolSpace(type, fullName, parent); + // freed in ~ReASTree() + ReSymbolSpace* space = new ReSymbolSpace(type, fullName, parent); m_symbolSpaceHeap[fullName] = space; m_symbolSpaces.append(space); m_currentSpace = space; @@ -2865,11 +2865,11 @@ RplSymbolSpace* RplASTree::startClassOrMethod(const QByteArray& name, * * @param name the name of the class (short form) */ -void RplASTree::finishClassOrMethod(const QByteArray& name) +void ReASTree::finishClassOrMethod(const QByteArray& name) { - RplSymbolSpace* top = m_symbolSpaces.at(m_symbolSpaces.size() - 1); + ReSymbolSpace* top = m_symbolSpaces.at(m_symbolSpaces.size() - 1); if (! top->name().endsWith("." + name)) - throw RplException("RplASTree::finishModule(): class is not top: %s", + throw ReException("ReASTree::finishModule(): class is not top: %s", name.constData()); else { m_symbolSpaces.removeLast(); @@ -2883,7 +2883,7 @@ void RplASTree::finishClassOrMethod(const QByteArray& name) * * @return the stack with the active symbol spaces */ -RplASTree::SymbolSpaceStack& RplASTree::symbolSpaces() +ReASTree::SymbolSpaceStack& ReASTree::symbolSpaces() { return m_symbolSpaces; } @@ -2892,7 +2892,7 @@ RplASTree::SymbolSpaceStack& RplASTree::symbolSpaces() * * @return the current symbol space */ -RplSymbolSpace* RplASTree::currentSpace() const +ReSymbolSpace* ReASTree::currentSpace() const { return m_currentSpace; } @@ -2900,7 +2900,7 @@ RplSymbolSpace* RplASTree::currentSpace() const /** * @brief Removes all content from the abstract syntax tree. */ -void RplASTree::clear() +void ReASTree::clear() { destroy(); //m_global->clear(); @@ -2916,9 +2916,9 @@ void RplASTree::clear() * @param flags what to dump: sum of DMP_... flags * @param header NULL or a text put on the top */ -void RplASTree::dump(const char* filename, int flags, const char* header) +void ReASTree::dump(const char* filename, int flags, const char* header) { - RplFileWriter writer(filename); + ReFileWriter writer(filename); if (header != NULL) writer.writeLine(header); if (flags & DMP_GLOBALS){ @@ -2934,14 +2934,14 @@ void RplASTree::dump(const char* filename, int flags, const char* header) qSort(sorted.begin(), sorted.end(), qLess()); QList::iterator it2; for (it2 = sorted.begin(); it2 != sorted.end(); it2++){ - RplSymbolSpace* space = m_modules[*it2]; + ReSymbolSpace* space = m_modules[*it2]; space->dump(writer, 0); } } writer.close(); } -/** @class RplASMethodCall rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASMethodCall rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a method or function call for the Abstract Syntax Tree. * @@ -2957,9 +2957,9 @@ void RplASTree::dump(const char* filename, int flags, const char* header) * otherwise: the parent (variable, field ...) */ -RplASMethodCall::RplASMethodCall(const QByteArray& name, RplASItem* parent) : - RplASNode3(AST_METHOD_CALL), - RplASStatement(), +ReASMethodCall::ReASMethodCall(const QByteArray& name, ReASItem* parent) : + ReASNode3(AST_METHOD_CALL), + ReASStatement(), m_name(name), m_method(NULL) { @@ -2974,39 +2974,39 @@ RplASMethodCall::RplASMethodCall(const QByteArray& name, RplASItem* parent) : * @return true: node is correct
* false: otherwise */ -bool RplASMethodCall::check(RplParser& parser) +bool ReASMethodCall::check(ReParser& parser) { bool rc = true; - RplASExprStatement* args = dynamic_cast(m_child2); + ReASExprStatement* args = dynamic_cast(m_child2); int argCount = 0; - RplASMethod* method = m_method; - RplASVarDefinition* params = dynamic_cast(method->child2()); + ReASMethod* method = m_method; + ReASVarDefinition* params = dynamic_cast(method->child2()); while (args != NULL && params != NULL){ argCount++; - RplASCalculable* argExpr = dynamic_cast + ReASCalculable* argExpr = dynamic_cast (args->child2()); if (argExpr == NULL) rc = error(LOC_METHOD_CALL_CHECK_1, parser, "argument %d misses expr", argCount); else { - RplASNamedValue* var; - RplASItem* param = params->child2(); + ReASNamedValue* var; + ReASItem* param = params->child2(); if (param == NULL - || (var = dynamic_cast(param)) == NULL) + || (var = dynamic_cast(param)) == NULL) rc = error(LOC_MEHTOD_CALL_CHECK_2, parser, "parameter %d misses named value: %s", argCount, param == NULL ? "" : param->nameOfItemType()); else { // tryConversion() calls args->args->child2()->check()! - RplASConversion* converter = RplASConversion::tryConversion( + ReASConversion* converter = ReASConversion::tryConversion( var->clazz(), args->child2(), parser, rc); if (rc && converter != NULL) args->setChild2(converter); } } - args = dynamic_cast(args->child()); - params = dynamic_cast(params->child()); + args = dynamic_cast(args->child()); + params = dynamic_cast(params->child()); } if (args != NULL && params == NULL) rc = error(LOC_MEHTOD_CALL_CHECK_3, parser, @@ -3024,7 +3024,7 @@ bool RplASMethodCall::check(RplParser& parser) * @param writer writes to output * @param indent nesting level */ -void RplASMethodCall::dump(RplWriter& writer, int indent) +void ReASMethodCall::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "call %s Id: %d args: %d parent: %d succ: %d %s", @@ -3044,14 +3044,28 @@ void RplASMethodCall::dump(RplWriter& writer, int indent) * * @return 0: continue the current statement list */ -int RplASMethodCall::execute(RplVMThread& thread) +int ReASMethodCall::execute(ReVMThread& thread) { int rc = 0; - + ReASMethod* method = m_method; + ReStackFrame frame(this, m_method->symbols()); + thread.pushFrame(&frame); + ReASExprStatement* args = dynamic_cast(m_child2); + int ixArg = -1; + while (args != NULL){ + ixArg++; + ReASCalculable* argExpr = dynamic_cast + (args->child2()); + argExpr->calc(thread); + ReASVariant& value = thread.popValue(); + ReASVariant& varValue = frame.valueOfVariable(ixArg); + varValue.copyValue(value); + } + thread.popFrame(); return rc; } -RplASMethod* RplASMethodCall::method() const +ReASMethod* ReASMethodCall::method() const { return m_method; } @@ -3060,7 +3074,7 @@ RplASMethod* RplASMethodCall::method() const * @brief Sets the method. * @param method method to set */ -void RplASMethodCall::setMethod(RplASMethod* method) +void ReASMethodCall::setMethod(ReASMethod* method) { m_method = method; } @@ -3070,12 +3084,12 @@ void RplASMethodCall::setMethod(RplASMethod* method) * * @return the first element of an argument list */ -RplASExprStatement* RplASMethodCall::arg1() const +ReASExprStatement* ReASMethodCall::arg1() const { - return dynamic_cast(m_child2); + return dynamic_cast(m_child2); } -/** @class RplASException rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASException rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a call of a method or function. * @@ -3083,7 +3097,7 @@ RplASExprStatement* RplASMethodCall::arg1() const * m_child2: argument list (or NULL) */ -/** @class RplASBinaryOp rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASBinaryOp rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements binary operator for the Abstract Syntax Tree. * @@ -3093,8 +3107,8 @@ RplASExprStatement* RplASMethodCall::arg1() const /** * @brief Constructor. */ -RplASBinaryOp::RplASBinaryOp() : - RplASNode2(AST_BINARY_OP), +ReASBinaryOp::ReASBinaryOp() : + ReASNode2(AST_BINARY_OP), m_operator(BOP_UNDEF) { } @@ -3104,13 +3118,13 @@ RplASBinaryOp::RplASBinaryOp() : * * @param thread IN/OUT: the bool value of the condition */ -void RplASBinaryOp::calc(RplVMThread& thread) +void ReASBinaryOp::calc(ReVMThread& thread) { if (isAssignment()) assign(thread); else{ - RplASCalculable* op1 = dynamic_cast(m_child); - RplASCalculable* op2 = dynamic_cast(m_child2); + ReASCalculable* op1 = dynamic_cast(m_child); + ReASCalculable* op2 = dynamic_cast(m_child2); if (op1 == NULL || op2 == NULL) error(thread.logger(), LOC_BINOP_CALC_1, "operand is null: %d / %d", m_child == NULL ? 0 : m_child->id(), @@ -3118,19 +3132,19 @@ void RplASBinaryOp::calc(RplVMThread& thread) else{ op1->calc(thread); op2->calc(thread); - RplASVariant& val1 = thread.top2OfValues(); - RplASVariant& val2 = thread.topOfValues(); + ReASVariant& val1 = thread.top2OfValues(); + ReASVariant& val2 = thread.topOfValues(); switch(m_operator){ case BOP_PLUS: switch(val1.variantType()){ - case RplASVariant::VT_FLOAT: + case ReASVariant::VT_FLOAT: val1.setFloat(val1.asFloat() + val2.asFloat()); break; - case RplASVariant::VT_INTEGER: + case ReASVariant::VT_INTEGER: val1.setInt(val1.asInt() + val2.asInt()); break; - case RplASVariant::VT_OBJECT: - //if (val1.getClass() == RplASString::m_instance) + case ReASVariant::VT_OBJECT: + //if (val1.getClass() == ReASString::m_instance) default: error(thread.logger(), LOC_BINOP_CALC_2, "invalid type for '+': %s", val1.nameOfType()); @@ -3139,10 +3153,10 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_MINUS: switch(val1.variantType()){ - case RplASVariant::VT_FLOAT: + case ReASVariant::VT_FLOAT: val1.setFloat(val1.asFloat() - val2.asFloat()); break; - case RplASVariant::VT_INTEGER: + case ReASVariant::VT_INTEGER: val1.setInt(val1.asInt() - val2.asInt()); break; default: @@ -3153,10 +3167,10 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_TIMES: switch(val1.variantType()){ - case RplASVariant::VT_FLOAT: + case ReASVariant::VT_FLOAT: val1.setFloat(val1.asFloat() * val2.asFloat()); break; - case RplASVariant::VT_INTEGER: + case ReASVariant::VT_INTEGER: val1.setInt(val1.asInt() * val2.asInt()); break; default: @@ -3167,10 +3181,10 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_DIV: switch(val1.variantType()){ - case RplASVariant::VT_FLOAT: + case ReASVariant::VT_FLOAT: val1.setFloat(val1.asFloat() / val2.asFloat()); break; - case RplASVariant::VT_INTEGER: + case ReASVariant::VT_INTEGER: val1.setInt(val1.asInt() / val2.asInt()); break; default: @@ -3181,10 +3195,10 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_MOD: switch(val1.variantType()){ - case RplASVariant::VT_FLOAT: + case ReASVariant::VT_FLOAT: val1.setFloat(fmod(val1.asFloat(), val2.asFloat())); break; - case RplASVariant::VT_INTEGER: + case ReASVariant::VT_INTEGER: val1.setInt(val1.asInt() % val2.asInt()); break; default: @@ -3195,7 +3209,7 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_POWER: switch(val1.variantType()){ - case RplASVariant::VT_FLOAT: + case ReASVariant::VT_FLOAT: val1.setFloat(fmod(val1.asFloat(), val2.asFloat())); break; default: @@ -3206,7 +3220,7 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_LOG_OR: switch(val1.variantType()){ - case RplASVariant::VT_BOOL: + case ReASVariant::VT_BOOL: val1.setBool(val1.asBool() || val2.asBool()); break; default: @@ -3217,7 +3231,7 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_LOG_AND: switch(val1.variantType()){ - case RplASVariant::VT_BOOL: + case ReASVariant::VT_BOOL: val1.setBool(val1.asBool() && val2.asBool()); break; default: @@ -3228,7 +3242,7 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_LOG_XOR: switch(val1.variantType()){ - case RplASVariant::VT_BOOL: + case ReASVariant::VT_BOOL: val1.setBool(val1.asBool() != val2.asBool()); break; default: @@ -3239,7 +3253,7 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_BIT_OR: switch(val1.variantType()){ - case RplASVariant::VT_INTEGER: + case ReASVariant::VT_INTEGER: val1.setInt(val1.asInt() | val2.asInt()); break; default: @@ -3250,7 +3264,7 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_BIT_AND: switch(val1.variantType()){ - case RplASVariant::VT_INTEGER: + case ReASVariant::VT_INTEGER: val1.setInt(val1.asInt() & val2.asInt()); break; default: @@ -3261,7 +3275,7 @@ void RplASBinaryOp::calc(RplVMThread& thread) break; case BOP_BIT_XOR: switch(val1.variantType()){ - case RplASVariant::VT_INTEGER: + case ReASVariant::VT_INTEGER: val1.setInt(val1.asInt() ^ val2.asInt()); break; default: @@ -3285,7 +3299,7 @@ void RplASBinaryOp::calc(RplVMThread& thread) * @return true: node is correct
* false: otherwise */ -bool RplASBinaryOp::check(RplParser& parser) +bool ReASBinaryOp::check(ReParser& parser) { return false; } @@ -3295,7 +3309,7 @@ bool RplASBinaryOp::check(RplParser& parser) * * @return the operator */ -RplASBinaryOp::BinOperator RplASBinaryOp::getOperator() const +ReASBinaryOp::BinOperator ReASBinaryOp::getOperator() const { return m_operator; } @@ -3305,7 +3319,7 @@ RplASBinaryOp::BinOperator RplASBinaryOp::getOperator() const * * @param op the operator */ -void RplASBinaryOp::setOperator(BinOperator op) +void ReASBinaryOp::setOperator(BinOperator op) { m_operator = op; } @@ -3315,7 +3329,7 @@ void RplASBinaryOp::setOperator(BinOperator op) * @param writer writes to output * @param indent nesting level */ -void RplASBinaryOp::dump(RplWriter& writer, int indent) +void ReASBinaryOp::dump(ReWriter& writer, int indent) { const QByteArray& opName = nameOfOp(m_operator); @@ -3337,15 +3351,15 @@ void RplASBinaryOp::dump(RplWriter& writer, int indent) * * @param thread */ -void RplASBinaryOp::assign(RplVMThread& thread) +void ReASBinaryOp::assign(ReVMThread& thread) { - RplASVariant& rValue = thread.lValue(m_child); - RplASCalculable* expr = dynamic_cast(m_child2); + ReASVariant& rValue = thread.lValue(m_child); + ReASCalculable* expr = dynamic_cast(m_child2); if (expr == NULL) error(thread.logger(), LOC_BINOP_1, "not a calculable: id: %d", m_child2 == NULL ? 0 : m_child2->id()); else { - RplASVariant& value = thread.popValue(); + ReASVariant& value = thread.popValue(); switch(m_operator){ case BOP_ASSIGN: break; @@ -3379,7 +3393,7 @@ void RplASBinaryOp::assign(RplVMThread& thread) * * @return the name of the operator */ -const char* RplASBinaryOp::nameOfOp(RplASBinaryOp::BinOperator op) +const char* ReASBinaryOp::nameOfOp(ReASBinaryOp::BinOperator op) { const char* rc; switch (op){ @@ -3494,12 +3508,12 @@ const char* RplASBinaryOp::nameOfOp(RplASBinaryOp::BinOperator op) rc = ">"; break; default: - throw RplException("unknown binary op %d", (int) op); + throw ReException("unknown binary op %d", (int) op); } return rc; } -/** @class RplASMethod rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASMethod rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a method definition for the Abstract Syntax Tree. * @@ -3514,13 +3528,14 @@ const char* RplASBinaryOp::nameOfOp(RplASBinaryOp::BinOperator op) * @param name the method name * @param tree the abstract syntax tree */ -RplASMethod::RplASMethod(const QByteArray& name, RplASTree& tree) : - RplASNode2(AST_METHOD), +ReASMethod::ReASMethod(const QByteArray& name, ReASTree& tree) : + ReASNode2(AST_METHOD), m_name(name), m_resultType(NULL), m_symbols(NULL), m_sibling(NULL), - m_tree(tree) + m_tree(tree), + firstParamWithDefault(-1) { } @@ -3531,7 +3546,7 @@ RplASMethod::RplASMethod(const QByteArray& name, RplASTree& tree) : * @return true: node is correct
* false: otherwise */ -bool RplASMethod::check(RplParser& parser) +bool ReASMethod::check(ReParser& parser) { return false; } @@ -3541,7 +3556,7 @@ bool RplASMethod::check(RplParser& parser) * * This method will be never called. Must exit: Otherwise the class is abstract. */ -int RplASMethod::execute(RplVMThread& thread) +int ReASMethod::execute(ReVMThread& thread) { return 0; } @@ -3553,7 +3568,7 @@ int RplASMethod::execute(RplVMThread& thread) * @param writer writes to output * @param indent nesting level */ -void RplASMethod::dump(RplWriter& writer, int indent) +void ReASMethod::dump(ReWriter& writer, int indent) { char buffer[256]; @@ -3561,7 +3576,7 @@ void RplASMethod::dump(RplWriter& writer, int indent) writer.format("Method %s %s(", m_resultType == NULL ? "" : m_resultType->name().constData(), m_name.constData()); - RplSymbolSpace* parent = m_symbols->parent(); + ReSymbolSpace* parent = m_symbols->parent(); writer.formatLine(") id: %d parent: %s args: %d body: %d %s", m_id, parent == NULL ? "" : parent->name().constData(), m_child2 == NULL ? 0 : m_child2->id(), @@ -3577,7 +3592,7 @@ void RplASMethod::dump(RplWriter& writer, int indent) * * @return the symbol space */ -RplSymbolSpace* RplASMethod::symbols() const +ReSymbolSpace* ReASMethod::symbols() const { return m_symbols; } @@ -3585,7 +3600,7 @@ RplSymbolSpace* RplASMethod::symbols() const /** * @brief Sets the symbol space from the current of the tree. */ -void RplASMethod::setSymbols() +void ReASMethod::setSymbols() { m_symbols = m_tree.currentSpace(); } @@ -3594,7 +3609,7 @@ void RplASMethod::setSymbols() * @return the name */ -const QByteArray& RplASMethod::name() const +const QByteArray& ReASMethod::name() const { return m_name; } @@ -3605,18 +3620,18 @@ const QByteArray& RplASMethod::name() const * @return true: same signature
* false: otherwise */ -bool RplASMethod::equalSignature(RplASMethod& other) const +bool ReASMethod::equalSignature(ReASMethod& other) const { bool rc = true; - RplASExprStatement* args = dynamic_cast(m_child2); - RplASExprStatement* otherArgs = dynamic_cast(other.child2()); + ReASExprStatement* args = dynamic_cast(m_child2); + ReASExprStatement* otherArgs = dynamic_cast(other.child2()); while(rc && (args != NULL || otherArgs != NULL)){ if (args == NULL || otherArgs == NULL) rc = false; else { - RplASVarDefinition* def = dynamic_cast(args->child2()); - RplASVarDefinition* defOther = dynamic_cast(otherArgs->child2()); + ReASVarDefinition* def = dynamic_cast(args->child2()); + ReASVarDefinition* defOther = dynamic_cast(otherArgs->child2()); if (def->clazz() != defOther->clazz()) rc = false; } @@ -3629,7 +3644,7 @@ bool RplASMethod::equalSignature(RplASMethod& other) const * @return NULL: no other method available
* otherwise: the next method with the same name but another signature */ -RplASMethod* RplASMethod::sibling() const +ReASMethod* ReASMethod::sibling() const { return m_sibling; } @@ -3639,13 +3654,32 @@ RplASMethod* RplASMethod::sibling() const * * @param sibling another method with the same name but another signature */ -void RplASMethod::setSibling(RplASMethod* sibling) +void ReASMethod::setSibling(ReASMethod* sibling) { m_sibling = sibling; } +/** + * @brief Returns the index of the first parameter with a default value. + * + * @return -1: no parameter has a default value
+ * otherwise: the index of the first parameter with a default + */ +int ReASMethod::getFirstParamWithDefault() const +{ + return firstParamWithDefault; +} +/** + * @brief Sets the index of the first parameter with default value + * @param value + */ +void ReASMethod::setFirstParamWithDefault(int value) +{ + firstParamWithDefault = value; +} + -/** @class RplASField rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASField rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an class field for the Abstract Syntax Tree. * @@ -3657,8 +3691,8 @@ void RplASMethod::setSibling(RplASMethod* sibling) * * @param name name of the field */ -RplASField::RplASField(const QByteArray& name) : - RplASNode1(AST_FIELD), +ReASField::ReASField(const QByteArray& name) : + ReASNode1(AST_FIELD), m_name(name) { } @@ -3670,7 +3704,7 @@ RplASField::RplASField(const QByteArray& name) : * @return true: node is correct
* false: otherwise */ -bool RplASField::check(RplParser& parser) +bool ReASField::check(ReParser& parser) { return false; } @@ -3681,7 +3715,7 @@ bool RplASField::check(RplParser& parser) * @param writer writes to output * @param indent nesting level */ -void RplASField::dump(RplWriter& writer, int indent) +void ReASField::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "field %s id: %d parent: %d succ: %s", diff --git a/expr/ReASTree.hpp b/expr/ReASTree.hpp new file mode 100644 index 0000000..f7ec9f1 --- /dev/null +++ b/expr/ReASTree.hpp @@ -0,0 +1,759 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtwriterl.net/. + * The original sources can be found on https://github.com/republib. +*/ + + +#ifndef RPLASTREE_HPP +#define RPLASTREE_HPP + +enum ReASItemType { + AST_UNDEF, + AST_CONSTANT, + AST_LIST_CONSTANT, + AST_LIST_ENTRY, + AST_MAP_CONSTANT, + AST_MAP_ENTRY, + AST_NAMED_VALUE, + AST_CONVERSION, + AST_INDEXED_VALUE, + AST_FIELD, + AST_VAR_DEFINITION, + AST_EXPR_STATEMENT, + AST_METHOD, + AST_ARGUMENT, + AST_INTRINSIC_METHOD, + AST_PRE_UNARY_OP, + AST_POST_UNARY_OP, + AST_BINARY_OP, + AST_METHOD_CALL, + AST_WHILE, + AST_REPEAT, + AST_IF, + AST_CONDITION, + AST_ITERATED_FOR, + AST_COUNTED_FOR, + AST_SWITCH, + AST_LEAVE, + AST_CONTINUE +}; + +class ReASException : public ReException { +public: + ReASException(); + ReASException(const ReSourcePosition* position, const char* format, ...); +protected: + void build(const ReSourcePosition* position, const char* format, + va_list varList); +}; + +class ReASClass; +class ReASNamedValue; +class ReASItem; +class ReASCondition; + +class ReASVariant { + /* The VM uses some tricks (performance): Therefore this class + * must not be virtual! + */ +public: + enum VariantType { + VT_UNDEF, + VT_FLOAT, + VT_INTEGER, + VT_BOOL, + VT_OBJECT + }; + enum VariantFlags { + VF_UNDEF, + /// if DT_OBJECT: object is a copy, don't free at method end + VF_IS_COPY = 1 << 1, + /// debugger: action if changed + VF_WATCH_POINT = 1 << 2 + }; + + friend class ReASCondition; +public: + ReASVariant(); + ~ReASVariant(); + ReASVariant(const ReASVariant& source); + ReASVariant& operator=(const ReASVariant& source); + qreal asFloat() const; + int asInt() const; + bool asBool() const; + void* asObject(const ReASClass** clazz) const; + const QByteArray* asString() const; + void setFloat(qreal number); + void setInt(int integer); + void setBool(bool value); + void setObject(void* object, const ReASClass* clazz); + void setString(const QByteArray& string); + QByteArray toString(int maxLength = 80) const; + VariantType variantType() const; + const char* nameOfType() const; + const ReASClass* getClass() const; + void copyValue(const ReASVariant& source); + void destroyValue(); +private: + VariantType m_variantType:8; + /// bitmap of VF_... flags: + int m_flags:8; + union { + qreal m_float; + int m_int; + bool m_bool; + void* m_object; + } m_value; + const ReASClass* m_class; +}; + +class ReASTree; +class ReParser; +class ReVMThread; + +class ReASItem +{ +public: + enum NodeFlags { + NF_UNDEF, + /// the node calculates a value: + NF_CALCULABLE = 1 << 1, + /// the node calculates a value: + NF_STATEMENT = 1 << 2, + /// the tree under this node is complete checked for data type correctness + NF_TYPECHECK_COMPLETE = 1 << 3, + /// debugger: this node is a breakpoint + NF_BREAKPOINT = 1 << 5 + }; + +public: + friend class ReASTree; + ReASItem(ReASItemType type); + virtual ~ReASItem(); +public: + virtual bool check(ReParser& parser) = 0; +public: + bool checkAsCalculable(const char* description, ReASClass* expectedClass, + ReParser& parser); + const ReSourcePosition* position() const; + void setPosition(const ReSourcePosition* position); + unsigned int id() const; + char* positionStr(char buffer[], size_t bufferSize) const; + void error(ReLogger* logger, int location, const char* format, ...); +public: + /** + * @brief Writes the content of the instance into an output medium. + * + * @param writer writes to output media + * @param indent nesting level: so many tabs will be used as prefix + */ + virtual void dump(ReWriter& writer,int indent) = 0; +public: + static void reset(); + static bool checkStatementList(ReASItem* list, ReParser& parser); + static int calcAsInteger(ReASItem* expr, ReVMThread& thread); + static bool calcAsBoolean(ReASItem* expr, ReVMThread& thread); +public: + ReASItemType nodeType() const; + const char* nameOfItemType() const; + + int flags() const; + void setFlags(int flags); + + bool typeCheck(ReASClass* clazz1, ReASClass* clazz2); + bool error(int location, ReParser& parser, const char* format, ...); + bool ensureError(ReParser& parser, const char* info); +protected: + unsigned int m_id:16; + ReASItemType m_nodeType:8; + int m_flags:5; + int m_dataType: 3; + const ReSourcePosition* m_position; +private: + static unsigned int m_nextId; +}; + +class ReASNode1; +class ReASCalculable +{ +public: + ReASCalculable(); +public: + virtual void calc(ReVMThread& thread) = 0; +public: + ReASClass* clazz() const; + void setClass(ReASClass* clazz); +protected: + ReASClass* m_class; +}; + +class ReStackFrame; +class ReASStorable : public ReASCalculable { +}; +class ReVMThread; +class ReASConstant : public ReASItem, public ReASCalculable +{ +public: + ReASConstant(); +public: + virtual void calc(ReVMThread& thread); + virtual bool check(ReParser& parser); +public: + virtual void dump(ReWriter& writer,int indent); + ReASVariant& value(); +private: + ReASVariant m_value; +}; + + +class ReASNode1 : public ReASItem +{ +public: + ReASNode1(ReASItemType type); + virtual ~ReASNode1(); +public: + ReASItem* child() const; + void setChild(ReASItem* child); +public: + static void dumpStatements(ReWriter& writer, int indent, ReASItem* statements); +protected: + ReASItem* m_child; +}; + +class ReASNode2 : public ReASNode1 +{ +public: + ReASNode2(ReASItemType type); + virtual ~ReASNode2(); +public: + ReASItem* child2() const; + void setChild2(ReASItem* child2); + +protected: + ReASItem* m_child2; +}; + +class ReASNode3 : public ReASNode2 +{ +public: + ReASNode3(ReASItemType type); + virtual ~ReASNode3(); +public: + ReASItem* child3() const; + void setChild3(ReASItem* child3); + +protected: + ReASItem* m_child3; +}; + +class ReASNode4 : public ReASNode3 +{ +public: + ReASNode4(ReASItemType type); + virtual ~ReASNode4(); +public: + ReASItem* child4() const; + void setChild4(ReASItem* child4); + +protected: + ReASItem* m_child4; +}; + +class ReASNode5 : public ReASNode4 +{ +public: + ReASNode5(ReASItemType type); + virtual ~ReASNode5(); +public: + ReASItem*child5() const; + void setChild5(ReASItem* child5); +protected: + ReASItem* m_child5; +}; +class ReASNode6 : public ReASNode5 +{ +public: + ReASNode6(ReASItemType type); + virtual ~ReASNode6(); +public: + ReASItem*child6() const; + void setChild6(ReASItem* child5); +protected: + ReASItem* m_child6; +}; + +typedef QList ReASListOfVariants; +typedef QMap ReASMapOfVariants; + +class ReASListConstant : public ReASNode1, public ReASCalculable +{ +public: + ReASListConstant(); +public: + virtual void calc(ReVMThread& thread); + virtual bool check(ReParser& parser); + +public: + virtual void dump(ReWriter& writer,int indent); + ReASVariant& value(); + ReASListOfVariants* list(); +private: + ReASVariant m_value; +}; +class ReASMapConstant : public ReASNode1, public ReASCalculable +{ +public: + ReASMapConstant(); +public: + virtual void calc(ReVMThread& thread); + virtual bool check(ReParser& parser); +public: + virtual void dump(ReWriter& writer,int indent); + ReASVariant& value(); + ReASMapOfVariants* map(); +private: + ReASVariant m_value; +}; + +class ReSymbolSpace; +class ReASNamedValue : public ReASItem, public ReASStorable +{ + friend class ReASVarDefinition; +public: + enum Attributes { + A_NONE, + /// the value cannot be changed. + A_CONST = 1<<1, + /// the variable/constant is found in the global namespace, not in a method + A_GLOBAL = 1<<2, + /// the variable/constant is found in the module namespace, not in a method + A_MODULE_STATIC = 1<<3, + /// the evaluation should be lazy + A_LAZY = 1<<4, + /// parameter of a method + A_PARAM = 1<<5, + /// a automatic variable in counted for loops: + A_LOOP = 1<<6 + }; + +public: + ReASNamedValue(ReASClass* clazz, ReSymbolSpace* space, + const QByteArray& name, int attributes); +public: + virtual void calc(ReVMThread& thread); + virtual bool check(ReParser& parser); +public: + const QByteArray& name() const; + void setSymbolSpace(ReSymbolSpace* space, int variableNo); + void dump(ReWriter& writer, int indent); + ReSymbolSpace* symbolSpace() const; + int variableNo() const; + void setVariableNo(int variableNo); +protected: + QByteArray m_name; + int m_attributes; + ReSymbolSpace* m_symbolSpace; + int m_variableNo; +}; +class ReASConversion : public ReASNode1, public ReASCalculable { +public: + enum Conversion { + C_UNDEF, + C_INT_TO_FLOAT, + C_FLOAT_TO_INT, + C_BOOL_TO_INT, + C_BOOL_TO_FLOAT + }; + +public: + ReASConversion(ReASItem* expression); +public: + virtual void calc(ReVMThread& thread); + virtual bool check(ReParser& parser); + virtual void dump(ReWriter& writer,int indent); +public: + static ReASConversion* tryConversion(ReASClass* expected, ReASItem* expr, + ReParser& parser, bool& isCorrect); + static Conversion findConversion(ReASClass* from, ReASClass* to); +private: + Conversion m_conversion; +}; + +class ReASIndexedValue : public ReASNode2, public ReASCalculable { +public: + ReASIndexedValue(); +public: + virtual void calc(ReVMThread& thread); + virtual bool check(ReParser& parser); +public: + void dump(ReWriter& writer, int indent); +}; + +class ReASStatement +{ +public: + ReASStatement(); +public: + virtual int execute(ReVMThread& thread) = 0; +public: + static int executeStatementList(ReASItem* list, ReVMThread& thread); +}; + + +class ReASVarDefinition : public ReASNode3, public ReASStatement +{ +public: + ReASVarDefinition(); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); +public: + void dump(ReWriter& writer, int indent); + const QByteArray& name() const; + int endOfScope() const; + void setEndOfScope(int endOfScope); + ReASClass* clazz() const; +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 ReASItem::m_sourcePosition + int m_endOfScope; +}; + +class ReASExprStatement : public ReASNode2, public ReASStatement +{ +public: + ReASExprStatement(); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); +public: + void dump(ReWriter& writer, int indent); +}; + +class ReASUnaryOp : public ReASNode1, ReASCalculable +{ +public: + enum UnaryOp { + UOP_UNDEF, + UOP_PLUS, + UOP_MINUS_INT, + UOP_MINUS_FLOAT, + UOP_NOT_BOOL, + UOP_NOT_INT, + UOP_INC, + UOP_DEC + }; +public: + ReASUnaryOp(UnaryOp op, ReASItemType type); +public: + virtual void calc(ReVMThread& thread); + virtual bool check(ReParser& parser); +public: + int getOperator() const; + void dump(ReWriter& writer, int indent); +public: + static const char* nameOfOp(UnaryOp op); +private: + UnaryOp m_operator; +}; +class ReASBinaryOp : public ReASNode2, public ReASCalculable +{ +public: + enum BinOperator { + BOP_UNDEF, + BOP_ASSIGN, + BOP_PLUS_ASSIGN, + BOP_MINUS_ASSIGN, + BOP_TIMES_ASSIGN, + BOP_DIV_ASSIGN, + BOP_MOD_ASSIGN, + BOP_POWER_ASSIGN, + BOP_LOG_OR_ASSIGN, + BOP_LOG_AND_ASSIGN, + BOP_LOG_XOR_ASSIGN, + BOP_BIT_OR_ASSIGN, + BOP_BIT_AND_ASSIGN, + BOP_BIT_XOR_ASSIGN, + BOP_LSHIFT_ASSIGN, + BOP_LOG_RSHIFT_ASSIGN, + BOP_ARTITH_RSHIFT_ASSIGN, + BOP_PLUS, + BOP_MINUS, + BOP_TIMES, + BOP_DIV, + BOP_MOD, + BOP_POWER, + BOP_LOG_OR, + BOP_LOG_AND, + BOP_LOG_XOR, + BOP_BIT_OR, + BOP_BIT_AND, + BOP_BIT_XOR, + BOP_LSHIFT, + BOP_LOG_RSHIFT, + BOP_ARTITH_RSHIFT, + BOP_EQ, + BOP_NE, + BOP_LE, + BOP_LT, + BOP_GE, + BOP_GT, + BOB_COUNT + }; +private: + inline bool isAssignment() const { + return m_operator >= BOP_ASSIGN + && m_operator <= BOP_ARTITH_RSHIFT_ASSIGN; + } +public: + ReASBinaryOp(); +public: + virtual void calc(ReVMThread& thread); + virtual bool check(ReParser& parser); +public: + BinOperator getOperator() const; + void setOperator(BinOperator op); + void dump(ReWriter& writer, int indent); +private: + void assign(ReVMThread& thread); +public: + static const char* nameOfOp(BinOperator op); +private: + BinOperator m_operator; +}; + +class ReASIf : public ReASNode4, public ReASStatement +{ +public: + ReASIf(); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); + virtual void dump(ReWriter& writer, int indent); +}; + +class ReASForIterated : public ReASNode4, public ReASStatement +{ +public: + ReASForIterated(ReASVarDefinition* variable); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); + virtual void dump(ReWriter& writer, int indent); +}; + +class ReASForCounted : public ReASNode6, public ReASStatement +{ +public: + ReASForCounted(ReASVarDefinition* variable); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); + virtual void dump(ReWriter& writer, int indent); +}; + +class ReASWhile : public ReASNode3, public ReASStatement +{ +public: + ReASWhile(); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); + virtual void dump(ReWriter& writer, int indent); +}; + +class ReASRepeat : public ReASNode3, public ReASStatement +{ +public: + ReASRepeat(); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); + virtual void dump(ReWriter& writer, int indent); +}; + +class ReASMethod; +class ReASMethodCall : public ReASNode3, public ReASStatement +{ +public: + ReASMethodCall(const QByteArray& name, ReASItem* parent); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); +public: + void dump(ReWriter& writer, int indent); + +public: + ReASMethod* method() const; + void setMethod(ReASMethod* method); + + ReASExprStatement* arg1() const; +private: + QByteArray m_name; + ReASMethod* m_method; +}; + +class RplParameter : ReASItem +{ +public: + RplParameter(); + virtual ~RplParameter(); +private: + QByteArray m_name; + ReASNamedValue* m_default; +}; + +class ReASField : public ReASNode1 +{ +public: + ReASField(const QByteArray& name); +public: + virtual bool check(ReParser& parser); +public: + void dump(ReWriter& writer, int indent); +private: + QByteArray m_name; +}; + + +class ReASClass; +class ReSymbolSpace; +class ReASMethod : public ReASNode2 +{ +public: + ReASMethod(const QByteArray& name, ReASTree& tree); +public: + virtual bool check(ReParser& parser); + virtual int execute(ReVMThread& thread); +public: + void dump(ReWriter& writer, int indent); + ReSymbolSpace* symbols() const; + void setSymbols(); + const QByteArray& name() const; + bool equalSignature(ReASMethod& other) const; + ReASMethod* sibling() const; + void setSibling(ReASMethod* sibling); + int getFirstParamWithDefault() const; + void setFirstParamWithDefault(int value); + +private: + QByteArray m_name; + ReASClass* m_resultType; + ReSymbolSpace* m_symbols; + // chain over all overloaded methods (same name, other signature): + ReASMethod* m_sibling; + ReASTree& m_tree; + // -1: no parameter with default value. >= 0: index of the first + int firstParamWithDefault; +}; + +class ReASClass { +public: + typedef QMap MethodMap; +public: + ReASClass(const QByteArray& name, ReASTree& m_tree); + virtual ~ReASClass(); +public: + /** + * @brief Creates a value object (used in ReASVariant). + * + * @param source NULL or a source to copy + * @return a new value object (specific for the class) + */ + virtual void* newValueInstance(void* source = NULL) const = 0; + /** + * @brief Destroys the given object. + * + * The object must be created by newValueInstance(). + * + * @param object object to destroy + */ + virtual void destroyValueInstance(void* object) const = 0; + /** + * @brief Returns the boolean value of a class specific value. + * + * Example: the boolean value of an the empty string is false + * + * @param object object to test + * @return false: the object represents the false value
+ * true: otherwise + */ + virtual bool boolValueOf(void* object) const = 0; + /** + * @brief Returns a string representation of an instance. + * + * @param object the object to convert + * @param maxLength the maximum length of the result (string) + * @return a string describing the object + */ + virtual QByteArray toString(void *object, int maxLength = 80) const = 0; +public: + const QByteArray& name() const; + virtual void dump(ReWriter& writer, int indent); + void setSymbols(); +protected: + QByteArray m_name; + ReSymbolSpace* m_symbols; + const ReASClass* m_superClass; + ReASTree& m_tree; +}; + +#include "rplexpr/rplasclasses.hpp" + +#include "ReParser.hpp" +class ReSymbolSpace; +class ReASTree +{ +public: + enum { + DMP_NONE, + DMP_GLOBALS = 1<<1, + DMP_MODULES = 1<<2, + DMP_SPACE_STACK = 1<<3, + DMP_SPACE_HEAP = 1<<4, + DMP_ALL = DMP_GLOBALS | DMP_MODULES | DMP_SPACE_STACK | DMP_SPACE_HEAP, + DMP_NO_GLOBALS = DMP_MODULES | DMP_SPACE_STACK | DMP_SPACE_HEAP + }; + typedef QMap SymbolSpaceMap; + typedef QList SymbolSpaceStack; +public: + ReASTree(); + ~ReASTree(); +public: + bool startModule(ReSourceUnitName name); + void finishModule(ReSourceUnitName name); + ReSymbolSpace* startClassOrMethod(const QByteArray& name, + ReSymbolSpace::SymbolSpaceType type); + void finishClassOrMethod(const QByteArray& name); + SymbolSpaceStack& symbolSpaces(); + ReSymbolSpace* currentSpace() const; + ReASClass* findClass(const QByteArray& name); + void clear(); + void dump(const char* filename, int flags = DMP_ALL, + const char* header = NULL); + ReSymbolSpace*findmodule(const QByteArray& name); + ReSourcePosition* copyPosition(); + ReByteStorage& store(); + +protected: + void init(); + void destroy(); +private: + // the mother of all symbol spaces. + ReSymbolSpace* m_global; + // contains all hit modules + SymbolSpaceMap m_modules; + // nested modules (import), classes and methods build this stack: + SymbolSpaceStack m_symbolSpaces; + // top of the stack: + ReSymbolSpace* m_currentSpace; + // contain all ever built symbol spaces: + SymbolSpaceMap m_symbolSpaceHeap; + ReByteStorage m_store; +}; + +#endif // RPLASTREE_HPP diff --git a/rplexpr/rplasclasses.cpp b/expr/ReAsClasses.cpp similarity index 69% rename from rplexpr/rplasclasses.cpp rename to expr/ReAsClasses.cpp index 11f21d6..2d607b5 100644 --- a/rplexpr/rplasclasses.cpp +++ b/expr/ReAsClasses.cpp @@ -7,26 +7,26 @@ */ /** @file - * @brief Predefined classes of the virtual machine, e.g RplASInteger. + * @brief Predefined classes of the virtual machine, e.g ReASInteger. */ /** @file rplexpr/rplasclasses.hpp * * @brief Definitions for predefined classes of the virtual machine. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/ReExpr.hpp" -RplASList* RplASList::m_instance = NULL; -RplASMap* RplASMap::m_instance = NULL; -RplASFloat* RplASFloat::m_instance = NULL; -RplASInteger* RplASInteger::m_instance = NULL; -RplASString* RplASString::m_instance = NULL; -RplASBoolean* RplASBoolean::m_instance = NULL; -RplASVoid* RplASVoid::m_instance = NULL; -RplASFormula* RplASFormula::m_instance = NULL; +ReASList* ReASList::m_instance = NULL; +ReASMap* ReASMap::m_instance = NULL; +ReASFloat* ReASFloat::m_instance = NULL; +ReASInteger* ReASInteger::m_instance = NULL; +ReASString* ReASString::m_instance = NULL; +ReASBoolean* ReASBoolean::m_instance = NULL; +ReASVoid* ReASVoid::m_instance = NULL; +ReASFormula* ReASFormula::m_instance = NULL; -/** @class RplSymbolSpace rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReSymbolSpace rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a symbol space for the parser. * @@ -56,7 +56,7 @@ RplASFormula* RplASFormula::m_instance = NULL; * @param name the symbol space's name * @param parent the parent of the symbol space */ -RplSymbolSpace::RplSymbolSpace(RplASTree& tree) : +ReSymbolSpace::ReSymbolSpace(ReASTree& tree) : m_type(SST_GLOBAL), m_name("$global"), m_variables(), @@ -74,9 +74,9 @@ RplSymbolSpace::RplSymbolSpace(RplASTree& tree) : * @param name the symbol space's name * @param parent the parent of the symbol space */ -RplSymbolSpace::RplSymbolSpace(RplSymbolSpace::SymbolSpaceType type, +ReSymbolSpace::ReSymbolSpace(ReSymbolSpace::SymbolSpaceType type, const QByteArray& name, - RplSymbolSpace* parent) : + ReSymbolSpace* parent) : m_type(type), m_name(name), m_variables(), @@ -92,7 +92,7 @@ RplSymbolSpace::RplSymbolSpace(RplSymbolSpace::SymbolSpaceType type, /** * @brief Destructor. */ -RplSymbolSpace::~RplSymbolSpace() +ReSymbolSpace::~ReSymbolSpace() { ClassMap::iterator it; for (it = m_classes.begin(); it != m_classes.end(); it++){ @@ -114,7 +114,7 @@ RplSymbolSpace::~RplSymbolSpace() * * @param scope OUT: status info */ -void RplSymbolSpace::startScope(RplASScope& scope) +void ReSymbolSpace::startScope(ReASScope& scope) { scope.m_varNoAtStart = m_listOfVars.size(); } @@ -128,13 +128,13 @@ void RplSymbolSpace::startScope(RplASScope& scope) * scope * @param scope the status of the scope at start. */ -void RplSymbolSpace::finishScope(int endOfScope, RplASScope& scope) +void ReSymbolSpace::finishScope(int endOfScope, ReASScope& scope) { // in methods/classes not needed: int ix = scope.m_varNoAtStart - scope.m_builtInVars; int last = m_listOfVars.size(); for (; ix < last; ix++){ - RplASVarDefinition* var = m_listOfVars[ix]; + ReASVarDefinition* var = m_listOfVars[ix]; var->setEndOfScope(endOfScope); const QByteArray& name = var->name(); if (m_variables.contains(name)) @@ -150,9 +150,9 @@ void RplSymbolSpace::finishScope(int endOfScope, RplASScope& scope) * @return NULL: not found
* otherwise: the variable */ -RplASVarDefinition* RplSymbolSpace::findVariable(const QByteArray& name) const +ReASVarDefinition* ReSymbolSpace::findVariable(const QByteArray& name) const { - RplASVarDefinition* rc = NULL; + ReASVarDefinition* rc = NULL; if (m_variables.contains(name)) rc = m_variables[name]; else if (m_parent != NULL) @@ -167,9 +167,9 @@ RplASVarDefinition* RplSymbolSpace::findVariable(const QByteArray& name) const * @return NULL: not found
* otherwise: the class */ -RplASClass* RplSymbolSpace::findClass(const QByteArray& name) const +ReASClass* ReSymbolSpace::findClass(const QByteArray& name) const { - RplASClass* rc = NULL; + ReASClass* rc = NULL; if (m_classes.contains(name)) rc = m_classes[name]; else if (m_parent != NULL) @@ -184,9 +184,9 @@ RplASClass* RplSymbolSpace::findClass(const QByteArray& name) const * @return NULL: method not found * otherwise: the method description */ -RplASMethod* RplSymbolSpace::findMethod(const QByteArray& name) const +ReASMethod* ReSymbolSpace::findMethod(const QByteArray& name) const { - RplASMethod* rc = NULL; + ReASMethod* rc = NULL; if (m_methods.contains(name)) rc = m_methods[name]; return rc; @@ -199,7 +199,7 @@ RplASMethod* RplSymbolSpace::findMethod(const QByteArray& name) const * @param indent nesting level: so many tabs will be used as prefix * @param header NULL or the headline */ -void RplSymbolSpace::dump(RplWriter& writer, int indent, const char* header) +void ReSymbolSpace::dump(ReWriter& writer, int indent, const char* header) { if (header != NULL) writer.writeLine(header); @@ -217,7 +217,7 @@ void RplSymbolSpace::dump(RplWriter& writer, int indent, const char* header) qSort(sorted.begin(), sorted.end(), qLess()); QList::iterator it2; for (it2 = sorted.begin(); it2 != sorted.end(); it2++){ - RplASClass* clazz = m_classes[*it2]; + ReASClass* clazz = m_classes[*it2]; clazz->dump(writer, indent); } } @@ -232,7 +232,7 @@ void RplSymbolSpace::dump(RplWriter& writer, int indent, const char* header) qSort(sorted.begin(), sorted.end(), qLess()); QList::iterator it4; for (it4 = sorted.begin(); it4 != sorted.end(); it4++){ - RplASMethod* method = m_methods[*it4]; + ReASMethod* method = m_methods[*it4]; do { method->dump(writer, indent); method = method->sibling(); @@ -244,13 +244,13 @@ void RplSymbolSpace::dump(RplWriter& writer, int indent, const char* header) writer.writeIndented(indent, "== Variables:"); QList::iterator it6; for (int ix = 0; ix < m_listOfVars.size(); ix++){ - RplASVarDefinition* var = m_listOfVars[ix]; + ReASVarDefinition* var = m_listOfVars[ix]; var->dump(writer, indent); } } if (m_body != NULL){ writer.writeIndented(indent, "== Body:"); - RplASNode1::dumpStatements(writer, indent, m_body); + ReASNode1::dumpStatements(writer, indent, m_body); } } @@ -260,8 +260,8 @@ void RplSymbolSpace::dump(RplWriter& writer, int indent, const char* header) * @param type type to inspect * @return the name of the type */ -const char*RplSymbolSpace::spaceTypeName( - RplSymbolSpace::SymbolSpaceType type) +const char*ReSymbolSpace::spaceTypeName( + ReSymbolSpace::SymbolSpaceType type) { const char* rc = NULL; switch(type){ @@ -293,26 +293,26 @@ const char*RplSymbolSpace::spaceTypeName( * @param tree the abstract syntax tree * @return the global symbol space */ -RplSymbolSpace* RplSymbolSpace::createGlobal(RplASTree& tree) +ReSymbolSpace* ReSymbolSpace::createGlobal(ReASTree& tree) { - RplSymbolSpace* rc = new RplSymbolSpace(tree); + ReSymbolSpace* rc = new ReSymbolSpace(tree); rc->m_tree = tree; - RplASInteger::m_instance = new RplASInteger(tree); - rc->m_classes[RplASInteger::m_instance->name()] = RplASInteger::m_instance; - RplASBoolean::m_instance = new RplASBoolean(tree); - rc->m_classes[RplASBoolean::m_instance->name()] = RplASBoolean::m_instance; - RplASFloat::m_instance = new RplASFloat(tree); - rc->m_classes[RplASFloat::m_instance->name()] = RplASFloat::m_instance; - RplASString::m_instance = new RplASString(tree); - rc->m_classes[RplASString::m_instance->name()] = RplASString::m_instance; - RplASList::m_instance = new RplASList(tree); - rc->m_classes[RplASList::m_instance->name()] = RplASList::m_instance; - RplASMap::m_instance = new RplASMap(tree); - rc->m_classes[RplASMap::m_instance->name()] = RplASMap::m_instance; - RplASVoid::m_instance = new RplASVoid(tree); - rc->m_classes[RplASVoid::m_instance->name()] = RplASVoid::m_instance; - RplASFormula::m_instance = new RplASFormula(tree); - rc->m_classes[RplASFormula::m_instance->name()] = RplASFormula::m_instance; + ReASInteger::m_instance = new ReASInteger(tree); + rc->m_classes[ReASInteger::m_instance->name()] = ReASInteger::m_instance; + ReASBoolean::m_instance = new ReASBoolean(tree); + rc->m_classes[ReASBoolean::m_instance->name()] = ReASBoolean::m_instance; + ReASFloat::m_instance = new ReASFloat(tree); + rc->m_classes[ReASFloat::m_instance->name()] = ReASFloat::m_instance; + ReASString::m_instance = new ReASString(tree); + rc->m_classes[ReASString::m_instance->name()] = ReASString::m_instance; + ReASList::m_instance = new ReASList(tree); + rc->m_classes[ReASList::m_instance->name()] = ReASList::m_instance; + ReASMap::m_instance = new ReASMap(tree); + rc->m_classes[ReASMap::m_instance->name()] = ReASMap::m_instance; + ReASVoid::m_instance = new ReASVoid(tree); + rc->m_classes[ReASVoid::m_instance->name()] = ReASVoid::m_instance; + ReASFormula::m_instance = new ReASFormula(tree); + rc->m_classes[ReASFormula::m_instance->name()] = ReASFormula::m_instance; return rc; } /** @@ -320,7 +320,7 @@ RplSymbolSpace* RplSymbolSpace::createGlobal(RplASTree& tree) * * @return the list of the variables */ -RplSymbolSpace::VariableList RplSymbolSpace::listOfVars() const +ReSymbolSpace::VariableList ReSymbolSpace::listOfVars() const { return m_listOfVars; } @@ -331,7 +331,7 @@ RplSymbolSpace::VariableList RplSymbolSpace::listOfVars() const * @return the symbolspace of the object (module, method, class..) containing * the object belonging to the instance */ -RplSymbolSpace* RplSymbolSpace::parent() const +ReSymbolSpace* ReSymbolSpace::parent() const { return m_parent; } @@ -342,7 +342,7 @@ RplSymbolSpace* RplSymbolSpace::parent() const * @return NULL: no body available
* othewise: the body of the instance */ -RplASItem* RplSymbolSpace::body() const +ReASItem* ReSymbolSpace::body() const { return m_body; } @@ -352,7 +352,7 @@ RplASItem* RplSymbolSpace::body() const * * @param body the new body */ -void RplSymbolSpace::setBody(RplASItem* body) +void ReSymbolSpace::setBody(ReASItem* body) { m_body = body; } @@ -365,9 +365,9 @@ void RplSymbolSpace::setBody(RplASItem* body) * @return NULL: success
* otherwise: the already defined variable/method */ -RplASItem* RplSymbolSpace::addVariable(RplASVarDefinition* variable, int& varNo) +ReASItem* ReSymbolSpace::addVariable(ReASVarDefinition* variable, int& varNo) { - RplASItem* rc = NULL; + ReASItem* rc = NULL; const QByteArray& name = variable->name(); if (m_variables.contains(name)) rc = m_variables[name]; @@ -388,17 +388,17 @@ RplASItem* RplSymbolSpace::addVariable(RplASVarDefinition* variable, int& varNo) * @return NULL: success
* otherwise: the already defined variable/method */ -RplASItem* RplSymbolSpace::addMethod(RplASMethod* method) +ReASItem* ReSymbolSpace::addMethod(ReASMethod* method) { - RplASItem* rc = NULL; + ReASItem* rc = NULL; const QByteArray& name = method->name(); if (m_variables.contains(name)) rc = m_variables[name]; else if (! m_methods.contains(name)){ m_methods[name] = method; } else { - RplASMethod* first = m_methods[name]; - RplASMethod* oldMethod = first; + ReASMethod* first = m_methods[name]; + ReASMethod* oldMethod = first; do { if (oldMethod->equalSignature(*method)) rc = oldMethod; @@ -419,12 +419,12 @@ RplASItem* RplSymbolSpace::addMethod(RplASMethod* method) * @return NULL: success
* otherwise: the already defined class */ -RplASUserClass* RplSymbolSpace::addClass(RplASUserClass* clazz) +ReASUserClass* ReSymbolSpace::addClass(ReASUserClass* clazz) { - RplASUserClass* rc = NULL; + ReASUserClass* rc = NULL; const QByteArray& name = clazz->name(); if (m_classes.contains(name)){ - rc = dynamic_cast(m_classes[name]); + rc = dynamic_cast(m_classes[name]); } else { m_classes[name] = clazz; } @@ -436,13 +436,13 @@ RplASUserClass* RplSymbolSpace::addClass(RplASUserClass* clazz) * * @return the name */ -const QByteArray& RplSymbolSpace::name() const +const QByteArray& ReSymbolSpace::name() const { return m_name; } -/** @class RplASBoolean rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASBoolean rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the class of a Boolean. * @@ -451,19 +451,19 @@ const QByteArray& RplSymbolSpace::name() const /** * @brief Constructor. */ -RplASBoolean::RplASBoolean(RplASTree& tree) : - RplASClass("Bool", tree) +ReASBoolean::ReASBoolean(ReASTree& tree) : + ReASClass("Bool", tree) { } /** - * @brief Creates a value object (used in RplASVariant). + * @brief Creates a value object (used in ReASVariant). * * For Booleans nothing is to do! * * @param source NULL or a source to copy * @return NULL */ -void* RplASBoolean::newValueInstance(void*) const +void* ReASBoolean::newValueInstance(void*) const { return NULL; } @@ -475,7 +475,7 @@ void* RplASBoolean::newValueInstance(void*) const * * @param object object to destroy */ -void RplASBoolean::destroyValueInstance(void*) const +void ReASBoolean::destroyValueInstance(void*) const { } @@ -487,7 +487,7 @@ void RplASBoolean::destroyValueInstance(void*) const * @param object the object to test (with type QList*) * @return false */ -bool RplASBoolean::boolValueOf(void*) const +bool ReASBoolean::boolValueOf(void*) const { return false; } @@ -499,12 +499,12 @@ bool RplASBoolean::boolValueOf(void*) const * @param maxLength not used * @return a string describing the object */ -QByteArray RplASBoolean::toString(void* object, int) const +QByteArray ReASBoolean::toString(void* object, int) const { - return ((RplASVariant*) object)->asBool() ? "True" : "False"; + return ((ReASVariant*) object)->asBool() ? "True" : "False"; } -/** @class RplASNumber rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASNumber rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the class of a Boolean. * @@ -513,25 +513,25 @@ QByteArray RplASBoolean::toString(void* object, int) const /** * @brief Constructor. */ -RplASFloat::RplASFloat(RplASTree& tree) : - RplASClass("Float", tree) +ReASFloat::ReASFloat(ReASTree& tree) : + ReASClass("Float", tree) { } -RplASFloat::RplASFloat(const QByteArray& name, RplASTree& tree) : - RplASClass(name, tree) +ReASFloat::ReASFloat(const QByteArray& name, ReASTree& tree) : + ReASClass(name, tree) { - m_superClass = RplASFloat::m_instance; + m_superClass = ReASFloat::m_instance; } /** - * @brief Creates a value object (used in RplASVariant). + * @brief Creates a value object (used in ReASVariant). * * For Booleans nothing is to do! * * @param source NULL or a source to copy * @return NULL */ -void* RplASFloat::newValueInstance(void*) const +void* ReASFloat::newValueInstance(void*) const { return NULL; } @@ -543,7 +543,7 @@ void* RplASFloat::newValueInstance(void*) const * * @param object object to destroy */ -void RplASFloat::destroyValueInstance(void*) const +void ReASFloat::destroyValueInstance(void*) const { } @@ -555,7 +555,7 @@ void RplASFloat::destroyValueInstance(void*) const * @param object the object to test * @return false */ -bool RplASFloat::boolValueOf(void*) const +bool ReASFloat::boolValueOf(void*) const { return false; } @@ -567,15 +567,15 @@ bool RplASFloat::boolValueOf(void*) const * @param maxLength not used * @return a string describing the object */ -QByteArray RplASFloat::toString(void* object, int) const +QByteArray ReASFloat::toString(void* object, int) const { char buffer[256]; - qsnprintf(buffer, sizeof buffer, "%f", ((RplASVariant *) object)->asFloat()); + qsnprintf(buffer, sizeof buffer, "%f", ((ReASVariant *) object)->asFloat()); return buffer; } -/** @class RplASInteger rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASInteger rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the class of a Boolean. * @@ -584,8 +584,8 @@ QByteArray RplASFloat::toString(void* object, int) const /** * @brief Constructor. */ -RplASInteger::RplASInteger(RplASTree& tree) : - RplASFloat("Int", tree) +ReASInteger::ReASInteger(ReASTree& tree) : + ReASFloat("Int", tree) { } @@ -597,7 +597,7 @@ RplASInteger::RplASInteger(RplASTree& tree) : * @param object the object to test * @return false */ -bool RplASInteger::boolValueOf(void*) const +bool ReASInteger::boolValueOf(void*) const { return false; } @@ -609,16 +609,16 @@ bool RplASInteger::boolValueOf(void*) const * @param maxLength the maximum length of the result * @return a string describing the object */ -QByteArray RplASInteger::toString(void* object, int maxLength) const +QByteArray ReASInteger::toString(void* object, int maxLength) const { char buffer[64]; qsnprintf(buffer, sizeof buffer, "%.*d", maxLength, - ((RplASVariant *) object)->asInt()); + ((ReASVariant *) object)->asInt()); return buffer; } -/** @class RplASString rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASString rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the class of a string. * @@ -627,17 +627,17 @@ QByteArray RplASInteger::toString(void* object, int maxLength) const /** * @brief Constructor. */ -RplASString::RplASString(RplASTree& tree) : - RplASClass("Str", tree) +ReASString::ReASString(ReASTree& tree) : + ReASClass("Str", tree) { } /** - * @brief Creates a value object (used in RplASVariant). + * @brief Creates a value object (used in ReASVariant). * * @param source NULL or a source to copy * @return a new value object (specific for the class) */ -void* RplASString::newValueInstance(void* source) const +void* ReASString::newValueInstance(void* source) const { QByteArray* rc = source == NULL ? new QByteArray() : new QByteArray(*(QByteArray*) source); return (void*) rc; @@ -650,7 +650,7 @@ void* RplASString::newValueInstance(void* source) const * * @param object object to destroy */ -void RplASString::destroyValueInstance(void* object) const +void ReASString::destroyValueInstance(void* object) const { delete (QByteArray*) object; } @@ -664,13 +664,13 @@ void RplASString::destroyValueInstance(void* object) const * @return false: the string is empty * true: otherwise */ -bool RplASString::boolValueOf(void* object) const +bool ReASString::boolValueOf(void* object) const { bool rc = false; if (object != NULL){ QByteArray* string = static_cast(object); if (string == NULL) - throw RplException("RplASString.boolValueOf(): not a string"); + throw ReException("ReASString.boolValueOf(): not a string"); rc = ! string->isEmpty(); } return rc; @@ -683,7 +683,7 @@ bool RplASString::boolValueOf(void* object) const * @param maxLength the maximum length of the result * @return a string describing the object */ -QByteArray RplASString::toString(void* object, int maxLength) const +QByteArray ReASString::toString(void* object, int maxLength) const { QByteArray rc; QByteArray* string = reinterpret_cast (object); @@ -702,7 +702,7 @@ QByteArray RplASString::toString(void* object, int maxLength) const return rc; } -/** @class RplASList rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASList rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the class of a list. * @@ -711,29 +711,29 @@ QByteArray RplASString::toString(void* object, int maxLength) const /** * @brief Constructor. */ -RplASList::RplASList(RplASTree& tree) : - RplASClass("List", tree) +ReASList::ReASList(ReASTree& tree) : + ReASClass("List", tree) { } /** - * @brief Creates a value object (used in RplASVariant). + * @brief Creates a value object (used in ReASVariant). * * @param source NULL or a source to copy * @return a new value object (specific for the class) */ -void* RplASList::newValueInstance(void* source) const +void* ReASList::newValueInstance(void* source) const { - RplASListOfVariants* rc = new RplASListOfVariants(); + ReASListOfVariants* rc = new ReASListOfVariants(); if (source != NULL){ - RplASListOfVariants* source2 = (RplASListOfVariants*) source; + ReASListOfVariants* source2 = (ReASListOfVariants*) source; rc->reserve(source2->size()); - RplASListOfVariants::iterator it; + ReASListOfVariants::iterator it; for (it = source2->begin(); it != source2->end(); it++){ // deleting in destroyValue(): - rc->append(new RplASVariant(*(*it))); + rc->append(new ReASVariant(*(*it))); } } return (void*) rc; @@ -746,9 +746,9 @@ void* RplASList::newValueInstance(void* source) const * * @param object object to destroy */ -void RplASList::destroyValueInstance(void* object) const +void ReASList::destroyValueInstance(void* object) const { - delete static_cast(object); + delete static_cast(object); } /** @@ -758,13 +758,13 @@ void RplASList::destroyValueInstance(void* object) const * @return false: the list is empty
* true: otherwise */ -bool RplASList::boolValueOf(void* object) const +bool ReASList::boolValueOf(void* object) const { bool rc = false; if (object != NULL){ - RplASListOfVariants* list = static_cast(object); + ReASListOfVariants* list = static_cast(object); if (list == NULL) - throw RplException("RplASList.boolValueOf(): not a list"); + throw ReException("ReASList.boolValueOf(): not a list"); rc = ! list->empty(); } return rc; @@ -777,13 +777,13 @@ bool RplASList::boolValueOf(void* object) const * @param maxLength unused * @return a string describing the object */ -QByteArray RplASList::toString(void* object, int maxLength) const +QByteArray ReASList::toString(void* object, int maxLength) const { QByteArray rc; rc.reserve(maxLength); rc += "["; - RplASListOfVariants* list = reinterpret_cast(object); - RplASListOfVariants::iterator it; + ReASListOfVariants* list = reinterpret_cast(object); + ReASListOfVariants::iterator it; bool first = true; for(it = list->begin(); it != list->end(); it++){ if (first) @@ -803,7 +803,7 @@ QByteArray RplASList::toString(void* object, int maxLength) const return rc; } -/** @class RplASMap rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASMap rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements the class of a map. * @@ -813,28 +813,28 @@ QByteArray RplASList::toString(void* object, int maxLength) const /** * @brief Constructor. */ -RplASMap::RplASMap(RplASTree& tree) : - RplASClass("Map", tree) +ReASMap::ReASMap(ReASTree& tree) : + ReASClass("Map", tree) { } /** - * @brief Creates a value object (used in RplASVariant). + * @brief Creates a value object (used in ReASVariant). * * @param source NULL or a source to copy * @return a new value object (specific for the class) */ -void* RplASMap::newValueInstance(void* source) const +void* ReASMap::newValueInstance(void* source) const { - RplASMapOfVariants* rc = new RplASMapOfVariants(); + ReASMapOfVariants* rc = new ReASMapOfVariants(); if (source != NULL){ - RplASMapOfVariants* source2 = - static_cast(source); + ReASMapOfVariants* source2 = + static_cast(source); // rc->reserve(source2->size()); - RplASMapOfVariants::iterator it; + ReASMapOfVariants::iterator it; for (it = source2->begin(); it != source2->end(); it++){ // deleting in destroyValue(): const QByteArray& key = it.key(); - RplASVariant* value = new RplASVariant(*it.value()); + ReASVariant* value = new ReASVariant(*it.value()); (*rc)[key] = value; } } @@ -848,9 +848,9 @@ void* RplASMap::newValueInstance(void* source) const * * @param object object to destroy */ -void RplASMap::destroyValueInstance(void* object) const +void ReASMap::destroyValueInstance(void* object) const { - delete (RplASMapOfVariants*) object; + delete (ReASMapOfVariants*) object; } /** @@ -859,13 +859,13 @@ void RplASMap::destroyValueInstance(void* object) const * @param object the object to test (with type QMap*) * @return */ -bool RplASMap::boolValueOf(void* object) const +bool ReASMap::boolValueOf(void* object) const { bool rc = false; if (object != NULL){ - RplASMapOfVariants* map = reinterpret_cast(object); + ReASMapOfVariants* map = reinterpret_cast(object); if (map == NULL) - throw RplException("RplASMap.boolValueOf(): not a map"); + throw ReException("ReASMap.boolValueOf(): not a map"); rc = map->empty() > 0; } return rc; @@ -878,13 +878,13 @@ bool RplASMap::boolValueOf(void* object) const * @param maxLength maximal length of the result * @return a string describing the object */ -QByteArray RplASMap::toString(void* object, int maxLength) const +QByteArray ReASMap::toString(void* object, int maxLength) const { QByteArray rc; rc.reserve(maxLength); rc += "["; - RplASMapOfVariants* map = reinterpret_cast(object); - RplASMapOfVariants::iterator it; + ReASMapOfVariants* map = reinterpret_cast(object); + ReASMapOfVariants::iterator it; bool first = true; for(it = map->begin(); it != map->end(); it++){ if (first) @@ -913,7 +913,7 @@ QByteArray RplASMap::toString(void* object, int maxLength) const } -/** @class RplVariable rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReVariable rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a variable of a symbol space. */ @@ -921,7 +921,7 @@ QByteArray RplASMap::toString(void* object, int maxLength) const /** * @brief Constructor. */ -RplVariable::RplVariable(const QByteArray& name) : +ReVariable::ReVariable(const QByteArray& name) : m_name(name), m_namespace(NULL), m_value(), @@ -936,7 +936,7 @@ RplVariable::RplVariable(const QByteArray& name) : * @param writer writes to output * @param indent nesting level: so many tabs will be used as prefix */ -void RplVariable::dump(RplWriter& writer, int indent) +void ReVariable::dump(ReWriter& writer, int indent) { const char* name1 = m_type == NULL ? "NoneType" : m_type->name().constData(); QByteArray val = m_value.toString(); @@ -948,7 +948,7 @@ void RplVariable::dump(RplWriter& writer, int indent) * * @return the class of the variable */ -RplASClass* RplVariable::type() const +ReASClass* ReVariable::type() const { return m_type; } @@ -957,7 +957,7 @@ RplASClass* RplVariable::type() const * @brief Sets the data type. * @param type the class of the variable */ -void RplVariable::setType(RplASClass* type) +void ReVariable::setType(ReASClass* type) { m_type = type; } @@ -966,17 +966,17 @@ void RplVariable::setType(RplASClass* type) * * @return the name */ -const QByteArray& RplVariable::name() const +const QByteArray& ReVariable::name() const { return m_name; } -/** @class RplVariable rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReVariable rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a data type representing a none type. */ -RplASVoid::RplASVoid(RplASTree& tree) : - RplASClass("Void", tree) +ReASVoid::ReASVoid(ReASTree& tree) : + ReASClass("Void", tree) { } @@ -988,7 +988,7 @@ RplASVoid::RplASVoid(RplASTree& tree) : * @param source ignored * @return */ -void*RplASVoid::newValueInstance(void*) const +void*ReASVoid::newValueInstance(void*) const { return NULL; } @@ -1000,7 +1000,7 @@ void*RplASVoid::newValueInstance(void*) const * * @param object not used */ -void RplASVoid::destroyValueInstance(void*) const +void ReASVoid::destroyValueInstance(void*) const { } @@ -1009,7 +1009,7 @@ void RplASVoid::destroyValueInstance(void*) const * @param object ignored * @return false */ -bool RplASVoid::boolValueOf(void*) const +bool ReASVoid::boolValueOf(void*) const { return false; } @@ -1021,12 +1021,12 @@ bool RplASVoid::boolValueOf(void*) const * @param maxLength ignored * @return the empty string */ -QByteArray RplASVoid::toString(void*, int) const +QByteArray ReASVoid::toString(void*, int) const { return QByteArray(""); } -/** @class RplASFormula rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASFormula rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a data type representing a calculated value. */ @@ -1036,8 +1036,8 @@ QByteArray RplASVoid::toString(void*, int) const * * @param tree the abstract syntax tree */ -RplASFormula::RplASFormula(RplASTree& tree) : - RplASClass("Formula", tree) +ReASFormula::ReASFormula(ReASTree& tree) : + ReASClass("Formula", tree) { } @@ -1049,7 +1049,7 @@ RplASFormula::RplASFormula(RplASTree& tree) : * @param expr the result * @return */ -void* RplASFormula::newValueInstance(void* expr) const +void* ReASFormula::newValueInstance(void* expr) const { return expr; } @@ -1061,7 +1061,7 @@ void* RplASFormula::newValueInstance(void* expr) const * * @param object not used */ -void RplASFormula::destroyValueInstance(void*) const +void ReASFormula::destroyValueInstance(void*) const { } @@ -1070,7 +1070,7 @@ void RplASFormula::destroyValueInstance(void*) const * @param object ignored * @return false */ -bool RplASFormula::boolValueOf(void*) const +bool ReASFormula::boolValueOf(void*) const { return false; } @@ -1082,16 +1082,16 @@ bool RplASFormula::boolValueOf(void*) const * @param maxLength ignored * @return the empty string */ -QByteArray RplASFormula::toString(void* object, int) const +QByteArray ReASFormula::toString(void* object, int) const { - RplASExprStatement* expr = static_cast(object); + ReASExprStatement* expr = static_cast(object); char buffer[64]; qsnprintf(buffer, sizeof buffer, "", expr->id()); return buffer; } -/** @class RplASUserClass rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASUserClass rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements a data type representing an user defined class. */ @@ -1104,10 +1104,10 @@ QByteArray RplASFormula::toString(void* object, int) const * @param position the position of the class definition * @param tree the abstract syntax tree */ -RplASUserClass::RplASUserClass(const QByteArray& name, - const RplSourcePosition* position, - RplASTree& tree) : - RplASClass(name, tree), +ReASUserClass::ReASUserClass(const QByteArray& name, + const ReSourcePosition* position, + ReASTree& tree) : + ReASClass(name, tree), m_position(position) { } @@ -1118,16 +1118,16 @@ RplASUserClass::RplASUserClass(const QByteArray& name, * @param source the type (user defined class) of the result * @return an instance of an user defined class */ -void*RplASUserClass::newValueInstance(void* source) const +void*ReASUserClass::newValueInstance(void* source) const { - RplASUserClass* clazz = static_cast(source); - RplASUserObject* rc = new RplASUserObject(clazz); + ReASUserClass* clazz = static_cast(source); + ReASUserObject* rc = new ReASUserObject(clazz); return static_cast(rc); } -void RplASUserClass::destroyValueInstance(void* object) const +void ReASUserClass::destroyValueInstance(void* object) const { - RplASUserObject* obj = static_cast(object); + ReASUserObject* obj = static_cast(object); delete obj; } @@ -1138,7 +1138,7 @@ void RplASUserClass::destroyValueInstance(void* object) const * @return true: object != NULL
* false: object == NULL */ -bool RplASUserClass::boolValueOf(void* object) const +bool ReASUserClass::boolValueOf(void* object) const { return object != NULL; } @@ -1150,7 +1150,7 @@ bool RplASUserClass::boolValueOf(void* object) const * @param maxLength maximum length of the string * @return */ -QByteArray RplASUserClass::toString(void*, int) const +QByteArray ReASUserClass::toString(void*, int) const { return m_name; } @@ -1159,18 +1159,18 @@ QByteArray RplASUserClass::toString(void*, int) const * * @return the source position */ -const RplSourcePosition* RplASUserClass::position() const +const ReSourcePosition* ReASUserClass::position() const { return m_position; } -/** @class RplASUserObject rplastree.hpp "rplexpr/rplastree.hpp" +/** @class ReASUserObject rplastree.hpp "rplexpr/rplastree.hpp" * * @brief Implements an instance of an user defined class. */ -RplASUserObject::RplASUserObject(RplASUserClass* clazz) : +ReASUserObject::ReASUserObject(ReASUserClass* clazz) : m_class(clazz), m_fields(NULL) { @@ -1179,7 +1179,7 @@ RplASUserObject::RplASUserObject(RplASUserClass* clazz) : /** * @brief Destructor. */ -RplASUserObject::~RplASUserObject() +ReASUserObject::~ReASUserObject() { delete[] m_fields; m_fields = NULL; diff --git a/rplexpr/rplasclasses.hpp b/expr/ReAsClasses.hpp similarity index 53% rename from rplexpr/rplasclasses.hpp rename to expr/ReAsClasses.hpp index fbb5df2..53f3f90 100644 --- a/rplexpr/rplasclasses.hpp +++ b/expr/ReAsClasses.hpp @@ -10,35 +10,35 @@ #ifndef RPLASCLASSES_HPP #define RPLASCLASSES_HPP -class RplSymbolSpace; -class RplVariable { +class ReSymbolSpace; +class ReVariable { public: - RplVariable(const QByteArray& name); + ReVariable(const QByteArray& name); public: - void dump(RplWriter& writer, int indent); + void dump(ReWriter& writer, int indent); - RplASClass* type() const; - void setType(RplASClass* type); + ReASClass* type() const; + void setType(ReASClass* type); const QByteArray& name() const; protected: QByteArray m_name; // NULL for "simple" variables (int, float, bool) - RplSymbolSpace* m_namespace; - RplASVariant m_value; - RplASClass* m_type; + ReSymbolSpace* m_namespace; + ReASVariant m_value; + ReASClass* m_type; }; -class RplASScope +class ReASScope { public: int m_builtInVars; int m_varNoAtStart; }; -class RplASUserClass; -class RplASTree; -class RplSymbolSpace +class ReASUserClass; +class ReASTree; +class ReSymbolSpace { public: enum SymbolSpaceType { @@ -50,165 +50,165 @@ public: }; public: - typedef QMap VariableMap; - typedef QMap ClassMap; - typedef QMap MethodMap; - typedef QList VariableList; + typedef QMap VariableMap; + typedef QMap ClassMap; + typedef QMap MethodMap; + typedef QList VariableList; private: - RplSymbolSpace(RplASTree& tree); -public: - RplSymbolSpace(SymbolSpaceType type, const QByteArray& name, - RplSymbolSpace* parent); - virtual ~RplSymbolSpace(); -public: - void startScope(RplASScope& scope); - void finishScope(int endOfScope, RplASScope& scope); - RplASVarDefinition* findVariable(const QByteArray& name) const; - RplASClass* findClass(const QByteArray& name) const; - RplASMethod* findMethod(const QByteArray& name) const; - void dump(RplWriter& writer, int indent, const char* header = NULL); + ReSymbolSpace(ReASTree& tree); +public: + ReSymbolSpace(SymbolSpaceType type, const QByteArray& name, + ReSymbolSpace* parent); + virtual ~ReSymbolSpace(); +public: + void startScope(ReASScope& scope); + void finishScope(int endOfScope, ReASScope& scope); + ReASVarDefinition* findVariable(const QByteArray& name) const; + ReASClass* findClass(const QByteArray& name) const; + ReASMethod* findMethod(const QByteArray& name) const; + void dump(ReWriter& writer, int indent, const char* header = NULL); const QByteArray& name() const; - RplASItem* body() const; - void setBody(RplASItem* body); - RplASItem* addVariable(RplASVarDefinition* variable, int& varNo); - RplASItem* addMethod(RplASMethod* method); - RplASUserClass* addClass(RplASUserClass* clazz); - RplSymbolSpace* parent() const; + ReASItem* body() const; + void setBody(ReASItem* body); + ReASItem* addVariable(ReASVarDefinition* variable, int& varNo); + ReASItem* addMethod(ReASMethod* method); + ReASUserClass* addClass(ReASUserClass* clazz); + ReSymbolSpace* parent() const; VariableList listOfVars() const; public: static const char* spaceTypeName(SymbolSpaceType type); - static RplSymbolSpace* createGlobal(RplASTree& tree); + static ReSymbolSpace* createGlobal(ReASTree& tree); private: SymbolSpaceType m_type; QByteArray m_name; VariableMap m_variables; ClassMap m_classes; MethodMap m_methods; - RplSymbolSpace* m_parent; - RplASItem* m_body; + ReSymbolSpace* m_parent; + ReASItem* m_body; VariableList m_listOfVars; - RplASTree& m_tree; + ReASTree& m_tree; }; -class RplASBoolean : public RplASClass { +class ReASBoolean : public ReASClass { public: - RplASBoolean(RplASTree& tree); + ReASBoolean(ReASTree& tree); public: void* newValueInstance(void* source = NULL) const; void destroyValueInstance(void* object) const; virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; public: - static RplASBoolean* m_instance; + static ReASBoolean* m_instance; }; -class RplASFloat : public RplASClass { +class ReASFloat : public ReASClass { public: - RplASFloat(RplASTree& tree); - RplASFloat(const QByteArray& name, RplASTree& tree); + ReASFloat(ReASTree& tree); + ReASFloat(const QByteArray& name, ReASTree& tree); public: void* newValueInstance(void* source = NULL) const; void destroyValueInstance(void* object) const; virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; public: - static RplASFloat* m_instance; + static ReASFloat* m_instance; }; -class RplASInteger : public RplASFloat { +class ReASInteger : public ReASFloat { public: - RplASInteger(RplASTree& tree); + ReASInteger(ReASTree& tree); public: virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; public: - static RplASInteger* m_instance; + static ReASInteger* m_instance; }; -class RplASString : public RplASClass { +class ReASString : public ReASClass { public: - RplASString(RplASTree& tree); + ReASString(ReASTree& tree); public: void* newValueInstance(void* source = NULL) const; void destroyValueInstance(void* object) const; virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; public: - static RplASString* m_instance; + static ReASString* m_instance; }; -class RplASList : public RplASClass { +class ReASList : public ReASClass { public: - RplASList(RplASTree& tree); + ReASList(ReASTree& tree); public: void* newValueInstance(void* source = NULL) const; void destroyValueInstance(void* object) const; virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; public: - static RplASList* m_instance; + static ReASList* m_instance; }; -class RplASMap : public RplASClass { +class ReASMap : public ReASClass { public: - RplASMap(RplASTree& tree); + ReASMap(ReASTree& tree); public: void* newValueInstance(void* source = NULL) const; void destroyValueInstance(void* object) const; virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; public: - static RplASMap* m_instance; + static ReASMap* m_instance; }; -class RplASVoid : public RplASClass { +class ReASVoid : public ReASClass { public: - RplASVoid(RplASTree& tree); + ReASVoid(ReASTree& tree); public: void* newValueInstance(void* source = NULL) const; void destroyValueInstance(void* object) const; virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; public: - static RplASVoid* m_instance; + static ReASVoid* m_instance; }; -class RplASFormula : public RplASClass { +class ReASFormula : public ReASClass { public: - RplASFormula(RplASTree& tree); + ReASFormula(ReASTree& tree); public: void* newValueInstance(void* source = NULL) const; void destroyValueInstance(void* object) const; virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; public: - static RplASFormula* m_instance; + static ReASFormula* m_instance; }; -class RplASUserClass : public RplASClass { +class ReASUserClass : public ReASClass { public: - RplASUserClass(const QByteArray& name, const RplSourcePosition* position, - RplASTree& tree); + ReASUserClass(const QByteArray& name, const ReSourcePosition* position, + ReASTree& tree); public: void* newValueInstance(void* source = NULL) const; void destroyValueInstance(void* object) const; virtual bool boolValueOf(void* object) const; virtual QByteArray toString(void *object, int maxLength = 80) const; - const RplSourcePosition* position() const; + const ReSourcePosition* position() const; private: - const RplSourcePosition* m_position; + const ReSourcePosition* m_position; }; -class RplASUserObject { +class ReASUserObject { public: - RplASUserObject(RplASUserClass* clazz); - ~RplASUserObject(); + ReASUserObject(ReASUserClass* clazz); + ~ReASUserObject(); public: void callMember(); private: - RplASUserClass* m_class; - RplASVariant* m_fields; + ReASUserClass* m_class; + ReASVariant* m_fields; }; #endif // RPLASCLASSES_HPP diff --git a/rplexpr/rpllexer.cpp b/expr/ReLexer.cpp similarity index 90% rename from rplexpr/rpllexer.cpp rename to expr/ReLexer.cpp index 1366cf8..986ebc6 100644 --- a/rplexpr/rpllexer.cpp +++ b/expr/ReLexer.cpp @@ -6,19 +6,19 @@ * The original sources can be found on https://github.com/republib. */ /** @file - * @brief Configurable scanner, wich separates syntactic symbols from an input media. + * @brief Configurable scanner, which separates syntactic symbols from an input media. */ -/** @file rplexpr/rpllexer.hpp +/** @file expr/ReLexer.hpp * @brief Definitions for a configurable lexical analyser. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" #define CHAR_INFO_SIZE (int(sizeof m_charInfo / sizeof m_charInfo[0])) -/** @class RplToken rpllexer.hpp "rplexpr/rpllexer.hpp" +/** @class ReToken ReLexer.hpp "expr/ReLexer.hpp" * * @brief Implements specific exception for the lexer. * @@ -31,9 +31,9 @@ * @param format the reason of the exception * @param ... the values for the placeholders in the format. */ -RplLexException::RplLexException(const RplSourcePosition& position, +ReLexException::ReLexException(const ReSourcePosition& position, const char* format, ...) : - RplException("") + ReException("") { char buffer[64000]; m_message = position.toString().toUtf8(); @@ -44,7 +44,7 @@ RplLexException::RplLexException(const RplSourcePosition& position, m_message += buffer; } -/** @class RplToken rpllexer.hpp "rplexpr/rpllexer.hpp" +/** @class ReToken ReLexer.hpp "expr/ReLexer.hpp" * * @brief Implements a token which is the smallest unit for a parser. * @@ -53,7 +53,7 @@ RplLexException::RplLexException(const RplSourcePosition& position, * @brief Constructor. * @param type token type */ -RplToken::RplToken(RplTokenType type) : +ReToken::ReToken(RplTokenType type) : m_tokenType(type), m_string(), m_printableString() @@ -65,7 +65,7 @@ RplToken::RplToken(RplTokenType type) : /** * @brief Destructor. */ -RplToken::~RplToken() +ReToken::~ReToken() { } /** @@ -73,7 +73,7 @@ RplToken::~RplToken() * * @param source source to copy */ -RplToken::RplToken(const RplToken& source) : +ReToken::ReToken(const ReToken& source) : m_tokenType(source.m_tokenType), m_string(source.m_string), m_printableString(source.m_printableString), @@ -86,7 +86,7 @@ RplToken::RplToken(const RplToken& source) : * @param source source to copy * @return */ -RplToken& RplToken::operator =(const RplToken& source) +ReToken& ReToken::operator =(const ReToken& source) { m_tokenType = source.m_tokenType; m_string = source.m_string; @@ -98,7 +98,7 @@ RplToken& RplToken::operator =(const RplToken& source) * @brief Returns the string representation of the instance * @return a string representing the instance */ -const QByteArray& RplToken::toString() +const QByteArray& ReToken::toString() { return m_string; } @@ -110,7 +110,7 @@ const QByteArray& RplToken::toString() * * @return the value of the token as integer */ -int RplToken::asInteger() const +int ReToken::asInteger() const { return (int) m_value.m_integer; } @@ -122,7 +122,7 @@ int RplToken::asInteger() const * * @return the value of the token as unsigned integer (64 bit) */ -quint64 RplToken::asUInt64() const +quint64 ReToken::asUInt64() const { return m_value.m_integer; } @@ -134,7 +134,7 @@ quint64 RplToken::asUInt64() const * * @return the value of the token as floating point value */ -qreal RplToken::asReal() const +qreal ReToken::asReal() const { return m_value.m_real; } @@ -146,7 +146,7 @@ qreal RplToken::asReal() const * * @return the value of the token as floating point value */ -const QByteArray& RplToken::rawString() const +const QByteArray& ReToken::rawString() const { return m_printableString; } @@ -159,7 +159,7 @@ const QByteArray& RplToken::rawString() const * * @return the id of the token */ -int RplToken::id() const +int ReToken::id() const { return m_value.m_id; } @@ -167,7 +167,7 @@ int RplToken::id() const * @brief Returns the token type. * @return the token type */ -RplTokenType RplToken::tokenType() const +RplTokenType ReToken::tokenType() const { return m_tokenType; } @@ -180,7 +180,7 @@ RplTokenType RplToken::tokenType() const * @return true: the expected type is the current
* false: otherwise */ -bool RplToken::isTokenType(RplTokenType expected) const +bool ReToken::isTokenType(RplTokenType expected) const { return m_tokenType == expected; } @@ -194,7 +194,7 @@ bool RplToken::isTokenType(RplTokenType expected) const * @return true: the instance is an operator and the expected or the alternative
* false: otherwise */ -bool RplToken::isOperator(int expected, int alternative) const +bool ReToken::isOperator(int expected, int alternative) const { return m_tokenType == TOKEN_OPERATOR && (m_value.m_id == expected || m_value.m_id == alternative); @@ -210,7 +210,7 @@ bool RplToken::isOperator(int expected, int alternative) const * false: otherwise */ -bool RplToken::isKeyword(int expected, int alternative) const +bool ReToken::isKeyword(int expected, int alternative) const { return m_tokenType == TOKEN_KEYWORD && (m_value.m_id == expected || m_value.m_id == alternative); @@ -219,7 +219,7 @@ bool RplToken::isKeyword(int expected, int alternative) const /** * @brief Makes all members undefined. */ -void RplToken::clear() +void ReToken::clear() { m_string.clear(); m_printableString.clear(); @@ -233,7 +233,7 @@ void RplToken::clear() * @return true: the token is an id and the first char is an upper case char
* false: otherwise */ -bool RplToken::isCapitalizedId() const +bool ReToken::isCapitalizedId() const { bool rc = m_tokenType == TOKEN_ID && isupper(m_string.at(0)) && (m_string.length() == 1 || islower(m_string.at(1))); @@ -245,14 +245,14 @@ bool RplToken::isCapitalizedId() const * * @return a description of the instance */ -QByteArray RplToken::dump() const +QByteArray ReToken::dump() const { QByteArray rc; rc = nameOfType(m_tokenType); rc.append(": ").append(this->asUtf8()); return rc; } -QByteArray RplToken::asUtf8() const +QByteArray ReToken::asUtf8() const { char buffer[4096]; buffer[0] = '\0'; @@ -293,7 +293,7 @@ QByteArray RplToken::asUtf8() const * @param type the type to convert * @return the token type name */ -const char* RplToken::nameOfType(RplTokenType type) +const char* ReToken::nameOfType(RplTokenType type) { const char* rc = "?"; @@ -341,7 +341,7 @@ const char* RplToken::nameOfType(RplTokenType type) } -/** @class RplLexer rpllexer.hpp "rplexpr/rpllexer.hpp" +/** @class ReLexer ReLexer.hpp "expr/ReLexer.hpp" * * @brief Implements a lexical analyser. * @@ -350,7 +350,7 @@ const char* RplToken::nameOfType(RplTokenType type) * */ -static void itemsToVector(const char* items, RplLexer::StringList& vector, +static void itemsToVector(const char* items, ReLexer::StringList& vector, int firstCharFlag, int secondCharFlag, int thirdCharFlag, int restCharFlag, int charInfo[]) @@ -401,7 +401,7 @@ static void charClassToCharInfo(const char* charClass, int flag, if (ubound == '\0') charInfo['-'] |= flag; else if (cc >= ubound) - throw new RplException("wrong character class range: %c-%c (%s)", + throw new ReException("wrong character class range: %c-%c (%s)", cc, ubound, charClass); else { for (int ii = cc + 1; ii <= ubound; ii++){ @@ -438,7 +438,7 @@ static void charClassToCharInfo(const char* charClass, int flag, * @param storageFlags describes the things which should be stored, e.g. * S_ORG_STRINGS | S_COMMENTS | S_BLANKS */ -RplLexer::RplLexer(RplSource* source, +ReLexer::ReLexer(ReSource* source, const char* keywords, const char* operators, const char* rightAssociatives, const char* comments, @@ -490,7 +490,7 @@ RplLexer::RplLexer(RplSource* source, /** * @brief Destructor. */ -RplLexer::~RplLexer() +ReLexer::~ReLexer() { } @@ -518,7 +518,7 @@ int countBlanks(const char* start, const char* end){ * '\n' separates the operators with the same priority. * Lower position means lower priority */ -void RplLexer::prepareOperators(const char* operators, +void ReLexer::prepareOperators(const char* operators, const char* rightAssociatives){ QByteArray op2(operators); QByteArray rightAssociatives2(" "); @@ -567,7 +567,7 @@ void RplLexer::prepareOperators(const char* operators, } } -void RplLexer::initializeComments(const char* comments) +void ReLexer::initializeComments(const char* comments) { if (comments != NULL) { @@ -575,7 +575,7 @@ void RplLexer::initializeComments(const char* comments) QByteArray comments2(comments); int ix = comments2.indexOf(" "); if (ix >= 0) - throw RplException("more than one blank between comment pair(s): col %d %s", + throw ReException("more than one blank between comment pair(s): col %d %s", ix + 1, comments + ix); // the index of m_commentEnds is the position number: we need a dummy entry: m_commentEnds.append(""); @@ -593,7 +593,7 @@ void RplLexer::initializeComments(const char* comments) } } if (ix % 2 != 0) - throw RplException("not only pairs in the comment list"); + throw ReException("not only pairs in the comment list"); itemsToVector(starters, m_commentStarts, CC_FIRST_COMMENT_START, CC_2nd_COMMENT_START, CC_3rd_COMMENT_START, CC_REST_COMMENT_START, m_charInfo); @@ -608,7 +608,7 @@ void RplLexer::initializeComments(const char* comments) * @param id the id of the entry in the vector. Only set if found * @return */ -int RplLexer::findInVector(int tokenLength, const StringList& vector) +int ReLexer::findInVector(int tokenLength, const StringList& vector) { int id = 0; int lbound = 0; @@ -653,7 +653,7 @@ int RplLexer::findInVector(int tokenLength, const StringList& vector) * @return false: no more input is available
* true: data are available */ -bool RplLexer::fillInput() +bool ReLexer::fillInput() { if (m_hasMoreInput){ if (m_input.size() < m_maxTokenLength){ @@ -682,7 +682,7 @@ bool RplLexer::fillInput() * @return NULL: not found
* otherwise: the token */ -RplToken* RplLexer::findTokenWithId(RplTokenType tokenType, int flag2, +ReToken* ReLexer::findTokenWithId(RplTokenType tokenType, int flag2, StringList& names) { int length = 1; @@ -711,7 +711,7 @@ RplToken* RplLexer::findTokenWithId(RplTokenType tokenType, int flag2, } } } - RplToken* rc = NULL; + ReToken* rc = NULL; if (! (tokenType == TOKEN_KEYWORD && length < inputLength && (cc = m_input[length]) < CHAR_INFO_SIZE && (m_charInfo[cc] & CC_REST_ID))) { @@ -742,7 +742,7 @@ RplToken* RplLexer::findTokenWithId(RplTokenType tokenType, int flag2, * * @return the token with the number */ -RplToken* RplLexer::scanNumber() +ReToken* ReLexer::scanNumber() { int inputLength = m_input.size(); int cc; @@ -751,11 +751,11 @@ RplToken* RplLexer::scanNumber() if ( (cc = m_input[0]) == '0' && inputLength > 1 && (m_numericTypes & NUMTYPE_HEXADECIMAL) && (m_input[1] == 'x' || m_input[1] == 'X')){ - length = RplString::lengthOfUInt64(m_input.constData() + 2, 16, &value); + length = ReStringUtil::lengthOfUInt64(m_input.constData() + 2, 16, &value); if (length > 0) length += 2; else - throw RplException("invalid hexadecimal number: no digit behind 'x"); + throw ReException("invalid hexadecimal number: no digit behind 'x"); } else if (cc == '0' && (m_numericTypes & NUMTYPE_OCTAL) && inputLength > 1){ length = 1; @@ -763,7 +763,7 @@ RplToken* RplLexer::scanNumber() if ( (cc = m_input[length]) >= '0' && cc <= '7') value = value * 8 + cc - '0'; else if (cc >= '8' && cc <= '9') - throw RplLexException(*m_currentPosition, + throw ReLexException(*m_currentPosition, "invalid octal digit: %c", cc); else break; @@ -785,7 +785,7 @@ RplToken* RplLexer::scanNumber() if (length + 1 < inputLength && ((cc = m_input[length]) == '.' || toupper(cc) == 'E')){ qreal realValue; - int realLength = RplString::lengthOfReal(m_input.constData(), &realValue); + int realLength = ReStringUtil::lengthOfReal(m_input.constData(), &realValue); if (realLength > length){ m_currentToken->m_tokenType = TOKEN_REAL; m_currentToken->m_value.m_real = realValue; @@ -801,7 +801,7 @@ RplToken* RplLexer::scanNumber() * @brief Reads a string into the internal data. * @return the token with the string */ -RplToken*RplLexer::scanString() +ReToken*ReLexer::scanString() { int delim = m_input[0]; int inputLength = m_input.size(); @@ -819,22 +819,22 @@ RplToken*RplLexer::scanString() m_currentToken->m_string.append(QChar(cc)); } else { if (length >= inputLength) - throw RplLexException(*m_currentPosition, + throw ReLexException(*m_currentPosition, "backslash without following character"); cc = m_input[length++]; if ( (m_stringFeatures & SF_C_HEX_CHARS) && toupper(cc) == 'X'){ if (length >= inputLength) - throw RplLexException(*m_currentPosition, + throw ReLexException(*m_currentPosition, "missing hexadecimal digit behind \\x"); cc = m_input[length++]; - int hexVal = RplQString::valueOfHexDigit(cc); + int hexVal = ReQString::valueOfHexDigit(cc); if (hexVal < 0) - throw RplLexException(*m_currentPosition, + throw ReLexException(*m_currentPosition, "not a hexadecimal digit behind \\x: %lc", QChar(cc)); if (length < inputLength){ cc = m_input[length]; - int nibble = RplQString::valueOfHexDigit(cc); + int nibble = ReQString::valueOfHexDigit(cc); if (nibble >= 0){ length++; hexVal = hexVal * 16 + nibble; @@ -893,7 +893,7 @@ RplToken*RplLexer::scanString() * * precondition: the current token is prepared yet */ -void RplLexer::scanComment() +void ReLexer::scanComment() { int inputLength = m_input.size(); int length = 1; @@ -911,7 +911,7 @@ void RplLexer::scanComment() m_currentToken->m_string.append(m_input); m_input.clear(); if (! fillInput()) - throw RplLexException(*m_currentPosition, + throw ReLexException(*m_currentPosition, "comment end not found"); } length = ix + commentEnd.size(); @@ -923,12 +923,12 @@ void RplLexer::scanComment() m_currentCol += length; } #if defined (RPL_LEXER_TRACE) -bool RplLexer::trace() const +bool ReLexer::trace() const { return m_trace; } -void RplLexer::setTrace(bool trace) +void ReLexer::setTrace(bool trace) { m_trace = trace; } @@ -938,7 +938,7 @@ void RplLexer::setTrace(bool trace) * * @return the current token */ -RplToken* RplLexer::currentToken() const +ReToken* ReLexer::currentToken() const { return m_currentToken; } @@ -948,7 +948,7 @@ RplToken* RplLexer::currentToken() const * * @return the current source code position */ -const RplSourcePosition* RplLexer::currentPosition() const +const ReSourcePosition* ReLexer::currentPosition() const { return m_currentPosition; } @@ -958,9 +958,9 @@ const RplSourcePosition* RplLexer::currentPosition() const * * @return the next token */ -RplToken* RplLexer::nextToken() +ReToken* ReLexer::nextToken() { - RplToken* rc = NULL; + ReToken* rc = NULL; int ix; if (m_waitingToken != NULL){ rc = m_currentToken = m_waitingToken; @@ -971,7 +971,7 @@ RplToken* RplLexer::nextToken() m_waitingPosition2 = NULL; } else { m_currentToken->clear(); - RplReader* reader = m_source->currentReader(); + ReReader* reader = m_source->currentReader(); if (reader == NULL) m_currentToken->m_tokenType = TOKEN_END_OF_SOURCE; else { @@ -1001,7 +1001,7 @@ RplToken* RplLexer::nextToken() rc = scanString(); } else { if (cc >= CHAR_INFO_SIZE) - throw RplLexException(*m_currentPosition, + throw ReLexException(*m_currentPosition, "no lexical symbol can start with this char: %lc", cc); else @@ -1054,7 +1054,7 @@ RplToken* RplLexer::nextToken() rc->m_tokenType = TOKEN_END_OF_SOURCE; } else { QByteArray symbol = m_input.mid(0, qMin(20, m_input.size()-1)); - throw RplLexException(*m_currentPosition, + throw ReLexException(*m_currentPosition, "unknown lexical symbol: %s", symbol.constData()); } } @@ -1074,7 +1074,7 @@ RplToken* RplLexer::nextToken() * * Makes that nextToken() returns the current token again. */ -void RplLexer::undoLastToken() +void ReLexer::undoLastToken() { m_waitingToken = m_currentToken; m_currentToken = m_currentToken == &m_token1 ? &m_token2 : &m_token1; @@ -1096,7 +1096,7 @@ void RplLexer::undoLastToken() * * Makes that nextToken() returns the current token again. */ -void RplLexer::undoLastToken2() +void ReLexer::undoLastToken2() { m_waitingToken2 = m_currentToken; m_waitingToken = m_currentToken == &m_token1 ? &m_token2 : &m_token1; @@ -1115,7 +1115,7 @@ void RplLexer::undoLastToken2() *
* Then token1 and token2 contains the wanted content. */ -void RplLexer::saveLastToken() +void ReLexer::saveLastToken() { if (m_waitingToken == NULL) m_currentToken = m_currentToken == &m_token1 ? &m_token2 : &m_token1; @@ -1126,9 +1126,9 @@ void RplLexer::saveLastToken() * * @return the next token which is not a space/comment */ -RplToken*RplLexer::peekNonSpaceToken() +ReToken*ReLexer::peekNonSpaceToken() { - RplToken* token = nextNonSpaceToken(); + ReToken* token = nextNonSpaceToken(); undoLastToken(); return token; } @@ -1136,7 +1136,7 @@ RplToken*RplLexer::peekNonSpaceToken() * @brief Returns the maximal length of a token * @return the maximal length of a token */ -size_t RplLexer::maxTokenLength() const +size_t ReLexer::maxTokenLength() const { return m_maxTokenLength; } @@ -1146,18 +1146,18 @@ size_t RplLexer::maxTokenLength() const * * @param maxTokenLength the new maximal length of a token */ -void RplLexer::setMaxTokenLength(size_t maxTokenLength) +void ReLexer::setMaxTokenLength(size_t maxTokenLength) { m_maxTokenLength = maxTokenLength; } /** - * @brief RplLexer::nextNonSpaceToken + * @brief ReLexer::nextNonSpaceToken * @return */ -RplToken* RplLexer::nextNonSpaceToken() +ReToken* ReLexer::nextNonSpaceToken() { - RplToken* rc = NULL; + ReToken* rc = NULL; RplTokenType type; do{ rc = nextToken(); @@ -1177,7 +1177,7 @@ RplToken* RplLexer::nextNonSpaceToken() * * @param unit the new source unit */ -void RplLexer::startUnit(RplSourceUnitName unit) +void ReLexer::startUnit(ReSourceUnitName unit) { m_source->startUnit(unit, *m_currentPosition); } @@ -1186,7 +1186,7 @@ void RplLexer::startUnit(RplSourceUnitName unit) * * @return the source of the instance */ -RplSource* RplLexer::source() +ReSource* ReLexer::source() { return m_source; } @@ -1197,7 +1197,7 @@ RplSource* RplLexer::source() * @param op the operator * @return the priority of the op */ -int RplLexer::prioOfOp(int op) const +int ReLexer::prioOfOp(int op) const { int rc = op > 0 && (unsigned) op < sizeof m_prioOfOp / sizeof m_prioOfOp[0] ? m_prioOfOp[op] : 0; @@ -1210,7 +1210,7 @@ int RplLexer::prioOfOp(int op) const * @param op the operator id * @return the name of the operator */ -const QByteArray&RplLexer::nameOfOp(int op) const +const QByteArray&ReLexer::nameOfOp(int op) const { const QByteArray& rc = m_opNames.at(op); return rc; @@ -1222,7 +1222,7 @@ const QByteArray&RplLexer::nameOfOp(int op) const * @return true: the operator is right associative
* false: otherwise */ -bool RplLexer::isRightAssociative(int op) const +bool ReLexer::isRightAssociative(int op) const { bool rc = false; if (op >= 0 && (unsigned) op < sizeof m_assocOfOp / sizeof m_assocOfOp[0]){ diff --git a/rplexpr/rpllexer.hpp b/expr/ReLexer.hpp similarity index 86% rename from rplexpr/rpllexer.hpp rename to expr/ReLexer.hpp index cf27d9b..fea3b0d 100644 --- a/rplexpr/rpllexer.hpp +++ b/expr/ReLexer.hpp @@ -28,21 +28,21 @@ enum RplTokenType { TOKEN_COUNT }; -class RplLexException : public RplException { +class ReLexException : public ReException { public: - RplLexException(const RplSourcePosition& position, const char* message, ...); + ReLexException(const ReSourcePosition& position, const char* message, ...); }; -class RplLexer; +class ReLexer; -class RplToken { +class ReToken { public: - RplToken(RplTokenType type); - ~RplToken(); - RplToken(const RplToken& source); - RplToken& operator =(const RplToken& source); + ReToken(RplTokenType type); + ~ReToken(); + ReToken(const ReToken& source); + ReToken& operator =(const ReToken& source); public: - friend class RplLexer; + friend class ReLexer; const QByteArray& toString(); bool isInteger(); int asInteger() const; @@ -73,8 +73,8 @@ protected: }; -class RplSource; -class RplLexer +class ReSource; +class ReLexer { public: typedef QList StringList; @@ -159,7 +159,7 @@ public: }; public: - RplLexer(RplSource* source, + ReLexer(ReSource* source, const char* keywords, const char* operators, const char* rightAssociatives, @@ -170,23 +170,23 @@ public: int stringFeatures = SF_TICK | SF_QUOTE | SF_C_ESCAPING | SF_C_SPECIAL | SF_C_HEX_CHARS, int storageFlags = STORE_NOTHING); - virtual ~RplLexer(); + virtual ~ReLexer(); public: - RplToken* nextToken(); + ReToken* nextToken(); void undoLastToken(); void undoLastToken2(); void saveLastToken(); - RplToken* peekNonSpaceToken(); - RplToken* nextNonSpaceToken(); + ReToken* peekNonSpaceToken(); + ReToken* nextNonSpaceToken(); size_t maxTokenLength() const; void setMaxTokenLength(size_t maxTokenLength); - void startUnit(RplSourceUnitName unit); - RplSource* source(); + void startUnit(ReSourceUnitName unit); + ReSource* source(); int prioOfOp(int op) const; const QByteArray& nameOfOp(int op) const; bool isRightAssociative(int op) const; - const RplSourcePosition* currentPosition() const; - RplToken* currentToken() const; + const ReSourcePosition* currentPosition() const; + ReToken* currentToken() const; #if defined RPL_LEXER_TRACE bool trace() const; void setTrace(bool trace); @@ -196,13 +196,13 @@ private: void initializeComments(const char* comments); bool fillInput(); int findInVector(int tokenLength, const StringList& vector); - RplToken* findTokenWithId(RplTokenType tokenType, int flag2, + ReToken* findTokenWithId(RplTokenType tokenType, int flag2, StringList& names); - RplToken* scanNumber(); - RplToken* scanString(); + ReToken* scanNumber(); + ReToken* scanString(); void scanComment(); protected: - RplSource* m_source; + ReSource* m_source; /// sorted, string ends with the id of the keyword StringList m_keywords; // sorted, string ends with the id of the operator @@ -220,14 +220,14 @@ protected: // a list of QChars with ord(cc) > 127 and which can be the first char int m_numericTypes; QByteArray m_idRest2; - RplToken* m_currentToken; - RplToken* m_waitingToken; - RplToken* m_waitingToken2; - RplToken m_token1; - RplToken m_token2; - const RplSourcePosition* m_currentPosition; - const RplSourcePosition* m_waitingPosition1; - const RplSourcePosition* m_waitingPosition2; + ReToken* m_currentToken; + ReToken* m_waitingToken; + ReToken* m_waitingToken2; + ReToken m_token1; + ReToken m_token2; + const ReSourcePosition* m_currentPosition; + const ReSourcePosition* m_waitingPosition1; + const ReSourcePosition* m_waitingPosition2; int m_maxTokenLength; QByteArray m_input; int m_currentCol; diff --git a/rplexpr/rplmfparser.cpp b/expr/ReMFParser.cpp similarity index 74% rename from rplexpr/rplmfparser.cpp rename to expr/ReMFParser.cpp index 9f3f5ec..38475da 100644 --- a/rplexpr/rplmfparser.cpp +++ b/expr/ReMFParser.cpp @@ -13,8 +13,8 @@ * @brief Definition for a parser for the language ML. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" enum MFLocations{ L_PARSE_OPERAND_RPARENTH = 2001, @@ -71,7 +71,7 @@ enum MFLocations{ }; -/** @class RplMFParser rpllexer.hpp "rplexpr/rplmfparser.hpp" +/** @class ReMFParser rpllexer.hpp "rplexpr/rplmfparser.hpp" * * @brief Implements a parser for the language MF. * @@ -80,34 +80,34 @@ enum MFLocations{ * for matrix operations, simulation and graphics. */ -RplMFParser::RplMFParser(RplSource& source, RplASTree& abstractSyntaxTree) : - RplParser(m_lexer, abstractSyntaxTree), +ReMFParser::ReMFParser(ReSource& source, ReASTree& abstractSyntaxTree) : + ReParser(m_lexer, abstractSyntaxTree), m_lexer(&source, MF_KEYWORDS, MF_OPERATORS, MF_RIGHT_ASSOCIATIVES, "/* */ // \n", "a-zA-Z_", "a-zA-Z0-9_", - RplLexer::NUMTYPE_ALL, RplLexer::SF_LIKE_C) + ReLexer::NUMTYPE_ALL, ReLexer::SF_LIKE_C) { } /** * @brief Parses an if statement. */ -RplASItem* RplMFParser::parseIf() +ReASItem* ReMFParser::parseIf() { - RplASIf* rc = new RplASIf(); + ReASIf* rc = new ReASIf(); rc->setPosition(m_lexer.currentPosition()); - RplASItem* condition = parseExpr(0); + ReASItem* condition = parseExpr(0); if (! m_lexer.currentToken()->isKeyword(K_THEN)) syntaxError(L_PARSE_IF_NO_THEN, "'then' expected"); rc->setChild2(condition); - RplASItem* body = parseBody(K_ELSE, K_FI); + ReASItem* body = parseBody(K_ELSE, K_FI); rc->setChild3(body); if (! m_lexer.currentToken()->isKeyword(K_ELSE, K_FI)) syntaxError(L_PARSE_IF_NO_ELSE, "'else' or 'fi' expected"); if ( m_lexer.currentToken()->isKeyword(K_ELSE)){ - RplASItem* body = parseBody(K_FI); + ReASItem* body = parseBody(K_FI); rc->setChild4(body); } if (! m_lexer.currentToken()->isKeyword(K_FI)) @@ -119,16 +119,16 @@ RplASItem* RplMFParser::parseIf() * @brief Parses a while statement. */ -RplASItem* RplMFParser::parseWhile() +ReASItem* ReMFParser::parseWhile() { - RplASWhile* rc = new RplASWhile(); + ReASWhile* rc = new ReASWhile(); rc->setPosition(m_lexer.currentPosition()); - RplASItem* condition = parseExpr(0); + ReASItem* condition = parseExpr(0); if (! m_lexer.currentToken()->isKeyword(K_DO)) syntaxError(L_PARSE_WHILE_NO_DO, "'do' expected"); rc->setChild2(condition); - RplASItem* body = parseBody(K_OD); + ReASItem* body = parseBody(K_OD); rc->setChild3(body); if (! m_lexer.currentToken()->isKeyword(K_OD)) syntaxError(L_PARSE_WHILE_NO_OD, "'od' expected"); @@ -139,17 +139,17 @@ RplASItem* RplMFParser::parseWhile() /** * @brief Parses a repeat statement. */ -RplASItem* RplMFParser::parseRepeat() +ReASItem* ReMFParser::parseRepeat() { - RplASRepeat* rc = new RplASRepeat(); + ReASRepeat* rc = new ReASRepeat(); rc->setPosition(m_lexer.currentPosition()); - RplASItem* body = parseBody(K_UNTIL); + ReASItem* body = parseBody(K_UNTIL); rc->setChild3(body); if (! m_lexer.currentToken()->isKeyword(K_UNTIL)) syntaxError(L_PARSE_REPEAT_NO_UNTIL, "'until' expected"); - RplASItem* condition = parseExpr(0); + ReASItem* condition = parseExpr(0); if (! m_lexer.currentToken()->isOperator(O_SEMICOLON)) syntaxError(L_PARSE_REPEAT_NO_SEMI, "';' expected"); rc->setChild2(condition); @@ -162,12 +162,12 @@ RplASItem* RplMFParser::parseRepeat() * @param var the basic variable data * @return */ -RplASVarDefinition* RplMFParser::buildVarDef(RplASNamedValue* var) +ReASVarDefinition* ReMFParser::buildVarDef(ReASNamedValue* var) { - RplASVarDefinition* rc = new RplASVarDefinition(); + ReASVarDefinition* rc = new ReASVarDefinition(); rc->setPosition(var->position()); rc->setChild2(var); - RplSymbolSpace* symbols = m_tree.currentSpace(); + ReSymbolSpace* symbols = m_tree.currentSpace(); int varNo; symbols->addVariable(rc, varNo); var->setVariableNo(varNo); @@ -186,27 +186,27 @@ RplASVarDefinition* RplMFParser::buildVarDef(RplASNamedValue* var) * @post the token behind the do is read * @return the abstract syntax tree of the for statement */ -RplASItem* RplMFParser::parseFor() +ReASItem* ReMFParser::parseFor() { int builtinVars = 1; - RplASNode2* rc = NULL; - const RplSourcePosition* startPosition = m_lexer.currentPosition(); - RplToken* token = m_lexer.nextNonSpaceToken(); - RplASNamedValue* var = NULL; + ReASNode2* rc = NULL; + const ReSourcePosition* startPosition = m_lexer.currentPosition(); + ReToken* token = m_lexer.nextNonSpaceToken(); + ReASNamedValue* var = NULL; if (token->isTokenType(TOKEN_ID)){ - var = new RplASNamedValue(RplASInteger::m_instance, + var = new ReASNamedValue(ReASInteger::m_instance, m_tree.currentSpace(), token->toString(), - RplASNamedValue::A_LOOP); + ReASNamedValue::A_LOOP); var->setPosition(m_lexer.currentPosition()); token = m_lexer.nextNonSpaceToken(); } if (token->isKeyword(K_IN)){ - RplASVarDefinition* varDef = buildVarDef(var); - RplASForIterated* node = new RplASForIterated(varDef); + ReASVarDefinition* varDef = buildVarDef(var); + ReASForIterated* node = new ReASForIterated(varDef); rc = node; node->setPosition(startPosition); node->setChild3(var); - RplASItem* iterable = parseExpr(0); + ReASItem* iterable = parseExpr(0); node->setChild4(iterable); } else { if (var == NULL){ @@ -214,13 +214,13 @@ RplASItem* RplMFParser::parseFor() // Build a unique name inside the scope: qsnprintf(name, sizeof name, "$%d_%d", startPosition->lineNo(), startPosition->column()); - var = new RplASNamedValue(RplASInteger::m_instance, + var = new ReASNamedValue(ReASInteger::m_instance, m_tree.currentSpace(), name, - RplASNamedValue::A_LOOP); + ReASNamedValue::A_LOOP); var->setPosition(startPosition); } - RplASVarDefinition* varDef = buildVarDef(var); - RplASForCounted* node = new RplASForCounted(varDef); + ReASVarDefinition* varDef = buildVarDef(var); + ReASForCounted* node = new ReASForCounted(varDef); rc = node; node->setPosition(startPosition); node->setChild3(var); @@ -254,18 +254,18 @@ RplASItem* RplMFParser::parseFor() * @param attribute attribute of the variable: A_PARAM... * @return a variable/parameter definition */ -RplASVarDefinition* RplMFParser::parseVarDefinition( - RplASNamedValue::Attributes attribute) +ReASVarDefinition* ReMFParser::parseVarDefinition( + ReASNamedValue::Attributes attribute) { int attributes = attribute; - RplToken* token = m_lexer.currentToken(); + ReToken* token = m_lexer.currentToken(); while(token->isKeyword(K_CONST, K_LAZY)){ switch(token->id()){ case K_CONST: - attributes += RplASNamedValue::A_CONST; + attributes += ReASNamedValue::A_CONST; break; case K_LAZY: - attributes += RplASNamedValue::A_LAZY; + attributes += ReASNamedValue::A_LAZY; break; default: break; @@ -277,29 +277,29 @@ RplASVarDefinition* RplMFParser::parseVarDefinition( if (! token->isCapitalizedId()) syntaxError(L_DEFINITION_WRONG_ID, "a class name must start with an upper case character"); - RplASClass* clazz = m_tree.currentSpace()->findClass(token->toString()); + ReASClass* clazz = m_tree.currentSpace()->findClass(token->toString()); if (clazz == NULL) syntaxError(L_DEFINITION_UNKNOWN_CLASS, "unknown class"); token = m_lexer.nextNonSpaceToken(); if (! token->isTokenType(TOKEN_ID)) syntaxError(L_DEFINITION_MISSING_ID, "variable name expected"); - RplSymbolSpace* symbols = m_tree.currentSpace(); + ReSymbolSpace* symbols = m_tree.currentSpace(); // freed in the destructor of the nodes: - RplASNamedValue* namedValue = new RplASNamedValue(clazz, symbols, + ReASNamedValue* namedValue = new ReASNamedValue(clazz, symbols, token->toString(), attributes); namedValue->setPosition(m_lexer.currentPosition()); - RplASVarDefinition* rc = new RplASVarDefinition(); + ReASVarDefinition* rc = new ReASVarDefinition(); rc->setPosition(m_lexer.currentPosition()); rc->setChild2(namedValue); token = m_lexer.nextNonSpaceToken(); if (token->id() == O_ASSIGN){ - RplASItem* value = parseExpr(0); + ReASItem* value = parseExpr(0); rc->setChild3(value); token = m_lexer.currentToken(); } int varNo = 0; - RplASItem* oldSymbol = symbols->addVariable(rc, varNo); + ReASItem* oldSymbol = symbols->addVariable(rc, varNo); if (oldSymbol != NULL) error(L_PARSE_VAR_DEF_ALREADY_DEFINED, oldSymbol->position(), "symbol already defined", "previous definition"); @@ -315,25 +315,25 @@ RplASVarDefinition* RplMFParser::parseVarDefinition( * the new expression is chained into the parent * @return the variant containing the formula */ -RplASVariant* RplMFParser::createFormula(RplASNode1* parent) +ReASVariant* ReMFParser::createFormula(ReASNode1* parent) { - RplASVariant* variant = NULL; + ReASVariant* variant = NULL; m_lexer.undoLastToken2(); - RplASExprStatement* expr = dynamic_cast + ReASExprStatement* expr = dynamic_cast (parseExprStatement(false)); if (expr != NULL){ // chaining per m_child (= next statement) is for freeing while destruction: expr->setChild(parent->child()); parent->setChild(expr); - // freed in the destructor of varList (~RplASVariant()): - variant = new RplASVariant(); - variant->setObject(expr, RplASFormula::m_instance); + // freed in the destructor of varList (~ReASVariant()): + variant = new ReASVariant(); + variant->setObject(expr, ReASFormula::m_instance); } return variant; } /** - * @brief Converts the current expression into a RplASVariant. + * @brief Converts the current expression into a ReASVariant. * * If the expression is a constant, the constant value will be the content * of the variant. Otherwise a formula will be stored. @@ -345,38 +345,38 @@ RplASVariant* RplMFParser::createFormula(RplASNode1* parent) * @param parent the parent node of the expression * @return the variant with the token's content */ -RplASVariant* RplMFParser::tokenToVariant(RplToken* token, - bool endsWithComma, RplASNode1* parent) +ReASVariant* ReMFParser::tokenToVariant(ReToken* token, + bool endsWithComma, ReASNode1* parent) { - RplASVariant* variant = NULL; + ReASVariant* variant = NULL; if (endsWithComma){ switch(token->tokenType()){ case TOKEN_NUMBER: - // freed in the destructor of varList (~RplASVariant()): - variant = new RplASVariant(); + // freed in the destructor of varList (~ReASVariant()): + variant = new ReASVariant(); variant->setInt(token->asInteger()); break; case TOKEN_STRING: - // freed in the destructor of varList (~RplASVariant()): - variant = new RplASVariant(); + // freed in the destructor of varList (~ReASVariant()): + variant = new ReASVariant(); variant->setString(token->toString()); break; case TOKEN_REAL: - // freed in the destructor of varList (~RplASVariant()): - variant = new RplASVariant(); + // freed in the destructor of varList (~ReASVariant()): + variant = new ReASVariant(); variant->setFloat(token->asReal()); break; case TOKEN_KEYWORD: switch(token->id()){ case K_TRUE: case K_FALSE: - // freed in the destructor of varList (~RplASVariant()): - variant = new RplASVariant(); + // freed in the destructor of varList (~ReASVariant()): + variant = new ReASVariant(); variant->setBool(token->id() == K_TRUE); break; case K_NONE: - // freed in the destructor of varList (~RplASVariant()): - variant = new RplASVariant(); + // freed in the destructor of varList (~ReASVariant()): + variant = new ReASVariant(); break; default: break; @@ -401,17 +401,17 @@ RplASVariant* RplMFParser::tokenToVariant(RplToken* token, * @post the token behind the ']' is read * @return a node of the abstract syntax tree */ -RplASItem* RplMFParser::parseList() +ReASItem* ReMFParser::parseList() { - RplASListConstant* rc = new RplASListConstant(); - RplASVariant& varList = rc->value(); - RplASListOfVariants* list = static_cast + ReASListConstant* rc = new ReASListConstant(); + ReASVariant& varList = rc->value(); + ReASListOfVariants* list = static_cast (varList.asObject(NULL)); rc->setPosition(m_lexer.currentPosition()); - RplASVariant* variant; + ReASVariant* variant; bool again = true; - RplToken* token; - RplToken* token2; + ReToken* token; + ReToken* token2; // read the token behind '[': token = m_lexer.nextNonSpaceToken(); if (token->isOperator(O_RBRACKET)){ @@ -447,17 +447,17 @@ RplASItem* RplMFParser::parseList() * @post the token behind the '}' is read * @return a node of the abstract syntax tree */ -RplASItem* RplMFParser::parseMap() +ReASItem* ReMFParser::parseMap() { - RplASMapConstant* rc = new RplASMapConstant(); - RplASVariant& varMap = rc->value(); - RplASMapOfVariants* map = static_cast + ReASMapConstant* rc = new ReASMapConstant(); + ReASVariant& varMap = rc->value(); + ReASMapOfVariants* map = static_cast (varMap.asObject(NULL)); rc->setPosition(m_lexer.currentPosition()); - RplASVariant* variant; + ReASVariant* variant; bool again = true; - RplToken* token; - RplToken* token2; + ReToken* token; + ReToken* token2; QByteArray key; while(again){ token = m_lexer.nextNonSpaceToken(); @@ -467,7 +467,7 @@ RplASItem* RplMFParser::parseMap() key.clear(); switch(token->tokenType()){ case TOKEN_STRING: - // freed in the destructor of varList (~RplASVariant()): + // freed in the destructor of varList (~ReASVariant()): key = token->toString(); break; case TOKEN_KEYWORD: @@ -526,25 +526,25 @@ RplASItem* RplMFParser::parseMap() * @param position source position * @param parent NULL: result is a variable * - * @return a RplASNamedValue or a - * RplASNamedValue instance + * @return a ReASNamedValue or a + * ReASNamedValue instance */ -RplASItem* RplMFParser::buildVarOrField(const QByteArray& name, - const RplSourcePosition* position, RplASItem* parent) +ReASItem* ReMFParser::buildVarOrField(const QByteArray& name, + const ReSourcePosition* position, ReASItem* parent) { - RplASItem* rc = NULL; + ReASItem* rc = NULL; if (parent == NULL){ - RplSymbolSpace* space = m_tree.currentSpace(); - RplASVarDefinition* var = space->findVariable(name); - RplASClass* clazz = NULL; + ReSymbolSpace* space = m_tree.currentSpace(); + ReASVarDefinition* var = space->findVariable(name); + ReASClass* clazz = NULL; if (var != NULL) clazz = var->clazz(); - RplASNamedValue* var2 = new RplASNamedValue(clazz, space, - name, RplASNamedValue::A_NONE); + ReASNamedValue* var2 = new ReASNamedValue(clazz, space, + name, ReASNamedValue::A_NONE); var2->setPosition(position); rc = var2; } else { - RplASField* field = new RplASField(name); + ReASField* field = new ReASField(name); field->setPosition(position); rc = field; field->setChild(parent); @@ -558,30 +558,30 @@ RplASItem* RplMFParser::buildVarOrField(const QByteArray& name, * * @return operator known by the abstract syntax tree */ -RplASUnaryOp::UnaryOp RplMFParser::convertUnaryOp(int op) +ReASUnaryOp::UnaryOp ReMFParser::convertUnaryOp(int op) { - RplASUnaryOp::UnaryOp rc; + ReASUnaryOp::UnaryOp rc; switch(op){ case O_PLUS: - rc = RplASUnaryOp::UOP_PLUS; + rc = ReASUnaryOp::UOP_PLUS; break; case O_MINUS: - rc = RplASUnaryOp::UOP_MINUS_INT; + rc = ReASUnaryOp::UOP_MINUS_INT; break; case O_NOT: - rc = RplASUnaryOp::UOP_NOT_BOOL; + rc = ReASUnaryOp::UOP_NOT_BOOL; break; case O_BIT_NOT: - rc = RplASUnaryOp::UOP_NOT_INT; + rc = ReASUnaryOp::UOP_NOT_INT; break; case O_INC: - rc = RplASUnaryOp::UOP_INC; + rc = ReASUnaryOp::UOP_INC; break; case O_DEC: - rc = RplASUnaryOp::UOP_DEC; + rc = ReASUnaryOp::UOP_DEC; break; default: - throw RplException("unknown unary operator %d", op); + throw ReException("unknown unary operator %d", op); break; } return rc; @@ -596,11 +596,11 @@ RplASUnaryOp::UnaryOp RplMFParser::convertUnaryOp(int op) * @post the token behind the operand is read * @return the node with the operand */ -RplASItem* RplMFParser::parseOperand(int level, RplASItem* parent) +ReASItem* ReMFParser::parseOperand(int level, ReASItem* parent) { - RplToken* token = m_lexer.nextNonSpaceToken(); - const RplSourcePosition* startPosition = m_lexer.currentPosition(); - RplASItem* rc = NULL; + ReToken* token = m_lexer.nextNonSpaceToken(); + const ReSourcePosition* startPosition = m_lexer.currentPosition(); + ReASItem* rc = NULL; bool readNext = true; switch(token->tokenType()){ case TOKEN_OPERATOR: @@ -614,7 +614,7 @@ RplASItem* RplMFParser::parseOperand(int level, RplASItem* parent) rc = parseList(); readNext = false; } else { - RplASIndexedValue* value = new RplASIndexedValue(); + ReASIndexedValue* value = new ReASIndexedValue(); value->setPosition(startPosition); value->setChild(parent); rc = value; @@ -635,7 +635,7 @@ RplASItem* RplMFParser::parseOperand(int level, RplASItem* parent) "')' expected", "(", startPosition); } } else if (IS_UNARY_OP(opId)){ - RplASUnaryOp* op = new RplASUnaryOp(convertUnaryOp(token->id()), + ReASUnaryOp* op = new ReASUnaryOp(convertUnaryOp(token->id()), AST_PRE_UNARY_OP); op->setPosition(m_lexer.currentPosition()); op->setChild(parseOperand(level)); @@ -653,7 +653,7 @@ RplASItem* RplMFParser::parseOperand(int level, RplASItem* parent) if (parent != NULL) syntaxError(L_PARSE_OPERAND_NO_FIELD2, "field expected (behind a '.')"); - RplASConstant* constant = new RplASConstant(); + ReASConstant* constant = new ReASConstant(); constant->setPosition(m_lexer.currentPosition()); rc = constant; switch(token->tokenType()){ @@ -683,27 +683,27 @@ RplASItem* RplMFParser::parseOperand(int level, RplASItem* parent) readNext = false; } else { if (token->id() == O_LPARENTH){ - RplASMethodCall* call = new RplASMethodCall(name, parent); + ReASMethodCall* call = new ReASMethodCall(name, parent); call->setPosition(startPosition); rc = call; token = m_lexer.nextNonSpaceToken(); if (! token->isOperator(O_RPARENTH)){ m_lexer.undoLastToken(); - RplASExprStatement* args = parseArguments(); + ReASExprStatement* args = parseArguments(); call->setChild2(args); readNext = false; } } else { rc = buildVarOrField(name, startPosition, parent); if (token->id() == O_LBRACKET){ - RplASItem* indexExpr = parseExpr(0); + ReASItem* indexExpr = parseExpr(0); if (! m_lexer.currentToken()->isOperator(O_RBRACKET)) syntaxError(L_PARSE_OPERAND_NO_BRACKET, "']' expected"); - dynamic_cast(rc)->setChild(indexExpr); + dynamic_cast(rc)->setChild(indexExpr); } else { if (token->id() == O_INC || token->id() == O_DEC){ - RplASUnaryOp* op = new RplASUnaryOp(convertUnaryOp( + ReASUnaryOp* op = new ReASUnaryOp(convertUnaryOp( token->id()), AST_POST_UNARY_OP); op->setChild(rc); @@ -741,107 +741,107 @@ RplASItem* RplMFParser::parseOperand(int level, RplASItem* parent) * * @return operator known by the abstract syntax tree */ -RplASBinaryOp::BinOperator RplMFParser::convertBinaryOp(int op){ - RplASBinaryOp::BinOperator rc; +ReASBinaryOp::BinOperator ReMFParser::convertBinaryOp(int op){ + ReASBinaryOp::BinOperator rc; switch(op){ - case RplMFParser::O_ASSIGN: - rc = RplASBinaryOp::BOP_ASSIGN; + case ReMFParser::O_ASSIGN: + rc = ReASBinaryOp::BOP_ASSIGN; break; - case RplMFParser::O_PLUS_ASSIGN: - rc = RplASBinaryOp::BOP_PLUS_ASSIGN; + case ReMFParser::O_PLUS_ASSIGN: + rc = ReASBinaryOp::BOP_PLUS_ASSIGN; break; - case RplMFParser::O_MINUS_ASSIGN: - rc = RplASBinaryOp::BOP_MINUS_ASSIGN; + case ReMFParser::O_MINUS_ASSIGN: + rc = ReASBinaryOp::BOP_MINUS_ASSIGN; break; - case RplMFParser::O_DIV_ASSIGN: - rc = RplASBinaryOp::BOP_DIV_ASSIGN; + case ReMFParser::O_DIV_ASSIGN: + rc = ReASBinaryOp::BOP_DIV_ASSIGN; break; - case RplMFParser::O_TIMES_ASSIGN: - rc = RplASBinaryOp::BOP_TIMES_ASSIGN; + case ReMFParser::O_TIMES_ASSIGN: + rc = ReASBinaryOp::BOP_TIMES_ASSIGN; break; - case RplMFParser::O_MOD_ASSIGN: - rc = RplASBinaryOp::BOP_MOD_ASSIGN; + case ReMFParser::O_MOD_ASSIGN: + rc = ReASBinaryOp::BOP_MOD_ASSIGN; break; - case RplMFParser::O_POWER_ASSIGN: - rc = RplASBinaryOp::BOP_POWER_ASSIGN; + case ReMFParser::O_POWER_ASSIGN: + rc = ReASBinaryOp::BOP_POWER_ASSIGN; break; - case RplMFParser::O_OR_ASSIGN: - rc = RplASBinaryOp::BOP_LOG_OR_ASSIGN; + case ReMFParser::O_OR_ASSIGN: + rc = ReASBinaryOp::BOP_LOG_OR_ASSIGN; break; - case RplMFParser::O_AND_ASSIGN: - rc = RplASBinaryOp::BOP_LOG_AND_ASSIGN; + case ReMFParser::O_AND_ASSIGN: + rc = ReASBinaryOp::BOP_LOG_AND_ASSIGN; break; - case RplMFParser::O_LSHIFT_ASSIGN: - rc = RplASBinaryOp::BOP_LSHIFT_ASSIGN; + case ReMFParser::O_LSHIFT_ASSIGN: + rc = ReASBinaryOp::BOP_LSHIFT_ASSIGN; break; - case RplMFParser::O_RSHIFT_ASSIGN: - rc = RplASBinaryOp::BOP_LOG_RSHIFT_ASSIGN; + case ReMFParser::O_RSHIFT_ASSIGN: + rc = ReASBinaryOp::BOP_LOG_RSHIFT_ASSIGN; break; - case RplMFParser::O_RSHIFT2_ASSIGN: - rc = RplASBinaryOp::BOP_ARTITH_RSHIFT_ASSIGN; + case ReMFParser::O_RSHIFT2_ASSIGN: + rc = ReASBinaryOp::BOP_ARTITH_RSHIFT_ASSIGN; break; - case RplMFParser::O_OR: - rc = RplASBinaryOp::BOP_LOG_OR; + case ReMFParser::O_OR: + rc = ReASBinaryOp::BOP_LOG_OR; break; - case RplMFParser::O_AND: - rc = RplASBinaryOp::BOP_LOG_AND; + case ReMFParser::O_AND: + rc = ReASBinaryOp::BOP_LOG_AND; break; - case RplMFParser::O_EQ: - rc = RplASBinaryOp::BOP_EQ; + case ReMFParser::O_EQ: + rc = ReASBinaryOp::BOP_EQ; break; - case RplMFParser::O_NE: - rc = RplASBinaryOp::BOP_NE; + case ReMFParser::O_NE: + rc = ReASBinaryOp::BOP_NE; break; - case RplMFParser::O_LT: - rc = RplASBinaryOp::BOP_LT; + case ReMFParser::O_LT: + rc = ReASBinaryOp::BOP_LT; break; - case RplMFParser::O_GT: - rc = RplASBinaryOp::BOP_GT; + case ReMFParser::O_GT: + rc = ReASBinaryOp::BOP_GT; break; - case RplMFParser::O_LE: - rc = RplASBinaryOp::BOP_LE; + case ReMFParser::O_LE: + rc = ReASBinaryOp::BOP_LE; break; - case RplMFParser::O_GE: - rc = RplASBinaryOp::BOP_GE; + case ReMFParser::O_GE: + rc = ReASBinaryOp::BOP_GE; break; - case RplMFParser::O_PLUS: - rc = RplASBinaryOp::BOP_PLUS; + case ReMFParser::O_PLUS: + rc = ReASBinaryOp::BOP_PLUS; break; - case RplMFParser::O_MINUS: - rc = RplASBinaryOp::BOP_MINUS; + case ReMFParser::O_MINUS: + rc = ReASBinaryOp::BOP_MINUS; break; - case RplMFParser::O_DIV: - rc = RplASBinaryOp::BOP_DIV; + case ReMFParser::O_DIV: + rc = ReASBinaryOp::BOP_DIV; break; - case RplMFParser::O_MOD: - rc = RplASBinaryOp::BOP_MOD; + case ReMFParser::O_MOD: + rc = ReASBinaryOp::BOP_MOD; break; - case RplMFParser::O_TIMES: - rc = RplASBinaryOp::BOP_TIMES; + case ReMFParser::O_TIMES: + rc = ReASBinaryOp::BOP_TIMES; break; - case RplMFParser::O_POWER: - rc = RplASBinaryOp::BOP_POWER; + case ReMFParser::O_POWER: + rc = ReASBinaryOp::BOP_POWER; break; - case RplMFParser::O_XOR: - rc = RplASBinaryOp::BOP_LOG_XOR; + case ReMFParser::O_XOR: + rc = ReASBinaryOp::BOP_LOG_XOR; break; - case RplMFParser::O_BIT_OR: - rc = RplASBinaryOp::BOP_BIT_OR; + case ReMFParser::O_BIT_OR: + rc = ReASBinaryOp::BOP_BIT_OR; break; - case RplMFParser::O_BIT_AND: - rc = RplASBinaryOp::BOP_BIT_AND; + case ReMFParser::O_BIT_AND: + rc = ReASBinaryOp::BOP_BIT_AND; break; - case RplMFParser::O_LSHIFT: - rc = RplASBinaryOp::BOP_LSHIFT; + case ReMFParser::O_LSHIFT: + rc = ReASBinaryOp::BOP_LSHIFT; break; - case RplMFParser::O_RSHIFT: - rc = RplASBinaryOp::BOP_LOG_RSHIFT; + case ReMFParser::O_RSHIFT: + rc = ReASBinaryOp::BOP_LOG_RSHIFT; break; - case RplMFParser::O_RSHIFT2: - rc = RplASBinaryOp::BOP_ARTITH_RSHIFT; + case ReMFParser::O_RSHIFT2: + rc = ReASBinaryOp::BOP_ARTITH_RSHIFT; break; default: - throw RplException("unknown binary operator %d", op); + throw ReException("unknown binary operator %d", op); break; } return rc; @@ -864,9 +864,9 @@ RplASBinaryOp::BinOperator RplMFParser::convertBinaryOp(int op){ * @param depth the level of the parenthesis * @return the abstract syntax tree representing the parsed expression */ -RplASItem* RplMFParser::parseExpr(int depth){ - RplToken* token; - RplASItem* top = parseOperand(depth); +ReASItem* ReMFParser::parseExpr(int depth){ + ReToken* token; + ReASItem* top = parseOperand(depth); if (top != NULL){ int lastPrio = INT_MAX; bool again = true; @@ -877,7 +877,7 @@ RplASItem* RplMFParser::parseExpr(int depth){ { Operator opId = (Operator) token->id(); if (IS_BINARY_OP(opId)){ - RplASBinaryOp* op = new RplASBinaryOp(); + ReASBinaryOp* op = new ReASBinaryOp(); op->setPosition(m_lexer.currentPosition()); op->setOperator(convertBinaryOp(opId)); @@ -889,7 +889,7 @@ RplASItem* RplMFParser::parseExpr(int depth){ top = op; } else { // right assoc or higher priority: - RplASBinaryOp* top2 = dynamic_cast(top); + ReASBinaryOp* top2 = dynamic_cast(top); op->setChild(top2->child2()); top2->setChild2(op); } @@ -928,12 +928,12 @@ RplASItem* RplMFParser::parseExpr(int depth){ * @param eatSemicolon true: a trailing ';' will be read * @return the abstract syntax tree of the expression statement */ -RplASItem* RplMFParser::parseExprStatement(bool eatSemicolon) +ReASItem* ReMFParser::parseExprStatement(bool eatSemicolon) { - RplASItem* item = parseExpr(0); - RplASExprStatement* statement = NULL; + ReASItem* item = parseExpr(0); + ReASExprStatement* statement = NULL; if (item != NULL){ - statement = new RplASExprStatement(); + statement = new ReASExprStatement(); statement->setPosition(item->position()); statement->setChild2(item); } @@ -947,8 +947,8 @@ RplASItem* RplMFParser::parseExprStatement(bool eatSemicolon) * * @return the variable definition */ -RplASItem* RplMFParser::parseLocalVar(){ - RplASItem* rc = parseVarDefinition(RplASNamedValue::A_NONE); +ReASItem* ReMFParser::parseLocalVar(){ + ReASItem* rc = parseVarDefinition(ReASNamedValue::A_NONE); return rc; } @@ -962,18 +962,18 @@ RplASItem* RplMFParser::parseLocalVar(){ * @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, +ReASItem* ReMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, int builtinVars) { - RplToken* token = m_lexer.nextNonSpaceToken(); - RplASItem* item = NULL; - RplASItem* body = NULL; - RplASNode1* lastStatement = NULL; - RplASScope scope; + ReToken* token = m_lexer.nextNonSpaceToken(); + ReASItem* item = NULL; + ReASItem* body = NULL; + ReASNode1* lastStatement = NULL; + ReASScope scope; m_tree.currentSpace()->startScope(scope); scope.m_builtInVars = builtinVars; bool again = true; - const RplSourcePosition* lastPos = NULL; + const ReSourcePosition* lastPos = NULL; do { token = m_lexer.currentToken(); if (lastPos == m_lexer.currentPosition()) @@ -1051,7 +1051,7 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, } else { lastStatement->setChild(item); } - lastStatement = dynamic_cast(item); + lastStatement = dynamic_cast(item); if (lastStatement == NULL) error(L_PARSE_BODY_WRONG_ITEM, "wrong item type: %d", item == NULL ? 0 : item->nodeType()); @@ -1060,7 +1060,7 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, && token->isKeyword(keywordStop, keywordStop2)) again = false; } - } catch(RplSyntaxError exc){ + } catch(RSyntaxError exc){ // we look for the end of the statement: token = m_lexer.currentToken(); RplTokenType type; @@ -1102,15 +1102,15 @@ RplASItem* RplMFParser::parseBody(Keyword keywordStop, Keyword keywordStop2, * @post token behind ')' is read * @return */ -RplASVarDefinition* RplMFParser::parseParameterList(){ - RplASVarDefinition* rc = NULL; - RplASVarDefinition* last = NULL; - const RplSourcePosition* startPos = m_lexer.currentPosition(); - RplASItem* definition = NULL; +ReASVarDefinition* ReMFParser::parseParameterList(){ + ReASVarDefinition* rc = NULL; + ReASVarDefinition* last = NULL; + const ReSourcePosition* startPos = m_lexer.currentPosition(); + ReASItem* definition = NULL; do { if (definition != NULL) m_lexer.nextNonSpaceToken(); - RplASVarDefinition* current = parseVarDefinition(RplASNamedValue::A_PARAM); + ReASVarDefinition* current = parseVarDefinition(ReASNamedValue::A_PARAM); if (rc == NULL){ rc = current; } else { @@ -1133,11 +1133,11 @@ RplASVarDefinition* RplMFParser::parseParameterList(){ * @post token behind "endf" is read * @return NULL */ -void RplMFParser::parseMethod() +void ReMFParser::parseMethod() { - RplASMethod* method = NULL; - const RplSourcePosition* startPos = m_lexer.currentPosition(); - RplToken* token = m_lexer.nextNonSpaceToken(); + ReASMethod* method = NULL; + const ReSourcePosition* startPos = m_lexer.currentPosition(); + ReToken* token = m_lexer.nextNonSpaceToken(); if (! token->isTokenType(TOKEN_ID)) syntaxError(L_PARSE_METH_NO_CLASS, "type name expected"); QByteArray type = token->toString(); @@ -1155,12 +1155,12 @@ void RplMFParser::parseMethod() if (! token->isOperator(O_LPARENTH, O_COLON)) syntaxError(L_PARSE_METH_NO_LPARENTH, "'(' or ':' expected"); - RplASVarDefinition* parameterList = NULL; - method = new RplASMethod(name, m_tree); + ReASVarDefinition* parameterList = NULL; + method = new ReASMethod(name, m_tree); method->setPosition(startPos); - RplSymbolSpace* symbols = m_tree.currentSpace(); + ReSymbolSpace* symbols = m_tree.currentSpace(); symbols->addMethod(method); - m_tree.startClassOrMethod(name, RplSymbolSpace::SST_METHOD); + m_tree.startClassOrMethod(name, ReSymbolSpace::SST_METHOD); method->setSymbols(); if (token->isOperator(O_LPARENTH)){ token = m_lexer.nextNonSpaceToken(); @@ -1188,23 +1188,23 @@ void RplMFParser::parseMethod() * @pre "class" is read * @post token behind "endc" is read */ -void RplMFParser::parseClass() +void ReMFParser::parseClass() { - const RplSourcePosition* startPos = m_lexer.currentPosition(); - RplToken* token = m_lexer.nextNonSpaceToken(); + const ReSourcePosition* startPos = m_lexer.currentPosition(); + ReToken* token = m_lexer.nextNonSpaceToken(); if (! token->isTokenType(TOKEN_ID)) syntaxError(L_PARSE_CLASS_NO_NAME, "class name expected"); if (! token->isCapitalizedId()) syntaxError(L_PARSE_CLASS_LOWERCASE, "class name must start with an uppercase character"); QByteArray name = token->toString(); - RplASUserClass* clazz = new RplASUserClass(name, startPos, m_tree); - RplSymbolSpace* parent = m_tree.currentSpace(); - RplASUserClass* alreadyDefined = parent->addClass(clazz); + ReASUserClass* clazz = new ReASUserClass(name, startPos, m_tree); + ReSymbolSpace* parent = m_tree.currentSpace(); + ReASUserClass* alreadyDefined = parent->addClass(clazz); if (alreadyDefined != NULL){ error(L_PARSE_CLASS_ALREADY_DEFINED, alreadyDefined->position(), "class already defined", "previous defined class"); } - m_tree.startClassOrMethod(name, RplSymbolSpace::SST_CLASS); + m_tree.startClassOrMethod(name, ReSymbolSpace::SST_CLASS); clazz->setSymbols(); m_tree.finishClassOrMethod(name); @@ -1213,7 +1213,7 @@ void RplMFParser::parseClass() /** * @brief Parses a the import statement */ -void RplMFParser::parseImport() +void ReMFParser::parseImport() { } @@ -1226,25 +1226,25 @@ void RplMFParser::parseImport() * * @param name the name of the module (without path) */ -RplASItem* RplMFParser::parseModule(RplSourceUnitName name) +ReASItem* ReMFParser::parseModule(ReSourceUnitName name) { m_tree.startModule(name); // parse until EOF: - RplASItem* body = parseBody(K_UNDEF); + ReASItem* body = parseBody(K_UNDEF); m_tree.finishModule(name); return body; } /** * @brief Parse the input given by the source. */ -void RplMFParser::parse() +void ReMFParser::parse() { - RplSource* source = m_lexer.source(); - RplSourceUnit* mainModule = source->currentReader()->currentSourceUnit(); - RplSourceUnitName mainModuleName = mainModule->name(); + ReSource* source = m_lexer.source(); + ReSourceUnit* mainModule = source->currentReader()->currentSourceUnit(); + ReSourceUnitName mainModuleName = mainModule->name(); try { - RplASItem* body = parseModule(mainModuleName); - RplSymbolSpace* module = m_tree.findmodule(mainModuleName); + ReASItem* body = parseModule(mainModuleName); + ReSymbolSpace* module = m_tree.findmodule(mainModuleName); if (module != NULL) module->setBody(body); } catch(RplParserStop exc){ @@ -1259,17 +1259,17 @@ void RplMFParser::parse() * @post the token behind the ')' is read * @return the first element of the argument list */ -RplASExprStatement* RplMFParser::parseArguments() +ReASExprStatement* ReMFParser::parseArguments() { - RplASExprStatement* first = NULL; - RplASExprStatement* last = NULL; + ReASExprStatement* first = NULL; + ReASExprStatement* last = NULL; bool again = false; do { - RplASItem* expr = parseExpr(0); + ReASItem* expr = parseExpr(0); if (! m_lexer.currentToken()->isOperator(O_COMMA, O_RPARENTH)) syntaxError(L_PARSE_ARGS_NO_COMMA_OR_PARENT, "',' or ')' expected"); again = m_lexer.currentToken()->isOperator(O_COMMA); - RplASExprStatement* current = new RplASExprStatement(); + ReASExprStatement* current = new ReASExprStatement(); current->setPosition(expr->position()); current->setChild2(expr); if (first == NULL) diff --git a/rplexpr/rplmfparser.hpp b/expr/ReMFParser.hpp similarity index 64% rename from rplexpr/rplmfparser.hpp rename to expr/ReMFParser.hpp index d1d9d61..fb5aeca 100644 --- a/rplexpr/rplmfparser.hpp +++ b/expr/ReMFParser.hpp @@ -7,10 +7,10 @@ */ -#ifndef RPLMFPARSER_HPP -#define RPLMFPARSER_HPP +#ifndef REMFPARSER_HPP +#define REMFPARSER_HPP -class RplMFParser : public RplParser +class ReMFParser : public ReParser { public: enum Keyword { @@ -65,43 +65,43 @@ public: ". ( ) [ ] { }" #define MF_RIGHT_ASSOCIATIVES "= += -= /= *= %= **= |= &= <<= >>= >>>= ** ." public: - RplMFParser(RplSource& source, RplASTree& ast); + ReMFParser(ReSource& source, ReASTree& ast); public: - RplASItem* parseIf(); - RplASItem* parseWhile(); - RplASItem* parseRepeat(); - RplASItem* parseFor(); - RplASVarDefinition* parseVarDefinition(RplASNamedValue::Attributes attribute); - RplASItem* parseExpr(int depth); - RplASItem* parseBody(Keyword keywordStop, Keyword keywordStop2 = K_UNDEF, + ReASItem* parseIf(); + ReASItem* parseWhile(); + ReASItem* parseRepeat(); + ReASItem* parseFor(); + ReASVarDefinition* parseVarDefinition(ReASNamedValue::Attributes attribute); + ReASItem* parseExpr(int depth); + ReASItem* parseBody(Keyword keywordStop, Keyword keywordStop2 = K_UNDEF, int builtinVars = 0); void parseMethod(); void parseClass(); void parseImport(); - RplASItem* parseModule(RplSourceUnitName name); + ReASItem* parseModule(ReSourceUnitName name); void parse(); - RplASItem*parseExprStatement(bool eatSemicolon = true); - RplASItem*parseList(); - RplASItem*parseMap(); + ReASItem*parseExprStatement(bool eatSemicolon = true); + ReASItem*parseList(); + ReASItem*parseMap(); protected: - RplASExprStatement* parseArguments(); - RplASItem* parseOperand(int level, RplASItem* parent = NULL); - RplASVariant* tokenToVariant(RplToken* token, bool endsWithComma, - RplASNode1* parent); - RplASVariant*createFormula(RplASNode1* parent); - RplASItem* buildVarOrField(const QByteArray& name, - const RplSourcePosition* position, - RplASItem* parent); - RplASVarDefinition* parseParameterList(); - RplASItem* parseLocalVar(); - RplASVarDefinition* buildVarDef(RplASNamedValue* var); + ReASExprStatement* parseArguments(); + ReASItem* parseOperand(int level, ReASItem* parent = NULL); + ReASVariant* tokenToVariant(ReToken* token, bool endsWithComma, + ReASNode1* parent); + ReASVariant*createFormula(ReASNode1* parent); + ReASItem* buildVarOrField(const QByteArray& name, + const ReSourcePosition* position, + ReASItem* parent); + ReASVarDefinition* parseParameterList(); + ReASItem* parseLocalVar(); + ReASVarDefinition* buildVarDef(ReASNamedValue* var); protected: - static RplASBinaryOp::BinOperator convertBinaryOp(int op); - static RplASUnaryOp::UnaryOp convertUnaryOp(int op); + static ReASBinaryOp::BinOperator convertBinaryOp(int op); + static ReASUnaryOp::UnaryOp convertUnaryOp(int op); private: ///syntax token builder. /// Note: the super class contains a reference with the same name - RplLexer m_lexer; + ReLexer m_lexer; }; -#endif // RPLMFPARSER_HPP +#endif // REMFPARSER_HPP diff --git a/rplexpr/rplparser.cpp b/expr/ReParser.cpp similarity index 84% rename from rplexpr/rplparser.cpp rename to expr/ReParser.cpp index de01de5..a0be1bb 100644 --- a/rplexpr/rplparser.cpp +++ b/expr/ReParser.cpp @@ -10,16 +10,16 @@ * * @brief Generally usable parts of an parser, e.g. error handling. */ -/** @file rplexpr/rplparser.hpp +/** @file expr/ReParser.hpp * * @brief Definition of a generally usable parts of an parser. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" -/** @class RplSyntaxError rplparser.hpp "rplexpr/rplparser.hpp" +/** @class RSyntaxError ReParser.hpp "expr/ReParser.hpp" * * @brief Implements an exception used for jumping out from many nested calls. * @@ -36,7 +36,7 @@ * @param reason the reason of the exception * @return */ -RplSyntaxError::RplSyntaxError(const char* reason) : +ReSyntaxError::ReSyntaxError(const char* reason) : m_reason(reason) { } @@ -45,12 +45,12 @@ RplSyntaxError::RplSyntaxError(const char* reason) : * * @return the reason */ -const char* RplSyntaxError::reason() const +const char* ReSyntaxError::reason() const { return m_reason; } -/** @class RplParserStop rplparser.hpp "rplexpr/rplparser.hpp" +/** @class RplParserStop ReParser.hpp "expr/ReParser.hpp" * * @brief Implements an exception used for jumping out from many nested calls. * @@ -64,11 +64,11 @@ const char* RplSyntaxError::reason() const * @param reason the reason of the exception */ RplParserStop::RplParserStop(const char* reason) : - RplSyntaxError(reason) + ReSyntaxError(reason) { } -/** @class RplParser rplparser.hpp "rplexpr/rplparser.hpp" +/** @class ReParser ReParser.hpp "expr/ReParser.hpp" * * @brief Implements a base class for parsers. * @@ -80,7 +80,7 @@ RplParserStop::RplParserStop(const char* reason) : * @param lexer the tokenizer * @param tree the abstract syntax tree */ -RplParser::RplParser(RplLexer& lexer, RplASTree& tree) : +ReParser::ReParser(ReLexer& lexer, ReASTree& tree) : m_lexer(lexer), m_tree(tree), m_messages(), @@ -100,8 +100,8 @@ RplParser::RplParser(RplLexer& lexer, RplASTree& tree) : * @param message message with placeholdes like sprintf() * @return false (for chaining) */ -bool RplParser::addSimpleMessage(LevelTag prefix, int location, - const RplSourcePosition* position, +bool ReParser::addSimpleMessage(LevelTag prefix, int location, + const ReSourcePosition* position, const char* message){ char buffer[2048]; QByteArray msg; @@ -128,8 +128,8 @@ bool RplParser::addSimpleMessage(LevelTag prefix, int location, * @param varList the variable argument list * @return false (for chaining) */ -bool RplParser::addMessage(LevelTag prefix, int location, - const RplSourcePosition* position, +bool ReParser::addMessage(LevelTag prefix, int location, + const ReSourcePosition* position, const char* format, va_list varList){ char buffer[2048]; qvsnprintf(buffer, sizeof buffer, format, varList); @@ -145,10 +145,10 @@ bool RplParser::addMessage(LevelTag prefix, int location, * @param message error message */ -void RplParser::syntaxError(int location, const char* message) +void ReParser::syntaxError(int location, const char* message) { addSimpleMessage(LT_ERROR, location, m_lexer.currentPosition(), message); - throw RplSyntaxError(message); + throw RSyntaxError(message); } /** @@ -166,9 +166,9 @@ void RplParser::syntaxError(int location, const char* message) * @param position position of the starting symbol */ -void RplParser::syntaxError(int location, const char* message, +void ReParser::syntaxError(int location, const char* message, const char* symbol, - const RplSourcePosition* position) + const ReSourcePosition* position) { char buffer[256]; char buffer2[512]; @@ -178,7 +178,7 @@ void RplParser::syntaxError(int location, const char* message, addSimpleMessage(LT_ERROR, location, m_lexer.currentPosition(), message); addSimpleMessage(LT_INFO, location + 1, position, buffer2); - throw RplSyntaxError(message); + throw RSyntaxError(message); } /** @@ -191,7 +191,7 @@ void RplParser::syntaxError(int location, const char* message, * @param ... optional: the variable argument list * @return false (for chaining) */ -bool RplParser::error(int location, const char* format, ...) +bool ReParser::error(int location, const char* format, ...) { va_list ap; va_start(ap, format); @@ -213,7 +213,7 @@ bool RplParser::error(int location, const char* format, ...) * @param ... optional: the variable argument list * @return false (for chaining) */ -bool RplParser::error(int location, const RplSourcePosition* position, +bool ReParser::error(int location, const ReSourcePosition* position, const char* message, const char* message2) { addSimpleMessage(LT_ERROR, location, m_lexer.currentPosition(), message); @@ -232,7 +232,7 @@ bool RplParser::error(int location, const RplSourcePosition* position, * @param format message with placeholdes like sprintf() * @param ... optional: the variable argument list */ -void RplParser::warning(int location, const char* format, ...) +void ReParser::warning(int location, const char* format, ...) { va_list ap; va_start(ap, format); @@ -246,7 +246,7 @@ void RplParser::warning(int location, const char* format, ...) * * @return the count of errors occurred until now */ -int RplParser::errors() const +int ReParser::errors() const { return m_errors; } @@ -255,7 +255,7 @@ int RplParser::errors() const * * @return the count of errors occurred until now */ -int RplParser::warnings() const +int ReParser::warnings() const { return m_warnings; } diff --git a/rplexpr/rplparser.hpp b/expr/ReParser.hpp similarity index 70% rename from rplexpr/rplparser.hpp rename to expr/ReParser.hpp index cb21c4c..80b9f15 100644 --- a/rplexpr/rplparser.hpp +++ b/expr/ReParser.hpp @@ -7,25 +7,25 @@ */ -#ifndef RPLPARSER_HPP -#define RPLPARSER_HPP +#ifndef REPARSER_HPP +#define REPARSER_HPP -class RplSyntaxError +class ReSyntaxError { public: - RplSyntaxError(const char* reason); + ReSyntaxError(const char* reason); public: const char* reason() const; private: const char* m_reason; }; -class RplParserStop : public RplSyntaxError { +class RplParserStop : public ReSyntaxError { public: RplParserStop(const char* reason); }; -class RplParser { +class ReParser { public: enum LevelTag { LT_ERROR = 'E', @@ -36,26 +36,26 @@ public: public: typedef QList MessageList; public: - RplParser(RplLexer& lexer, RplASTree& ast); + ReParser(ReLexer& lexer, ReASTree& ast); public: bool addSimpleMessage(LevelTag prefix, int location, - const RplSourcePosition* pos, + const ReSourcePosition* pos, const char* message); bool addMessage(LevelTag prefix, int location, - const RplSourcePosition* pos, + const ReSourcePosition* 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); + const ReSourcePosition* position); bool error(int location, const char* format, ...); - bool error(int location, const RplSourcePosition* position, + bool error(int location, const ReSourcePosition* 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; + ReLexer& m_lexer; + ReASTree& m_tree; MessageList m_messages; int m_errors; int m_warnings; @@ -63,4 +63,4 @@ protected: int m_maxWarnings; }; -#endif // RPLPARSER_HPP +#endif // REPARSER_HPP diff --git a/rplexpr/rplsource.cpp b/expr/ReSource.cpp similarity index 71% rename from rplexpr/rplsource.cpp rename to expr/ReSource.cpp index b10feac..b9e21e9 100644 --- a/rplexpr/rplsource.cpp +++ b/expr/ReSource.cpp @@ -9,28 +9,28 @@ /** @file * @brief Reading from several input media. * - * The abstract base class RplReader and its concrete derivations - * RplStringReader, RplFileReader are used to read + * The abstract base class ReReader and its concrete derivations + * ReStringReader, ReFileReader are used to read * from one medium. - * The RplSource combines several readers and build an uniquely + * The ReSource combines several readers and build an uniquely * usable input stream. */ -/** @file rplexpr/rplsource.hpp +/** @file expr/ReSource.hpp * * @brief Definitions for reading from several input media. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" -/** @class RplSource rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReSource ReSource.hpp "expr/ReSource.hpp" * * @brief Stores all source positions. * */ -/** @class RplSourceUnit rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReSourceUnit ReSource.hpp "expr/ReSource.hpp" * * @brief Implements the base class of input source units. * @@ -42,7 +42,7 @@ * @param name name of the unit * @param reader the reader which can read the unit */ -RplSourceUnit::RplSourceUnit(RplSourceUnitName name, RplReader* reader) : +ReSourceUnit::ReSourceUnit(ReSourceUnitName name, ReReader* reader) : m_name(name), m_lineNo(0), m_reader(reader) { @@ -51,14 +51,14 @@ RplSourceUnit::RplSourceUnit(RplSourceUnitName name, RplReader* reader) : /** * @brief Destructor. */ -RplSourceUnit::~RplSourceUnit() { +ReSourceUnit::~ReSourceUnit() { } /** * @brief Returns the name. * @return the name */ -RplSourceUnitName RplSourceUnit::name() const { +ReSourceUnitName ReSourceUnit::name() const { return m_name.constData(); } @@ -67,7 +67,7 @@ RplSourceUnitName RplSourceUnit::name() const { * * @return the line number */ -int RplSourceUnit::lineNo() const { +int ReSourceUnit::lineNo() const { return m_lineNo; } @@ -76,7 +76,7 @@ int RplSourceUnit::lineNo() const { * * @param lineNo the new line number */ -void RplSourceUnit::setLineNo(int lineNo) { +void ReSourceUnit::setLineNo(int lineNo) { m_lineNo = lineNo; } /** @@ -84,11 +84,11 @@ void RplSourceUnit::setLineNo(int lineNo) { * * @return the reader belonging to the instance */ -RplReader* RplSourceUnit::reader() const { +ReReader* ReSourceUnit::reader() const { return m_reader; } -/** @class RplSourcePosition rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReSourcePosition ReSource.hpp "expr/ReSource.hpp" * * @brief Stores a precise position in the input source. * @@ -104,7 +104,7 @@ RplReader* RplSourceUnit::reader() const { /** * @brief Constructor. */ -RplSourcePosition::RplSourcePosition() : +ReSourcePosition::ReSourcePosition() : m_sourceUnit(NULL), m_lineNo(0), m_column(0), @@ -119,20 +119,20 @@ RplSourcePosition::RplSourcePosition() : * @param lineNo line number inside the input source * @param colNo distance to the line start */ -RplSourcePosition::RplSourcePosition(RplSourceUnit* unit, int lineNo, +ReSourcePosition::ReSourcePosition(ReSourceUnit* unit, int lineNo, int colNo) : m_sourceUnit(unit), m_lineNo(lineNo), m_column(colNo), m_caller(NULL) { - RplReader* reader = dynamic_cast(unit->reader()); + ReReader* reader = dynamic_cast(unit->reader()); m_caller = reader->source().caller(); } /** * @brief Destructor */ -RplSourcePosition::~ RplSourcePosition(){ +ReSourcePosition::~ ReSourcePosition(){ // That should never occure! assert(false); } @@ -144,7 +144,7 @@ RplSourcePosition::~ RplSourcePosition(){ * @param buffer buffer for the instance * @return buffer */ -void*RplSourcePosition::operator new(size_t, void* buffer) +void*ReSourcePosition::operator new(size_t, void* buffer) { return buffer; } @@ -154,12 +154,12 @@ void*RplSourcePosition::operator new(size_t, void* buffer) * * @return a description of the instance */ -QString RplSourcePosition::toString() const +ReString ReSourcePosition::toString() const { char buffer[512]; utf8(buffer, sizeof buffer); - return QString(buffer); + return ReString(buffer); } /** @@ -169,7 +169,7 @@ QString RplSourcePosition::toString() const * @param bufferSize the size of the buffer * @return buffer */ -char* RplSourcePosition::utf8(char buffer[], size_t bufferSize) const +char* ReSourcePosition::utf8(char buffer[], size_t bufferSize) const { qsnprintf(buffer, bufferSize, "%s:%d:%d", m_sourceUnit == NULL ? "" : m_sourceUnit->name(), @@ -181,7 +181,7 @@ char* RplSourcePosition::utf8(char buffer[], size_t bufferSize) const * @brief Returns the line number. * @return the line number */ -int RplSourcePosition::lineNo() const +int ReSourcePosition::lineNo() const { return m_lineNo; } @@ -191,7 +191,7 @@ int RplSourcePosition::lineNo() const * * @param lineNo the new lineNo */ -void RplSourcePosition::setLineNo(int lineNo) +void ReSourcePosition::setLineNo(int lineNo) { m_lineNo = lineNo; } @@ -200,7 +200,7 @@ void RplSourcePosition::setLineNo(int lineNo) * * @return the column of instance. */ -int RplSourcePosition::column() const +int ReSourcePosition::column() const { return m_column; } @@ -210,7 +210,7 @@ int RplSourcePosition::column() const * * @param column the new column */ -void RplSourcePosition::setColumn(int column) +void ReSourcePosition::setColumn(int column) { m_column = column; } @@ -220,7 +220,7 @@ void RplSourcePosition::setColumn(int column) * * @return the source unit of the instance */ -RplSourceUnit* RplSourcePosition::sourceUnit() const +ReSourceUnit* ReSourcePosition::sourceUnit() const { return m_sourceUnit; } @@ -230,14 +230,14 @@ RplSourceUnit* RplSourcePosition::sourceUnit() const * * @param sourceUnit the new source unit of the instance */ -void RplSourcePosition::setSourceUnit(RplSourceUnit* sourceUnit) +void ReSourcePosition::setSourceUnit(ReSourceUnit* sourceUnit) { m_sourceUnit = sourceUnit; m_lineNo = sourceUnit->lineNo(); } -/** @class RplReader rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReReader ReSource.hpp "expr/ReSource.hpp" * * @brief Implements a base class for readers of different media. */ @@ -248,7 +248,7 @@ void RplSourcePosition::setSourceUnit(RplSourceUnit* sourceUnit) * * @param source the parent */ -RplReader::RplReader(RplSource& source) : +ReReader::ReReader(ReSource& source) : m_currentSourceUnit(NULL), m_units(), m_source(source) { @@ -257,7 +257,7 @@ RplReader::RplReader(RplSource& source) : /** * @brief Destructor. */ -RplReader::~RplReader() +ReReader::~ReReader() { clear(); } @@ -265,11 +265,11 @@ RplReader::~RplReader() /** * @brief Frees the resources. */ -void RplReader::clear() +void ReReader::clear() { UnitMap::iterator it; for(it = m_units.begin(); it != m_units.end(); it++) { - RplStringSourceUnit* unit = (RplStringSourceUnit*)(*it); + ReStringSourceUnit* unit = (ReStringSourceUnit*)(*it); delete unit; } m_units.clear(); @@ -281,7 +281,7 @@ void RplReader::clear() * * @return the parent, a source instance */ -RplSource&RplReader::source() +ReSource&ReReader::source() { return m_source; } @@ -290,7 +290,7 @@ RplSource&RplReader::source() * * @return the source unit */ -RplSourceUnit* RplReader::currentSourceUnit() const { +ReSourceUnit* ReReader::currentSourceUnit() const { return m_currentSourceUnit; } @@ -301,7 +301,7 @@ RplSourceUnit* RplReader::currentSourceUnit() const { * @return true: source unit exists
* false: source unit not found */ -bool RplReader::setCurrentSourceUnit(RplSourceUnitName& sourceUnit) { +bool ReReader::setCurrentSourceUnit(ReSourceUnitName& sourceUnit) { bool rc = m_units.contains(sourceUnit); if(rc) { m_currentSourceUnit = m_units.value(sourceUnit); @@ -313,37 +313,37 @@ bool RplReader::setCurrentSourceUnit(RplSourceUnitName& sourceUnit) { /** * @brief Removes the "latest" sourceUnit. */ -void RplReader::removeSourceUnit() { +void ReReader::removeSourceUnit() { m_currentSourceUnit = m_source.popSourceUnit(this);; } -/** @class RplSourcePositionBlock rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReSourcePositionBlock ReSource.hpp "expr/ReSource.hpp" * - * @brief Efficient heap of RplSourcePosition instances. + * @brief Efficient heap of ReSourcePosition instances. * - * The RplSourcePosition heap is only growing. The deletion is + * The ReSourcePosition heap is only growing. The deletion is * done for all entries together. * Therefore a simple allocation is possible with blocks. */ -RplSourcePositionBlock::RplSourcePositionBlock() : +ReSourcePositionBlock::ReSourcePositionBlock() : m_successor(NULL) // m_positions { memset(m_positions, 0, sizeof m_positions); } -/** @class RplSource rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReSource ReSource.hpp "expr/ReSource.hpp" * * @brief Administrates a set of input sources with different readers. * * An input stream can be built by some different resources, e.g. files - * and memory buffers. The RplSource can administrate these resources. + * and memory buffers. The ReSource can administrate these resources. */ /** * @brief Constructor. */ -RplSource::RplSource() : +ReSource::ReSource() : m_sourcePositionStack(), m_sourcePositionBlock(NULL), m_countPositionBlock(RPL_POSITIONS_PER_BLOCK + 1), @@ -359,24 +359,24 @@ RplSource::RplSource() : /** * @brief Destructor. */ -RplSource::~RplSource() { +ReSource::~ReSource() { destroy(); } /** * @brief Frees the resources of the instance. */ -void RplSource::destroy() +void ReSource::destroy() { m_sourcePositionStack.clear(); m_readers.clear(); m_sourceUnits.clear(); m_currentReader = NULL; - RplSourcePositionBlock* block = m_sourcePositionBlock; + ReSourcePositionBlock* block = m_sourcePositionBlock; m_sourcePositionBlock = NULL; m_countPositionBlock = RPL_POSITIONS_PER_BLOCK + 1; while(block != NULL){ - RplSourcePositionBlock* last = block; + ReSourcePositionBlock* last = block; block = block->m_successor; delete last; } @@ -392,7 +392,7 @@ void RplSource::destroy() * @param unit unit to find * @return a permanently valid unit name */ -RplSourceUnitName RplSource::permanentUnitName(RplSourceUnitName unit) { +ReSourceUnitName ReSource::permanentUnitName(ReSourceUnitName unit) { return unit; } @@ -401,7 +401,7 @@ RplSourceUnitName RplSource::permanentUnitName(RplSourceUnitName unit) { * * @return the stack */ -QStack RplSource::sourcePositionStack() const { +QStack ReSource::sourcePositionStack() const { return m_sourcePositionStack; } @@ -409,7 +409,7 @@ QStack RplSource::sourcePositionStack() const { * @brief Returns the source unit stack. * @return the stack of the source units */ -QStack& RplSource::sourceUnitStack() +QStack& ReSource::sourceUnitStack() { return m_unitStack; } @@ -419,7 +419,7 @@ QStack& RplSource::sourceUnitStack() * * @param reader the new reader. Will be freed in the destructor */ -void RplSource::addReader(RplReader* reader) { +void ReSource::addReader(ReReader* reader) { m_readers.push_back(reader); if (m_currentReader == NULL) m_currentReader = reader; @@ -430,7 +430,7 @@ void RplSource::addReader(RplReader* reader) { * * @param unit the new unit. Will be freed in the destructor */ -void RplSource::addSourceUnit(RplSourceUnit* unit) { +void ReSource::addSourceUnit(ReSourceUnit* unit) { m_sourceUnits.push_back(unit); } @@ -444,15 +444,15 @@ void RplSource::addSourceUnit(RplSourceUnit* unit) { * @param caller the position of the include * */ -bool RplSource::startUnit(RplSourceUnitName unit, - const RplSourcePosition& caller) { +bool ReSource::startUnit(ReSourceUnitName unit, + const ReSourcePosition& caller) { m_sourcePositionStack.push_back(&caller); - RplReader* reader = NULL; - QList::iterator it; + ReReader* reader = NULL; + QList::iterator it; for(it = m_readers.begin(); reader == NULL && it != m_readers.end(); it++) { - RplReader* current = *it; + ReReader* current = *it; if(current->openSourceUnit(unit)) { reader = current; m_currentReader = current; @@ -467,7 +467,7 @@ bool RplSource::startUnit(RplSourceUnitName unit, * * @param unit the source unit */ -void RplSource::pushSourceUnit(RplSourceUnit* unit) { +void ReSource::pushSourceUnit(ReSourceUnit* unit) { m_unitStack.push(unit); } @@ -478,8 +478,8 @@ void RplSource::pushSourceUnit(RplSourceUnit* unit) { * @return NULL: the current reader does not have an open source unit
* otherwise: the last entry from the source unit stack */ -RplSourceUnit* RplSource::popSourceUnit(RplReader* reader) { - RplSourceUnit* rc = NULL; +ReSourceUnit* ReSource::popSourceUnit(ReReader* reader) { + ReSourceUnit* rc = NULL; if(m_unitStack.size() > 0) m_unitStack.pop(); m_currentReader = m_unitStack.size() <= 0 @@ -503,7 +503,7 @@ RplSourceUnit* RplSource::popSourceUnit(RplReader* reader) { * @return NULL: no reader active
* otherwise: the current reader */ -RplReader* RplSource::currentReader() { +ReReader* ReSource::currentReader() { return m_currentReader; } @@ -515,20 +515,20 @@ RplReader* RplSource::currentReader() { * @param colNo the column in the line * @return a new instance of a source position */ -const RplSourcePosition* RplSource::newPosition(int colNo) +const ReSourcePosition* ReSource::newPosition(int colNo) { if (m_countPositionBlock >= RPL_POSITIONS_PER_BLOCK){ - RplSourcePositionBlock* newBlock = new RplSourcePositionBlock; + ReSourcePositionBlock* newBlock = new ReSourcePositionBlock; newBlock->m_successor = m_sourcePositionBlock; m_sourcePositionBlock = newBlock; m_countPositionBlock = 0; } - unsigned offset = m_countPositionBlock * sizeof(RplSourcePosition); + unsigned offset = m_countPositionBlock * sizeof(ReSourcePosition); m_countPositionBlock++; char* posInBlock = &m_sourcePositionBlock->m_positions[offset]; - RplSourceUnit* unit = dynamic_cast( + ReSourceUnit* unit = dynamic_cast( m_currentReader->currentSourceUnit()); - RplSourcePosition* rc = new (posInBlock) RplSourcePosition( + ReSourcePosition* rc = new (posInBlock) ReSourcePosition( unit, unit->lineNo(), colNo); return rc; } @@ -536,7 +536,7 @@ const RplSourcePosition* RplSource::newPosition(int colNo) /** * @brief Resets all states in the source. */ -void RplSource::clear() +void ReSource::clear() { destroy(); } @@ -547,13 +547,13 @@ void RplSource::clear() * @return NULL: stack is empty
* the top of the source unit stack */ -const RplSourcePosition* RplSource::caller() const +const ReSourcePosition* ReSource::caller() const { return m_sourcePositionStack.size() == 0 ? NULL : m_sourcePositionStack.top(); } -/** @class RplStringSourceUnit rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReStringSourceUnit ReSource.hpp "expr/ReSource.hpp" * * @brief Stores the state of a string based source unit. * @@ -566,9 +566,9 @@ const RplSourcePosition* RplSource::caller() const * @param content content of the unit * @param reader the parent */ -RplStringSourceUnit::RplStringSourceUnit(RplSourceUnitName name, - const RplSourceUnitContent& content, RplStringReader* reader) : - RplSourceUnit(name, reader), +ReStringSourceUnit::ReStringSourceUnit(ReSourceUnitName name, + const ReSourceUnitContent& content, ReStringReader* reader) : + ReSourceUnit(name, reader), m_currentPosition(0), m_content(content) { } @@ -576,7 +576,7 @@ RplStringSourceUnit::RplStringSourceUnit(RplSourceUnitName name, /** * @brief Destructor. */ -RplStringSourceUnit::~RplStringSourceUnit() { +ReStringSourceUnit::~ReStringSourceUnit() { } /** * @brief Returns the current read position. @@ -584,7 +584,7 @@ RplStringSourceUnit::~RplStringSourceUnit() { * @return the offset (count of QChars) of the end of the last read block * inside m_content */ -int RplStringSourceUnit::currentPosition() const { +int ReStringSourceUnit::currentPosition() const { return m_currentPosition; } @@ -594,7 +594,7 @@ int RplStringSourceUnit::currentPosition() const { * @param currentPosition the offset (count of QChars) of the end of * the last read block inside m_content */ -void RplStringSourceUnit::setCurrentPosition(int currentPosition) { +void ReStringSourceUnit::setCurrentPosition(int currentPosition) { m_currentPosition = currentPosition; } /** @@ -602,11 +602,11 @@ void RplStringSourceUnit::setCurrentPosition(int currentPosition) { * * @return the content */ -RplSourceUnitContent RplStringSourceUnit::content() const { +ReSourceUnitContent ReStringSourceUnit::content() const { return m_content.constData(); } -/** @class RplStringReader rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReStringReader ReSource.hpp "expr/ReSource.hpp" * * @brief Implements a source which provides reading from memory based buffers. * @@ -618,14 +618,14 @@ RplSourceUnitContent RplStringSourceUnit::content() const { * * @param source the parent */ -RplStringReader::RplStringReader(RplSource& source) : - RplReader(source) { +ReStringReader::ReStringReader(ReSource& source) : + ReReader(source) { } /** * @brief Destructor. */ -RplStringReader::~RplStringReader() { +ReStringReader::~ReStringReader() { clear(); } @@ -635,13 +635,13 @@ RplStringReader::~RplStringReader() { * @param unit name of the source * @return NULL: unknown source
* otherwise: an instance of a sub class of - * RplSourceUnit + * ReSourceUnit */ -RplSourceUnit* RplStringReader::openSourceUnit(RplSourceUnitName unit) { - RplSourceUnit* rc = NULL; +ReSourceUnit* ReStringReader::openSourceUnit(ReSourceUnitName unit) { + ReSourceUnit* rc = NULL; if(setCurrentSourceUnit(unit)) { rc = m_currentSourceUnit; - ((RplStringSourceUnit*) rc)->setCurrentPosition(0); + ((ReStringSourceUnit*) rc)->setCurrentPosition(0); } return rc; } @@ -656,7 +656,7 @@ RplSourceUnit* RplStringReader::openSourceUnit(RplSourceUnitName unit) { * @return false: no more input available
* true: success */ -bool RplStringReader::nextLine(int maxSize, QByteArray& buffer, bool& hasMore) { +bool ReStringReader::nextLine(int maxSize, QByteArray& buffer, bool& hasMore) { bool rc = m_currentSourceUnit != NULL; if (rc){ m_currentSourceUnit->setLineNo(m_currentSourceUnit->lineNo() + 1); @@ -676,9 +676,9 @@ bool RplStringReader::nextLine(int maxSize, QByteArray& buffer, bool& hasMore) { * @return false: no more input available
* true: success */ -bool RplStringReader::fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore) { - RplStringSourceUnit* unit = (RplStringSourceUnit*) m_currentSourceUnit; - RplSourceUnitContent content = unit->content(); +bool ReStringReader::fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore) { + ReStringSourceUnit* unit = (ReStringSourceUnit*) m_currentSourceUnit; + ReSourceUnitContent content = unit->content(); int startPos = unit->currentPosition(); const char* start = content + startPos; const char* end = strchr(start, '\n'); @@ -704,10 +704,10 @@ bool RplStringReader::fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore) * @param name name of the medium * @param content */ -void RplStringReader::addSource(RplSourceUnitName name, - RplSourceUnitContent content) { - // Deletion in the destructor of the base class RplReader - RplStringSourceUnit* unit = new RplStringSourceUnit(name, content, this); +void ReStringReader::addSource(ReSourceUnitName name, + ReSourceUnitContent content) { + // Deletion in the destructor of the base class ReReader + ReStringSourceUnit* unit = new ReStringSourceUnit(name, content, this); m_units.insert(m_units.begin(), unit->name(), unit); m_currentSourceUnit = unit; } @@ -718,26 +718,26 @@ void RplStringReader::addSource(RplSourceUnitName name, * @param name name of the source unit * @param content new content */ -void RplStringReader::replaceSource(RplSourceUnitName name, - RplSourceUnitContent content) +void ReStringReader::replaceSource(ReSourceUnitName name, + ReSourceUnitContent content) { if (m_units.contains(name)){ - RplStringSourceUnit* unit = dynamic_cast(m_units[name]); + ReStringSourceUnit* unit = dynamic_cast(m_units[name]); unit->m_content = content; } } -/** @class RplFileSourceUnit rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReFileSourceUnit ReSource.hpp "expr/ReSource.hpp" * * @brief Stores the state of a file based source unit. * - * This is the mostly used implementation of the RplSourceUnit/RplReader. + * This is the mostly used implementation of the ReSourceUnit/ReReader. */ -RplFileSourceUnit::RplFileSourceUnit(RplSourceUnitName filename, - RplFileReader* reader) : - RplSourceUnit(filename, reader), +ReFileSourceUnit::ReFileSourceUnit(ReSourceUnitName filename, + ReFileReader* reader) : + ReSourceUnit(filename, reader), m_currentPosition(0), m_fp(fopen(filename, "r")), m_textStream(m_fp, QIODevice::ReadOnly), @@ -749,16 +749,16 @@ RplFileSourceUnit::RplFileSourceUnit(RplSourceUnitName filename, /** * @brief Destructor. */ -RplFileSourceUnit::~RplFileSourceUnit() +ReFileSourceUnit::~ReFileSourceUnit() { fclose(m_fp); } -bool RplFileSourceUnit::isOpen() const +bool ReFileSourceUnit::isOpen() const { return m_fp != NULL; } -/** @class RplFileReader rplsource.hpp "rplexpr/rplsource.hpp" +/** @class ReFileReader ReSource.hpp "expr/ReSource.hpp" * * @brief Implements a source which provides reading from memory based buffers. * @@ -768,15 +768,15 @@ bool RplFileSourceUnit::isOpen() const /** * @brief Constructor. */ -RplFileReader::RplFileReader(RplSource& source) : - RplReader(source) +ReFileReader::ReFileReader(ReSource& source) : + ReReader(source) { } /** * @brief Destructor. */ -RplFileReader::~RplFileReader() { +ReFileReader::~ReFileReader() { } /** @@ -785,13 +785,13 @@ RplFileReader::~RplFileReader() { * @param unit name of the source * @return NULL: unknown source
* otherwise: an instance of a sub class of - * RplSourceUnit + * ReSourceUnit */ -RplSourceUnit* RplFileReader::openSourceUnit(RplSourceUnitName unit) { - RplSourceUnit* rc = NULL; +ReSourceUnit* ReFileReader::openSourceUnit(ReSourceUnitName unit) { + ReSourceUnit* rc = NULL; if(m_units.contains(unit)) { rc = *m_units.find(unit); - m_currentSourceUnit = static_cast(rc); + m_currentSourceUnit = static_cast(rc); } return rc; } @@ -806,8 +806,8 @@ RplSourceUnit* RplFileReader::openSourceUnit(RplSourceUnitName unit) { * @return false: no more input available
* true: success */ -bool RplFileReader::nextLine(int maxSize, QByteArray& buffer, bool& hasMore) { - RplFileSourceUnit* unit = static_cast +bool ReFileReader::nextLine(int maxSize, QByteArray& buffer, bool& hasMore) { + ReFileSourceUnit* unit = static_cast (m_currentSourceUnit); bool rc = ! feof(unit->m_fp); if(! rc) { @@ -839,8 +839,8 @@ bool RplFileReader::nextLine(int maxSize, QByteArray& buffer, bool& hasMore) { * @return false: no more input available
* true: success */ -bool RplFileReader::fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore) { - RplFileSourceUnit* unit = static_cast(m_currentSourceUnit); +bool ReFileReader::fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore) { + ReFileSourceUnit* unit = static_cast(m_currentSourceUnit); int start = unit->m_currentPosition; QByteArray& content = unit->m_line; int size = content.size() - start; @@ -857,9 +857,9 @@ bool RplFileReader::fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore) { * * @param filename the file' name (relative or absolute) */ -void RplFileReader::addSource(RplSourceUnitName filename) { - // Deleting in ~RplSourceUnit(): - RplFileSourceUnit* unit = new RplFileSourceUnit(filename, this); +void ReFileReader::addSource(ReSourceUnitName filename) { + // Deleting in ~ReSourceUnit(): + ReFileSourceUnit* unit = new ReFileSourceUnit(filename, this); m_units.insert(m_units.begin(), unit->name(), unit); m_currentSourceUnit = unit; } diff --git a/rplexpr/rplsource.hpp b/expr/ReSource.hpp similarity index 51% rename from rplexpr/rplsource.hpp rename to expr/ReSource.hpp index 40f80b9..cba5ea0 100644 --- a/rplexpr/rplsource.hpp +++ b/expr/ReSource.hpp @@ -11,64 +11,64 @@ #define RPLSOURCE_HPP // type of buffer names and filenames. Codec: UTF-8 -typedef const char* RplSourceUnitName; +typedef const char* ReSourceUnitName; -typedef const char* RplSourceUnitContent; +typedef const char* ReSourceUnitContent; -class RplSource; -class RplReader; +class ReSource; +class ReReader; -class RplSourceUnit { +class ReSourceUnit { public: - RplSourceUnit(const char* name, RplReader* reader); - virtual ~RplSourceUnit(); + ReSourceUnit(const char* name, ReReader* reader); + virtual ~ReSourceUnit(); public: const char* name() const; int lineNo() const; void setLineNo(int lineNo); - RplReader* reader() const; + ReReader* reader() const; protected: QByteArray m_name; int m_lineNo; - RplReader* m_reader; + ReReader* m_reader; }; -class RplSourcePosition { +class ReSourcePosition { public: - RplSourcePosition(); - RplSourcePosition(RplSourceUnit* unit, int lineNo, int colNo); - ~ RplSourcePosition(); + ReSourcePosition(); + ReSourcePosition(ReSourceUnit* unit, int lineNo, int colNo); + ~ ReSourcePosition(); void* operator new(size_t cbSize, void* buffer); private: /// forbid usage of the copy constructor! - RplSourcePosition(const RplSourcePosition& source); + ReSourcePosition(const ReSourcePosition& source); /// forbid usage of the the assignment! - RplSourcePosition& operator=(const RplSourcePosition& source); + ReSourcePosition& operator=(const ReSourcePosition& source); public: - QString toString() const; + ReString toString() const; int lineNo() const; void setLineNo(int lineNo); int column() const; void setColumn(int column); - RplSourceUnit* sourceUnit() const; - void setSourceUnit(RplSourceUnit* sourceUnit); + ReSourceUnit* sourceUnit() const; + void setSourceUnit(ReSourceUnit* sourceUnit); char*utf8(char buffer[], size_t bufferSize) const; private: - RplSourceUnit* m_sourceUnit; + ReSourceUnit* m_sourceUnit; int m_lineNo; int m_column; - const RplSourcePosition* m_caller; + const ReSourcePosition* m_caller; }; -class RplReader { +class ReReader { public: - typedef RplCharPtrMap UnitMap; + typedef ReCharPtrMap UnitMap; public: - RplReader(RplSource& source); - ~RplReader(); + ReReader(ReSource& source); + ~ReReader(); public: /** * @brief Prepares the reading from a given source unit. @@ -77,9 +77,9 @@ public: * @return NULL: unit not known
* otherwise: an instance with the state of the reader * for the source. This is normally a sub class of - * RplSourceUnit + * ReSourceUnit */ - virtual RplSourceUnit* openSourceUnit(const char* unit) = 0; + virtual ReSourceUnit* openSourceUnit(const char* unit) = 0; /** * @brief Reads the first part of the next line into a given buffer. * @@ -104,103 +104,103 @@ public: virtual bool fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore) = 0; public: virtual void clear(); - RplSource& source(); - RplSourceUnit* currentSourceUnit() const; - bool setCurrentSourceUnit(RplSourceUnitName& currentSourceUnit); + ReSource& source(); + ReSourceUnit* currentSourceUnit() const; + bool setCurrentSourceUnit(ReSourceUnitName& currentSourceUnit); protected: void removeSourceUnit(); protected: - RplSourceUnit* m_currentSourceUnit; + ReSourceUnit* m_currentSourceUnit; /// name -> source UnitMap m_units; - RplSource& m_source; + ReSource& m_source; }; #define RPL_POSITIONS_PER_BLOCK 512 -class RplSourcePositionBlock{ - friend class RplSource; +class ReSourcePositionBlock{ + friend class ReSource; public: - RplSourcePositionBlock(); + ReSourcePositionBlock(); private: - RplSourcePositionBlock* m_successor; - char m_positions[RPL_POSITIONS_PER_BLOCK * sizeof(RplSourcePosition)]; + ReSourcePositionBlock* m_successor; + char m_positions[RPL_POSITIONS_PER_BLOCK * sizeof(ReSourcePosition)]; }; -class RplSource { +class ReSource { public: - RplSource(); - virtual ~RplSource(); + ReSource(); + virtual ~ReSource(); public: virtual const char* permanentUnitName(const char* unit); void finishSourceUnit(); - void addReader(RplReader* reader); - void addSourceUnit(RplSourceUnit* unit); - QStack sourcePositionStack() const; - QStack& sourceUnitStack(); - - bool startUnit(const char* unit, const RplSourcePosition& caller); - void pushSourceUnit(RplSourceUnit* unit); - RplSourceUnit* popSourceUnit(RplReader* reader); - RplReader* currentReader(); - const RplSourcePosition* newPosition(int colNo); + void addReader(ReReader* reader); + void addSourceUnit(ReSourceUnit* unit); + QStack sourcePositionStack() const; + QStack& sourceUnitStack(); + + bool startUnit(const char* unit, const ReSourcePosition& caller); + void pushSourceUnit(ReSourceUnit* unit); + ReSourceUnit* popSourceUnit(ReReader* reader); + ReReader* currentReader(); + const ReSourcePosition* newPosition(int colNo); void clear(); - const RplSourcePosition* caller() const; + const ReSourcePosition* caller() const; protected: void destroy(); protected: // stack of the info about the stacked (open) source units: - QStack m_sourcePositionStack; - RplSourcePositionBlock* m_sourcePositionBlock; + QStack m_sourcePositionStack; + ReSourcePositionBlock* m_sourcePositionBlock; int m_countPositionBlock; - QList m_readers; - QList m_sourceUnits; + QList m_readers; + QList m_sourceUnits; // setCurrentSourceUnit() pushes one entry, removeSourceUnit() pops it // (when end of input has been reached). - QStack m_unitStack; - RplReader* m_currentReader; + QStack m_unitStack; + ReReader* m_currentReader; }; -class RplStringReader; +class ReStringReader; -class RplStringSourceUnit : public RplSourceUnit { - friend class RplStringReader; +class ReStringSourceUnit : public ReSourceUnit { + friend class ReStringReader; public: - RplStringSourceUnit(RplSourceUnitName name, - const RplSourceUnitContent& content, - RplStringReader* reader); - virtual ~RplStringSourceUnit(); + ReStringSourceUnit(ReSourceUnitName name, + const ReSourceUnitContent& content, + ReStringReader* reader); + virtual ~ReStringSourceUnit(); public: int currentPosition() const; void setCurrentPosition(int currentPosition); - RplSourceUnitContent content() const; + ReSourceUnitContent content() const; private: int m_currentPosition; QByteArray m_content; }; -class RplStringReader : public RplReader{ +class ReStringReader : public ReReader{ public: - RplStringReader(RplSource& source); - virtual ~RplStringReader(); - // RplReader interface + ReStringReader(ReSource& source); + virtual ~ReStringReader(); + // ReReader interface public: - virtual RplSourceUnit* openSourceUnit(RplSourceUnitName unit); + virtual ReSourceUnit* openSourceUnit(ReSourceUnitName unit); virtual bool nextLine(int maxSize, QByteArray& buffer, bool& hasMore); virtual bool fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore); public: - void addSource(RplSourceUnitName name, RplSourceUnitContent content); - void replaceSource(RplSourceUnitName name, RplSourceUnitContent content); + void addSource(ReSourceUnitName name, ReSourceUnitContent content); + void replaceSource(ReSourceUnitName name, ReSourceUnitContent content); }; -class RplFileReader; +class ReFileReader; -class RplFileSourceUnit : public RplSourceUnit { - friend class RplFileReader; +class ReFileSourceUnit : public ReSourceUnit { + friend class ReFileReader; public: - RplFileSourceUnit(RplSourceUnitName filename, RplFileReader* reader); - virtual ~RplFileSourceUnit(); + ReFileSourceUnit(ReSourceUnitName filename, ReFileReader* reader); + virtual ~ReFileSourceUnit(); public: bool isOpen() const; private: @@ -210,17 +210,17 @@ private: QByteArray m_line; }; -class RplFileReader : public RplReader{ +class ReFileReader : public ReReader{ public: - RplFileReader(RplSource& source); - virtual ~RplFileReader(); - // RplReader interface + ReFileReader(ReSource& source); + virtual ~ReFileReader(); + // ReReader interface public: - virtual RplSourceUnit* openSourceUnit(RplSourceUnitName unit); + virtual ReSourceUnit* openSourceUnit(ReSourceUnitName unit); virtual bool nextLine(int maxSize, QByteArray& buffer, bool& hasMore); virtual bool fillBuffer(int maxSize, QByteArray& buffer, bool& hasMore); public: - void addSource(RplSourceUnitName filename); + void addSource(ReSourceUnitName filename); }; diff --git a/rplexpr/rplvm.cpp b/expr/ReVM.cpp similarity index 66% rename from rplexpr/rplvm.cpp rename to expr/ReVM.cpp index 9598c23..1a4e177 100644 --- a/rplexpr/rplvm.cpp +++ b/expr/ReVM.cpp @@ -11,16 +11,16 @@ * @brief Implements an interpreter of an abstract syntax tree. */ -/** @file rplexpr/rplvm.hpp +/** @file expr/ReVM.hpp * * @brief Definitions for an interpreter of an abstract syntax tree. */ -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" +#include "base/rebase.hpp" +#include "expr/reexpr.hpp" enum { - LOC_VAL_OF_VAR_1 = RPL_FIRST_OF(RPL_MODULE_VM), // 11401 + LOC_VAL_OF_VAR_1 = LOC_FIRST_OF(LOC_VM), // 11401 LOC_UNOP_1, LOC_UNOP_2, LOC_UNOP_3, @@ -29,9 +29,9 @@ enum { LOC_COUNT }; -int RplVMThread::m_nextId = 1; +int ReVMThread::m_nextId = 1; -/** @class RplVmException rplvm.hpp "rplexpr/rplvm.hpp" +/** @class ReVMException ReVM.hpp "expr/ReVM.hpp" * * @brief Implements an exception for the virtual machine. * @@ -41,8 +41,8 @@ int RplVMThread::m_nextId = 1; * @param format the message with placeholders * @param ... the values for the placeholders */ -RplVmException::RplVmException(const char* format, ...) : - RplException("") +ReVMException::ReVMException(const char* format, ...) : + ReException("") { char buffer[16000]; va_list ap; @@ -52,7 +52,7 @@ RplVmException::RplVmException(const char* format, ...) : m_message = buffer; } -/** @class RplStackFrame rplvm.hpp "rplexpr/rplvm.hpp" +/** @class ReStackFrame ReVM.hpp "expr/ReVM.hpp" * * @brief Implements the storage for a symbol space. * @@ -68,19 +68,20 @@ RplVmException::RplVmException(const char* format, ...) : * @param symbols the symbol space belonging to the stack frame */ -RplStackFrame::RplStackFrame(RplSymbolSpace* symbols) : +ReStackFrame::ReStackFrame(ReASItem* caller, ReSymbolSpace* symbols) : m_countVariables(symbols->listOfVars().size()), m_variables(NULL), - m_symbols(symbols) + m_symbols(symbols), + m_caller(caller) { if (m_countVariables > 0) - m_variables = new RplASVariant[m_countVariables]; + m_variables = new ReASVariant[m_countVariables]; } /** * @brief Destructor. */ -RplStackFrame::~RplStackFrame() +ReStackFrame::~ReStackFrame() { delete[] m_variables; m_variables = NULL; @@ -93,10 +94,10 @@ RplStackFrame::~RplStackFrame() * * @return the storage of the variable */ -RplASVariant& RplStackFrame::valueOfVariable(int index) +ReASVariant& ReStackFrame::valueOfVariable(int index) { if (index < 0 || index >= m_countVariables) - throw RplVmException("valueOfVariable(): invalid index: %d", index); + throw ReVMException("valueOfVariable(): invalid index: %d", index); return m_variables[index]; } /** @@ -104,12 +105,12 @@ RplASVariant& RplStackFrame::valueOfVariable(int index) * * @return the symbol space */ -RplSymbolSpace* RplStackFrame::symbols() const +ReSymbolSpace* ReStackFrame::symbols() const { return m_symbols; } -/** @class RplVMThread rplvm.hpp "rplexpr/rplvm.hpp" +/** @class ReVMThread ReVM.hpp "expr/ReVM.hpp" * * @brief Implements a thread of the virtual machine. * @@ -123,7 +124,7 @@ RplSymbolSpace* RplStackFrame::symbols() const * @param maxStack the maximal number of nested stack frames * @param vm the parent, the virtual machine */ -RplVMThread::RplVMThread(int maxStack, RplVirtualMachine* vm) : +ReVMThread::ReVMThread(int maxStack, ReVirtualMachine* vm) : m_id(m_nextId++), m_debugMode(false), m_singleStep(false), @@ -136,15 +137,15 @@ RplVMThread::RplVMThread(int maxStack, RplVirtualMachine* vm) : // the stack is never empty! m_topOfValues(0), m_vm(vm), - m_logger(new RplLogger()) + m_logger(new ReLogger()) { QByteArray prefix = "vm_thread_" + QByteArray::number(m_id); m_logger->buildStandardAppender(prefix); m_frameStack.reserve(maxStack); // the stack is never empty! - m_frameStack.append(new RplStackFrame(vm->tree().symbolSpaces()[0])); + m_frameStack.append(new ReStackFrame(vm->tree().symbolSpaces()[0])); // the stack is never empty! - m_valueStack.append(new RplASVariant); + m_valueStack.append(new ReASVariant); } /** @@ -154,19 +155,19 @@ RplVMThread::RplVMThread(int maxStack, RplVirtualMachine* vm) : * m_child * @param space the current symbol space */ -void RplVMThread::execute(RplASNode1* statements, RplSymbolSpace* space) +void ReVMThread::execute(ReASNode1* statements, ReSymbolSpace* space) { bool debugMode = m_debugMode; - RplASNode1 *next; + ReASNode1 *next; while(statements != NULL){ if (debugMode && (m_singleStep - || (statements->flags() & RplASItem::NF_BREAKPOINT) != 0)) + || (statements->flags() & ReASItem::NF_BREAKPOINT) != 0)) debug(statements); - RplASStatement* statement = dynamic_cast(statements); + ReASStatement* statement = dynamic_cast(statements); if (statement != NULL) statement->execute(*this); - statements = dynamic_cast(statements->child()); + statements = dynamic_cast(statements->child()); } } @@ -175,7 +176,7 @@ void RplVMThread::execute(RplASNode1* statements, RplSymbolSpace* space) * * @param statement the current statement (not yet executed) */ -void RplVMThread::debug(RplASNode1* statement) +void ReVMThread::debug(ReASNode1* statement) { } @@ -185,7 +186,7 @@ void RplVMThread::debug(RplASNode1* statement) * * @return the logger */ -RplLogger* RplVMThread::logger() const +ReLogger* ReVMThread::logger() const { return m_logger; } @@ -194,14 +195,14 @@ RplLogger* RplVMThread::logger() const * * @return the reserved value */ -RplASVariant&RplVMThread::reserveValue() +ReASVariant&ReVMThread::reserveValue() { - RplASVariant* rc; + ReASVariant* rc; if (++m_topOfValues < m_valueStack.size()){ rc = m_valueStack[m_topOfValues]; rc->destroyValue(); } else { - rc = new RplASVariant(); + rc = new ReASVariant(); m_valueStack.append(rc); } return *rc; @@ -212,9 +213,9 @@ RplASVariant&RplVMThread::reserveValue() * * @return the top of the value stack */ -RplASVariant& RplVMThread::topOfValues() +ReASVariant& ReVMThread::topOfValues() { - RplASVariant& rc = *m_valueStack[m_topOfValues]; + ReASVariant& rc = *m_valueStack[m_topOfValues]; return rc; } @@ -224,9 +225,9 @@ RplASVariant& RplVMThread::topOfValues() * * @return the 2nd value the value stack */ -RplASVariant& RplVMThread::top2OfValues() +ReASVariant& ReVMThread::top2OfValues() { - RplASVariant& rc = *m_valueStack[m_topOfValues-1]; + ReASVariant& rc = *m_valueStack[m_topOfValues-1]; return rc; } @@ -235,9 +236,9 @@ RplASVariant& RplVMThread::top2OfValues() * * @return the old top of stack */ -RplASVariant& RplVMThread::popValue() +ReASVariant& ReVMThread::popValue() { - RplASVariant& rc = *m_valueStack[m_topOfValues]; + ReASVariant& rc = *m_valueStack[m_topOfValues]; if (m_topOfValues > 0) m_topOfValues--; return rc; @@ -249,7 +250,7 @@ RplASVariant& RplVMThread::popValue() * @param symbolSpace the symbol space of the variable * @param variableNo the current no of the variable in the symbol space */ -void RplVMThread::valueToTop(RplSymbolSpace* symbolSpace, int variableNo) +void ReVMThread::valueToTop(ReSymbolSpace* symbolSpace, int variableNo) { //@ToDo } @@ -259,13 +260,13 @@ void RplVMThread::valueToTop(RplSymbolSpace* symbolSpace, int variableNo) * @param item * @return */ -RplASVariant& RplVMThread::lValue(RplASItem* item) +ReASVariant& ReVMThread::lValue(ReASItem* item) { - RplASVariant* rc; + ReASVariant* rc; switch(item->nodeType()){ case AST_NAMED_VALUE: { - RplASNamedValue* var = dynamic_cast(item); + ReASNamedValue* var = dynamic_cast(item); rc = &valueOfVariable(var->symbolSpace(), var->variableNo()); break; } @@ -282,12 +283,12 @@ RplASVariant& RplVMThread::lValue(RplASItem* item) * @param variableNo the current number in the symbol space * @return */ -RplASVariant& RplVMThread::valueOfVariable(RplSymbolSpace* symbolSpace, +ReASVariant& ReVMThread::valueOfVariable(ReSymbolSpace* symbolSpace, int variableNo) { - RplASVariant& rc = *m_valueStack[0]; + ReASVariant& rc = *m_valueStack[0]; int ix = m_topOfFrames; - RplStackFrame* frame = NULL; + ReStackFrame* frame = NULL; for(int ix = m_topOfFrames; ix >= 0; ix--){ frame = m_frameStack[ix]; if (frame->symbols() == symbolSpace){ @@ -306,7 +307,7 @@ RplASVariant& RplVMThread::valueOfVariable(RplSymbolSpace* symbolSpace, * @return true: tracing is on
* false: otherwise */ -bool RplVMThread::tracing() const +bool ReVMThread::tracing() const { return m_tracing; } @@ -316,7 +317,7 @@ bool RplVMThread::tracing() const * @param tracing true: tracing will be done
* false: tracing will not be done */ -void RplVMThread::setTracing(bool tracing) +void ReVMThread::setTracing(bool tracing) { m_tracing = tracing; } @@ -326,18 +327,40 @@ void RplVMThread::setTracing(bool tracing) * * @return the virtual machine */ -RplVirtualMachine* RplVMThread::vm() const +ReVirtualMachine* ReVMThread::vm() const { return m_vm; } -/** @class RplVirtualMachine rplvm.hpp "rplexpr/rplvm.hpp" +/** + * @brief Adds a frame to the frame stack. + * + * @param frame frame to add + */ +void ReVMThread::pushFrame(ReStackFrame* frame) +{ + if (m_frameStack.size() >= m_maxStack) + throw ReASException(NULL, "too deep recursion: %d", m_maxStack); + m_frameStack.push_back(frame); +} + +/** + * @brief Removes the top of the frames from the stack. + */ +void ReVMThread::popFrame() +{ + if (m_frameStack.size() <= 0) + throw ReASException(NULL, "frame stack is empty"); + m_frameStack.pop_back(); +} + +/** @class ReVirtualMachine ReVM.hpp "expr/ReVM.hpp" * * @brief Implements a virtual machine. * * This is an execution unit which interprets an abstract syntax tree. */ -RplVirtualMachine::RplVirtualMachine(RplASTree& tree, RplSource& source, +ReVirtualMachine::ReVirtualMachine(ReASTree& tree, ReSource& source, int maxStack) : m_maxStack(maxStack), m_threads(), @@ -355,15 +378,15 @@ RplVirtualMachine::RplVirtualMachine(RplASTree& tree, RplSource& source, * * @param module the module's name */ -void RplVirtualMachine::executeModule(const char* module) +void ReVirtualMachine::executeModule(const char* module) { - RplSymbolSpace* space = m_tree.findmodule(module); + ReSymbolSpace* space = m_tree.findmodule(module); if (space == NULL) - throw RplVmException("module not found: %s", module); - RplStackFrame frame(space); - RplSymbolSpace* mainSpace = NULL; - RplASItem* mainStatements = NULL; - RplASMethod* method = space->findMethod("main"); + throw ReVMException("module not found: %s", module); + ReStackFrame frame(space); + ReSymbolSpace* mainSpace = NULL; + ReASItem* mainStatements = NULL; + ReASMethod* method = space->findMethod("main"); if (method != NULL){ mainStatements = method->child(); mainSpace = method->symbols(); @@ -383,21 +406,21 @@ void RplVirtualMachine::executeModule(const char* module) * @param maxStack the maximal number of nested stack frames. * <= 0: use the default */ -void RplVirtualMachine::addThread(RplASItem* initialization, - RplSymbolSpace* spaceInitialization, - RplASItem* statements, - RplSymbolSpace* space, +void ReVirtualMachine::addThread(ReASItem* initialization, + ReSymbolSpace* spaceInitialization, + ReASItem* statements, + ReSymbolSpace* space, int maxStack) { - RplVMThread* thread = new RplVMThread( + ReVMThread* thread = new ReVMThread( maxStack <= 0 ? m_maxStack : maxStack, this); m_threads.append(thread); if (initialization != NULL){ - thread->execute(dynamic_cast(initialization), + thread->execute(dynamic_cast(initialization), spaceInitialization); } if (statements != NULL) - thread->execute(dynamic_cast(statements), space); + thread->execute(dynamic_cast(statements), space); } /** * @brief Tests whether a given flag is set. @@ -406,7 +429,7 @@ void RplVirtualMachine::addThread(RplASItem* initialization, * @return true: the flag is set
* false: otherwise */ -bool RplVirtualMachine::hasFlag(RplVirtualMachine::VMFlag flag) const +bool ReVirtualMachine::hasFlag(ReVirtualMachine::VMFlag flag) const { bool rc = (m_flags & flag) != 0; return rc; @@ -417,7 +440,7 @@ bool RplVirtualMachine::hasFlag(RplVirtualMachine::VMFlag flag) const * @param flag * @return */ -void RplVirtualMachine::setFlag(RplVirtualMachine::VMFlag flag) +void ReVirtualMachine::setFlag(ReVirtualMachine::VMFlag flag) { m_flags |= flag; } @@ -428,7 +451,7 @@ void RplVirtualMachine::setFlag(RplVirtualMachine::VMFlag flag) * @param flag * @return */ -void RplVirtualMachine::clearFlag(RplVirtualMachine::VMFlag flag) +void ReVirtualMachine::clearFlag(ReVirtualMachine::VMFlag flag) { m_flags &= ~flag; } @@ -437,7 +460,7 @@ void RplVirtualMachine::clearFlag(RplVirtualMachine::VMFlag flag) * @brief Returns the trace writer. * @return the trace writer */ -RplWriter* RplVirtualMachine::traceWriter() const +ReWriter* ReVirtualMachine::traceWriter() const { return m_traceWriter; } @@ -447,7 +470,7 @@ RplWriter* RplVirtualMachine::traceWriter() const * * @param traceWriter the new writer */ -void RplVirtualMachine::setTraceWriter(RplWriter* traceWriter) +void ReVirtualMachine::setTraceWriter(ReWriter* traceWriter) { m_traceWriter = traceWriter; } @@ -456,7 +479,7 @@ void RplVirtualMachine::setTraceWriter(RplWriter* traceWriter) * * @return the abstract symbol tree */ -RplASTree& RplVirtualMachine::tree() const +ReASTree& ReVirtualMachine::tree() const { return m_tree; } diff --git a/expr/ReVM.hpp b/expr/ReVM.hpp new file mode 100644 index 0000000..938a1a4 --- /dev/null +++ b/expr/ReVM.hpp @@ -0,0 +1,114 @@ +/* + * 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 ReVM_HPP +#define ReVM_HPP + +class ReVMException : public ReException { +public: + ReVMException(const char* message, ...); +}; +class ReStackFrame { +public: + ReStackFrame(ReASItem* caller, ReSymbolSpace* symbols); + ~ReStackFrame(); +public: + ReASVariant& valueOfVariable(int index); + ReSymbolSpace* symbols() const; + +private: + int m_countVariables; + ReASVariant* m_variables; + ReSymbolSpace* m_symbols; + ReASItem* m_caller; +}; + +class ReVirtualMachine; +class ReVMThread +{ + friend class ReASItem; + friend class ReASStatement; + friend class ReASCalculable; + friend class ReASCondition; +public: + typedef QList StackFrameList; +public: + ReVMThread(int maxStack, ReVirtualMachine* vm); +public: + void execute(ReASNode1* statements, ReSymbolSpace* space); + virtual void debug(ReASNode1* statement); + ReWriter* errorWriter() const; + void setErrorWriter(ReWriter* errorWriter); + ReLogger* logger() const; + ReASVariant& reserveValue(); + ReASVariant& topOfValues(); + ReASVariant& top2OfValues(); + ReASVariant& popValue(); + void valueToTop(ReSymbolSpace* symbolSpace, int variableNo); + ReASVariant& lValue(ReASItem* item); + ReASVariant& valueOfVariable(ReSymbolSpace* symbolSpace, int variableNo); + bool tracing() const; + void setTracing(bool tracing); + ReVirtualMachine* vm() const; + void pushFrame(ReStackFrame* frame); + void popFrame(); + +protected: + int m_id; + bool m_debugMode; + bool m_singleStep; + bool m_tracing; + int m_maxStack; + StackFrameList m_frameStack; + int m_topOfFrames; + QList m_valueStack; + int m_topOfValues; + ReVirtualMachine* m_vm; + ReLogger* m_logger; +private: + static int m_nextId; +}; + +class ReVirtualMachine +{ +public: + enum VMFlag { + VF_UNDEF, + VF_TRACE_STATEMENTS = 1<<1, + VF_TRACE_LOCALS = 1<<2, + VF_TRACE_AUTO_VARIABLES = 1<<3 + + }; + typedef QList LineList; +public: + ReVirtualMachine(ReASTree& tree, ReSource& source, int maxStack = 1024); +public: + void executeModule(const char* module); + void addThread(ReASItem* initialization, + ReSymbolSpace* spaceInitialization, + ReASItem* statements, ReSymbolSpace* space, + int maxStack = 0); + bool hasFlag(VMFlag flag) const; + void setFlag(VMFlag flag); + void clearFlag(VMFlag flag); + ReWriter* traceWriter() const; + void setTraceWriter(ReWriter* traceWriter); + ReASTree& tree() const; + +private: + int m_maxStack; + QList m_threads; + int m_flags; + ReSource& m_source; + ReASTree& m_tree; + LineList m_trace; + ReWriter* m_traceWriter; +}; + +#endif // ReVM_HPP diff --git a/rplexpr/rplexpr.hpp b/expr/reexpr.hpp similarity index 95% rename from rplexpr/rplexpr.hpp rename to expr/reexpr.hpp index 7b04db0..3cb43d5 100644 --- a/rplexpr/rplexpr.hpp +++ b/expr/reexpr.hpp @@ -21,7 +21,7 @@ #include "rplexpr/rplsource.hpp" #include "rplexpr/rpllexer.hpp" #include "rplexpr/rplastree.hpp" -#include "rplexpr/rplvm.hpp" +#include "rplexpr/ReVM.hpp" #include "rplexpr/rplparser.hpp" #include "rplexpr/rplmfparser.hpp" diff --git a/rplmath/rplenigma.cpp b/math/ReEnigma.cpp similarity index 64% rename from rplmath/rplenigma.cpp rename to math/ReEnigma.cpp index eefa89b..f575f43 100644 --- a/rplmath/rplenigma.cpp +++ b/math/ReEnigma.cpp @@ -10,21 +10,22 @@ * * @brief Implements encryption and decryption engines. */ -/** @file rplmath/rplenigma.hpp +/** @file math/ReEnigma.hpp * * @brief Definitions for encryption and decryption engines. */ -#include "rplmath/rplmath.hpp" +#include "base/rebase.hpp" +#include "math/remath.hpp" -/** @class RplEnigma::secret_t rplenigma.hpp "rplmath/rplenigma.hpp" +/** @class ReEnigma::secret_t ReEnigma.hpp "math/ReEnigma.hpp" * * @brief Stores the internal structure of a secret. * * A secret can be a password, a salt, a certificate or simlar * which makes an encryption individually. */ -/** @class RplEnigma rplenigma.hpp "rplmath/rplenigma.hpp" +/** @class ReEnigma ReEnigma.hpp "math/ReEnigma.hpp" * * @brief Implements a portable en/decryption engine. * @@ -43,24 +44,24 @@ * and a 64 bit integer arithmetic is available. * */ -const char* RplEnigma::SET_DECIMALS = "0123456789"; -const char* RplEnigma::SET_HEXDIGITS = "0123456789abcdef"; -const char* RplEnigma::SET_ALPHANUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" +const char* ReEnigma::SET_DECIMALS = "0123456789"; +const char* ReEnigma::SET_HEXDIGITS = "0123456789abcdef"; +const char* ReEnigma::SET_ALPHANUM = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz_"; -const char* RplEnigma::SET_FILENAME = " !^°$%&=+~#-.0123456789ABCDEFGHIJKLM" +const char* ReEnigma::SET_FILENAME = " !^°$%&=+~#-.0123456789ABCDEFGHIJKLM" "NOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_"; -const char* RplEnigma::SET_32_127 = " !\"#$%&'()*+,-./0123456789:;<=>?@" +const char* ReEnigma::SET_32_127 = " !\"#$%&'()*+,-./0123456789:;<=>?@" "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f"; -const char* RplEnigma::SET_32_255 = " !\"#$%&'()*+,-./0123456789:;<=>?@" +const char* ReEnigma::SET_32_255 = " !\"#$%&'()*+,-./0123456789:;<=>?@" "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f" "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"; -const char* RplEnigma::SET_PRINTABLE_127 = +const char* ReEnigma::SET_PRINTABLE_127 = "\t\r\n !\"#$%&'()*+,-./0123456789:;<=>?@" "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f"; -const char* RplEnigma::SET_PRINTABLE_255 = +const char* ReEnigma::SET_PRINTABLE_255 = "\t\r\n !\"#$%&'()*+,-./0123456789:;<=>?@" "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f" "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" @@ -73,7 +74,7 @@ const char* RplEnigma::SET_PRINTABLE_255 = * * @param random pseudo random generator */ -RplEnigma::RplEnigma(RplRandom* random) : +ReEnigma::ReEnigma(ReRandom* random) : m_random(random), m_ownsRandom(false), m_secrets(), @@ -81,14 +82,14 @@ RplEnigma::RplEnigma(RplRandom* random) : m_randomSource("4711") { m_randomSource.reserve(8096); if(random == NULL) { - m_random = new RplRandom(); + m_random = new ReRandom(); m_ownsRandom = true; } } /** * @brief Destructor. */ -RplEnigma::~RplEnigma() { +ReEnigma::~ReEnigma() { if(m_ownsRandom) { delete m_random; m_random = NULL; @@ -103,7 +104,7 @@ RplEnigma::~RplEnigma() { * @return empty string: error while reading
* otherwise: the certificate as byte array */ -QByteArray RplEnigma::readCertificate(const char* filename) { +QByteArray ReEnigma::readCertificate(const char* filename) { QByteArray rc = "not implemented: readCertificate(): "; rc += filename; assert(rc.isEmpty()); @@ -137,7 +138,7 @@ inline void buildBooster(QByteArray& booster, const char* charSet) { * IN: "": not initialized otherwise: ready for work * OUT: ready for work */ -void RplEnigma::encode(char* data, int size, const char* charSet, +void ReEnigma::encode(char* data, int size, const char* charSet, QByteArray& booster) { if(booster.length() == 0) { buildBooster(booster, charSet); @@ -170,7 +171,7 @@ void RplEnigma::encode(char* data, int size, const char* charSet, * IN: "": not initialized otherwise: ready for work * OUT: ready for work */ -void RplEnigma::decode(char* data, int size, const char* charSet, +void ReEnigma::decode(char* data, int size, const char* charSet, QByteArray& booster) { if(booster.length() == 0) { buildBooster(booster, charSet); @@ -194,7 +195,7 @@ void RplEnigma::decode(char* data, int size, const char* charSet, * @param data IN: data to encode/decoded
* OUT: data encoded/decoded */ -void RplEnigma::change(QByteArray& data) { +void ReEnigma::change(QByteArray& data) { int randomLength = m_randomSource.length(); for(int ix = data.length() - 1; ix >= 0; ix--) { char item = data.at(ix); @@ -211,7 +212,7 @@ void RplEnigma::change(QByteArray& data) { * * @param byteSecret a byte sequence which influences the random generation */ -void RplEnigma::addByteSecret(QByteArray byteSecret) { +void ReEnigma::addByteSecret(QByteArray byteSecret) { // we expand it to a multiple of 64 bit: int oldSize = byteSecret.length(); int newSize = (oldSize + 7) / 8 * 8; @@ -231,17 +232,17 @@ void RplEnigma::addByteSecret(QByteArray byteSecret) { int count = newSize / 8; secret_t* secret = new secret_t(); secret->m_count = count; - secret->m_list = new u_int64_t[count]; + secret->m_list = new uint64_t[count]; m_secrets.append(secret); for(ix = 0; ix < count; ix++) { - u_int64_t value = 0; + uint64_t value = 0; for(int ix2 = 0; ix2 < 8; ix2++) value = (value << 8) + byteSecret.at(ix * 8 + ix2); secret->m_list[ix] = value; } QByteArray value; QCryptographicHash hash(QCryptographicHash::Md5); - RplRandom rand; + ReRandom rand; hash.addData(m_randomSource.constData(), 4); for(ix = 0; ix < byteSecret.length(); ix++) { hash.addData(byteSecret.constData() + ix, 1); @@ -257,8 +258,8 @@ void RplEnigma::addByteSecret(QByteArray byteSecret) { * @param maxValue * @return */ -int RplEnigma::nextInt(int maxValue) { - u_int64_t seed = 0; +int ReEnigma::nextInt(int maxValue) { + uint64_t seed = 0; QList::const_iterator it; int ixSecret = m_randomCalls++; int ix = ixSecret; @@ -276,121 +277,8 @@ int RplEnigma::nextInt(int maxValue) { * * @param seed the initial state */ -void RplEnigma::setSeed(u_int64_t seed) { +void ReEnigma::setSeed(uint64_t seed) { m_random->setSeed(seed); m_randomCalls = 0; } -// ------------------ -#if ! defined RPL_TEST -#define RPL_TEST -#endif -#ifdef RPL_TEST -#include "rplcore/rpltest.hpp" -/** - * @brief Unit test for RplEnigma. - */ -class TestRplEnigma : public RplTest { -public: - TestRplEnigma() : RplTest("RplEnigma") {} - -public: - void testOneCharset(const char* value, const char* charSet, - const char* expected) { - RplEnigma enigma; - enigma.addByteSecret(QByteArray("Geheim")); - enigma.setSeed(0); - QByteArray encoded = value; - QByteArray booster; - enigma.encode(encoded.data(), encoded.length(), charSet, booster); - //printString(encoded.constData()); - QByteArray decoded = encoded; - enigma.setSeed(0); - enigma.decode(decoded.data(), decoded.length(), charSet, booster); - checkE(value, decoded.constData()); - checkE(expected, encoded); - } - - void printCharSets() { - QByteArray value; - value.reserve(256); - unsigned char cc; - for(cc = ' '; cc <= 127; cc++) { - if(cc == '"' || cc == '\\') - value.append('\\'); - value.append(cc); - } - printf("%s\n", value.constData()); - value.resize(0); - for(cc = 128; cc >= 128; cc++) { - char buf[10]; - if(cc % 32 == 0) - value.append("\n"); - sprintf(buf, "\\x%02x", cc); - value.append(buf); - } - printf("%s\n", value.constData()); - } - void printString(const char* value) { - QByteArray v; - unsigned char cc; - while((cc = (unsigned char) *value++) != 0) { - if(cc == '\\' || cc == '"') { - v.append('\\'); - v.append(cc); - } else if(cc >= 127) { - char buffer[10]; - sprintf(buffer, "\\x%02x", cc); - v.append(buffer); - } else { - v.append(cc); - } - } - printf("%s\n", v.constData()); - } - void testOneBytes(const char* bytes) { - RplEnigma enigma; - enigma.addByteSecret("Hello World"); - enigma.setSeed(0x1234); - - QByteArray encoded(bytes); - enigma.change(encoded); - - enigma.setSeed(0x1234); - QByteArray decoded(encoded); - enigma.change(decoded); - checkE(bytes, decoded); - } - - void testBytes() { - testOneBytes("abcdefg"); - testOneBytes("01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); - } - - void testCharSet() { - //testOneCharset("&()[]{}Weiß der Geier/Kuckuck?", RplEnigma::SET_32_255, "2Kc\x9a\xfeQ\xd7\xa84sx)*\xfb\xd2z\xf4\"W\xb0\xee\xb0\xd1\x84\xace\xf8_u*T"); - testOneCharset("\\Weiß der Geier/Kuckuck?", RplEnigma::SET_32_127, - "(Z?hßaZ_#/QZ+Oi|SI^=<,)A"); - testOneCharset("01234567890abcdef", RplEnigma::SET_HEXDIGITS, - "c4c25b08735c53a63"); - testOneCharset("data$1%3.^~", RplEnigma::SET_FILENAME, "^voazo-n%$b"); - testOneCharset("Weiß der Geier!", RplEnigma::SET_ALPHANUM, "weyß BCk 19NoO!"); - testOneCharset("12345678901234567890", RplEnigma::SET_DECIMALS, - "97394833084815683977"); - testOneCharset("000000000000000000000000000", RplEnigma::SET_DECIMALS, - "850592651836811261879625929"); - } - - virtual void doIt() { - testBytes(); - testCharSet(); - } -}; - -#endif -void testRplEnigma() { -#ifdef RPL_TEST - TestRplEnigma test; - test.run(); -#endif -} diff --git a/rplmath/rplenigma.hpp b/math/ReEnigma.hpp similarity index 85% rename from rplmath/rplenigma.hpp rename to math/ReEnigma.hpp index e2ed1d3..1f252c4 100644 --- a/rplmath/rplenigma.hpp +++ b/math/ReEnigma.hpp @@ -1,7 +1,7 @@ #ifndef RPLENIGMA_HPP #define RPLENIGMA_HPP -class RplEnigma { +class ReEnigma { public: ///> '0'..'9' static const char* SET_DECIMALS; @@ -23,29 +23,29 @@ public: protected: typedef struct { int m_count; - u_int64_t* m_list; + uint64_t* m_list; } secret_t; public: - RplEnigma(RplRandom* random = NULL); - virtual ~RplEnigma(); + ReEnigma(ReRandom* random = NULL); + virtual ~ReEnigma(); private: // No copy constructor: no implementation! - RplEnigma(const RplEnigma& source); + ReEnigma(const ReEnigma& source); // Prohibits assignment operator: no implementation! - RplEnigma& operator =(const RplEnigma& source); + ReEnigma& operator =(const ReEnigma& source); public: void encode(char* data, int size, const char* charSet, QByteArray& cache); void decode(char* data, int size, const char* charSet, QByteArray& cache); void change(QByteArray& data); void addByteSecret(QByteArray byteSeed); - void setSeed(u_int64_t seed); + void setSeed(uint64_t seed); QByteArray readCertificate(const char* filename); protected: int nextInt(int maxValue); protected: ///> a pseudo random generator - RplRandom* m_random; + ReRandom* m_random; ///> true: m_random must be destroyed (in the destructor). bool m_ownsRandom; ///> This values will be mixed with m_random' seed diff --git a/rplmath/rplmatrix.cpp b/math/ReMatrix.cpp similarity index 61% rename from rplmath/rplmatrix.cpp rename to math/ReMatrix.cpp index 872af7b..626fe26 100644 --- a/rplmath/rplmatrix.cpp +++ b/math/ReMatrix.cpp @@ -13,31 +13,32 @@ * @brief Definitions for 2 dimensional matrices. */ -#include "rplmath/rplmath.hpp" +#include "base/rebase.hpp" +#include "math/remath.hpp" RplMatrixException::RplMatrixException(const RplMatrix& RplMatrix, - const char* format, ...) : - RplException() + const char* format, ...) : + ReException() { if (! RplMatrix.getName().isEmpty()) m_message = RplMatrix.getName() + ": "; - char buffer[16*1024]; + char buffer[16*1024]; - va_list args; - va_start(args, format); - qvsnprintf(buffer, sizeof buffer, format, args); - va_end(args); - m_message += buffer; + va_list args; + va_start(args, format); + qvsnprintf(buffer, sizeof buffer, format, args); + va_end(args); + m_message += buffer; } /** * Constructor. */ RplMatrix::RplMatrix(const char* name) : - m_rows(0), - m_cols(0), - m_values(NULL), - m_name(name) + m_rows(0), + m_cols(0), + m_values(NULL), + m_name(name) { } @@ -49,18 +50,18 @@ RplMatrix::RplMatrix(const char* name) : * @param name the name of the matrix */ RplMatrix::RplMatrix(int rows, int cols, const char* name): - m_rows(rows), - m_cols(cols), - m_values(new MatVal[rows*cols]), - m_name(name) + m_rows(rows), + m_cols(cols), + m_values(new MatVal[rows*cols]), + m_name(name) { } /** * Destructor. */ RplMatrix::~RplMatrix() { - delete m_values; - m_values = NULL; + delete m_values; + m_values = NULL; } /** @@ -69,12 +70,12 @@ RplMatrix::~RplMatrix() { * @param source source to copy */ RplMatrix::RplMatrix(const RplMatrix& source) : - m_rows(0), + m_rows(0), m_cols(0), - m_values(NULL), + m_values(NULL), m_name(source.m_name + QByteArray("-copy")) { - resize(source.m_rows, source.m_cols, source.m_values); + resize(source.m_rows, source.m_cols, source.m_values); } /** @@ -86,11 +87,11 @@ RplMatrix::RplMatrix(const RplMatrix& source) : */ void RplMatrix::checkDefinition(int rows, int cols) const { - if (rows < 0) + if (rows < 0) throw RplMatrixException(*this, "row number negative: %d", rows); - if (cols < 0) + if (cols < 0) throw RplMatrixException(*this, "column number negative: %d", cols); - if (double(rows) * cols > 1.0*1000*1000) + if (double(rows) * cols > 1.0*1000*1000) throw RplMatrixException(*this, "too many elements: %d*%d", rows, cols); } @@ -103,12 +104,12 @@ void RplMatrix::checkDefinition(int rows, int cols) const */ void RplMatrix::check(int row, int col) const { - if (row < 0 || row >= m_rows) + if (row < 0 || row >= m_rows) throw RplMatrixException(*this, "invalid row: %d not in [0,%d[", row, - m_rows); - if (col < 0 || col >= m_cols) + m_rows); + if (col < 0 || col >= m_cols) throw RplMatrixException(*this, "invalid column: %d not in [0,%d[", col, - m_cols); + m_cols); } /** * Checks whether a given Matrix has the same dimensions. @@ -118,11 +119,11 @@ void RplMatrix::check(int row, int col) const */ void RplMatrix::checkSameDimension(const RplMatrix& operand) const { - if (m_rows != operand.getRows()) + if (m_rows != operand.getRows()) throw RplMatrixException(*this, "%s has a different row count: %d / %d", operand.getName().constData(), m_rows, operand.getRows()); - if (m_cols != operand.getCols()) + if (m_cols != operand.getCols()) throw RplMatrixException(*this, "%s has a different column count: %d / %d", operand.getName().constData(), m_cols, operand.getCols()); @@ -135,8 +136,8 @@ void RplMatrix::checkSameDimension(const RplMatrix& operand) const */ RplMatrix& RplMatrix::operator =(const RplMatrix& source) { - resize(source.m_rows, source.m_cols, source.m_values); - return *this; + resize(source.m_rows, source.m_cols, source.m_values); + return *this; } /** * Adds a Matrix to the instance. @@ -146,11 +147,11 @@ RplMatrix& RplMatrix::operator =(const RplMatrix& source) */ RplMatrix& RplMatrix::operator +=(const RplMatrix& operand) { - checkSameDimension(operand); - for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ - m_values[ix] += operand.m_values[ix]; - } - return *this; + checkSameDimension(operand); + for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ + m_values[ix] += operand.m_values[ix]; + } + return *this; } /** * Subtracts a matrix from the instance. @@ -160,11 +161,11 @@ RplMatrix& RplMatrix::operator +=(const RplMatrix& operand) */ RplMatrix& RplMatrix::operator -=(const RplMatrix& operand) { - checkSameDimension(operand); - for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ - m_values[ix] -= operand.m_values[ix]; - } - return *this; + checkSameDimension(operand); + for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ + m_values[ix] -= operand.m_values[ix]; + } + return *this; } /** * Builds the sum of the instance and a given matrix. @@ -175,8 +176,8 @@ RplMatrix& RplMatrix::operator -=(const RplMatrix& operand) RplMatrix RplMatrix::operator +(const RplMatrix& operand) { RplMatrix rc(*this); - rc += operand; - return rc; + rc += operand; + return rc; } /** * Builds the difference of the instance and a given matrix. @@ -187,8 +188,8 @@ RplMatrix RplMatrix::operator +(const RplMatrix& operand) RplMatrix RplMatrix::operator -(const RplMatrix& operand) { RplMatrix rc(*this); - rc -= operand; - return rc; + rc -= operand; + return rc; } /** * Adds a scalar to the instance. @@ -198,10 +199,10 @@ RplMatrix RplMatrix::operator -(const RplMatrix& operand) */ RplMatrix& RplMatrix::operator +=(MatVal scalar) { - for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ - m_values[ix] += scalar; - } - return *this; + for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ + m_values[ix] += scalar; + } + return *this; } /** * Adds a scalar to the instance. @@ -211,10 +212,10 @@ RplMatrix& RplMatrix::operator +=(MatVal scalar) */ RplMatrix& RplMatrix::operator -=(MatVal scalar) { - for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ - m_values[ix] -= scalar; - } - return *this; + for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ + m_values[ix] -= scalar; + } + return *this; } /** * Builds the sum of the instance and a given scalar. @@ -225,8 +226,8 @@ RplMatrix& RplMatrix::operator -=(MatVal scalar) RplMatrix RplMatrix::operator +(MatVal scalar) { RplMatrix rc(*this); - rc += scalar; - return rc; + rc += scalar; + return rc; } /** * Builds the difference of the instance and a given scalar. @@ -237,8 +238,8 @@ RplMatrix RplMatrix::operator +(MatVal scalar) RplMatrix RplMatrix::operator -(MatVal scalar) { RplMatrix rc(*this); - rc -= scalar; - return rc; + rc -= scalar; + return rc; } /** * Tests the equiness of the instance with a given matrix. @@ -249,15 +250,15 @@ RplMatrix RplMatrix::operator -(MatVal scalar) */ bool RplMatrix::operator ==(const RplMatrix& operand) const { - checkSameDimension(operand); - bool rc = true; - for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ - if (m_values[ix] != operand.m_values[ix]){ - rc = false; - break; - } - } - return rc; + checkSameDimension(operand); + bool rc = true; + for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ + if (m_values[ix] != operand.m_values[ix]){ + rc = false; + break; + } + } + return rc; } /** * Compares the instance with a given scalar. @@ -268,39 +269,39 @@ bool RplMatrix::operator ==(const RplMatrix& operand) const */ bool RplMatrix::operator ==(MatVal scalar) const { - bool rc = true; - for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ - if (m_values[ix] != scalar){ - rc = false; - break; - } - } - return rc; + bool rc = true; + for (int ix = m_rows * m_cols - 1; ix >= 0; ix--){ + if (m_values[ix] != scalar){ + rc = false; + break; + } + } + return rc; } /** * Sets a new row-column pair. */ RplMatrix& RplMatrix::resize(int rows, int cols, const MatVal values[], - MatVal defaultValue) + MatVal defaultValue) { - checkDefinition(rows, cols); - if (rows != m_rows || cols != m_cols){ - delete m_values; - m_values = new MatVal[rows * cols]; + checkDefinition(rows, cols); + if (rows != m_rows || cols != m_cols){ + delete m_values; + m_values = new MatVal[rows * cols]; m_rows = rows; m_cols = cols; - } - if (values == NULL) - { + } + if (values == NULL) + { for (int ix = rows*cols - 1; ix >= 0; ix--){ m_values[ix] = defaultValue; - } - } else { + } + } else { for (int ix = rows*cols - 1; ix >= 0; ix--){ m_values[ix] = values[ix]; } - } - return *this; + } + return *this; } /** * Returns the minimum and the maximum of the instance. @@ -313,16 +314,16 @@ Tuple2 RplMatrix::minMax() const #define DBL_MAX std::numeric_limits::max() #define DBL_MIN std::numeric_limits::min() #endif - Tuple2 rc(DBL_MAX, DBL_MIN); + Tuple2 rc(DBL_MAX, DBL_MIN); - for (int ix = m_rows*m_cols - 1; ix >= 0; ix--){ - MatVal x; - if ( (x = m_values[ix]) < rc.m_value1) - rc.m_value1 = x; - if (x > rc.m_value2) - rc.m_value2 = x; - } - return rc; + for (int ix = m_rows*m_cols - 1; ix >= 0; ix--){ + MatVal x; + if ( (x = m_values[ix]) < rc.m_value1) + rc.m_value1 = x; + if (x > rc.m_value2) + rc.m_value2 = x; + } + return rc; } /** @@ -334,47 +335,47 @@ RplMatrix RplMatrix::transpose() const { RplMatrix rc(m_cols, m_rows); - for (int row = 0; row < m_rows; row++){ - for (int col = 0; col < m_cols; col++){ - rc.m_values[m_rows*col + row] = m_values[row * m_cols + col]; - } - } - return rc; + for (int row = 0; row < m_rows; row++){ + for (int col = 0; col < m_cols; col++){ + rc.m_values[m_rows*col + row] = m_values[row * m_cols + col]; + } + } + return rc; } QByteArray RplMatrix::toString(const char* prefix, const char* format, - const char* rowSeparator, const char* colSeparator) const + const char* rowSeparator, const char* colSeparator) const { - char buffer[128]; - Tuple2 minMaxi(minMax()); + char buffer[128]; + Tuple2 minMaxi(minMax()); QByteArray rc; - qsnprintf(buffer, sizeof buffer, format, minMaxi.m_value1); - int length = strlen(buffer); - qsnprintf(buffer, sizeof buffer, format, minMaxi.m_value2); - int length2 = strlen(buffer); - if (length < length2) - length = length2; - qsnprintf(buffer, sizeof buffer, format, - (minMaxi.m_value1 + minMaxi.m_value2) / 2); - length2 = strlen(buffer); - if (length < length2) - length = length2; - if (prefix == NULL) - prefix = ""; - length = m_rows * m_cols * (length + strlen(colSeparator)) - + m_rows * strlen(rowSeparator) + strlen(prefix) + 20; - rc.reserve(length); - rc += prefix; - rc += "["; - for (int row = 0; row < m_rows; row++){ + qsnprintf(buffer, sizeof buffer, format, minMaxi.m_value1); + int length = strlen(buffer); + qsnprintf(buffer, sizeof buffer, format, minMaxi.m_value2); + int length2 = strlen(buffer); + if (length < length2) + length = length2; + qsnprintf(buffer, sizeof buffer, format, + (minMaxi.m_value1 + minMaxi.m_value2) / 2); + length2 = strlen(buffer); + if (length < length2) + length = length2; + if (prefix == NULL) + prefix = ""; + length = m_rows * m_cols * (length + strlen(colSeparator)) + + m_rows * strlen(rowSeparator) + strlen(prefix) + 20; + rc.reserve(length); + rc += prefix; + rc += "["; + for (int row = 0; row < m_rows; row++){ for (int col = 0; col < m_cols; col++){ - qsnprintf(buffer, sizeof buffer, format, m_values[m_cols*row + col]); - rc += buffer; - rc += colSeparator; - } - rc += rowSeparator; - } - rc += "]"; - return rc; + qsnprintf(buffer, sizeof buffer, format, m_values[m_cols*row + col]); + rc += buffer; + rc += colSeparator; + } + rc += rowSeparator; + } + rc += "]"; + return rc; } /** * Finds the length of a column. @@ -384,28 +385,28 @@ QByteArray RplMatrix::toString(const char* prefix, const char* format, * @return the count of chars between start and the next separator */ static int lengthOfColumn(const char* text, char separator){ - const char* ptr = text; - while(*ptr == ' ') - ptr++; - char delimiter = 0; - if (*ptr == '"' || *ptr == '\''){ - delimiter = *ptr++; - } - while(*ptr){ - if (*ptr == '\\'){ - ptr++; - if (*ptr != '\0') - ptr++; - } else if (*ptr == separator) - break; - else if (*ptr != delimiter){ - ptr++; - while(*ptr && *ptr != separator) - ptr++; - } - } - int rc = ptr - text; - return rc; + const char* ptr = text; + while(*ptr == ' ') + ptr++; + char delimiter = 0; + if (*ptr == '"' || *ptr == '\''){ + delimiter = *ptr++; + } + while(*ptr){ + if (*ptr == '\\'){ + ptr++; + if (*ptr != '\0') + ptr++; + } else if (*ptr == separator) + break; + else if (*ptr != delimiter){ + ptr++; + while(*ptr && *ptr != separator) + ptr++; + } + } + int rc = ptr - text; + return rc; } /** * Skips all columns with a content other than a numeric value. @@ -416,14 +417,14 @@ static int lengthOfColumn(const char* text, char separator){ */ static const char* skipNonNumbers(const char* line, char separator) { - int len1, len2 = 0; + int len1, len2 = 0; - while ( (len1 = RplString::lengthOfNumber(line)) == 0 - && (len2 = lengthOfColumn(line, separator)) > 0) - line += len2; + while ( (len1 = ReStringUtil::lengthOfNumber(line)) == 0 + && (len2 = lengthOfColumn(line, separator)) > 0) + line += len2; if (*line == separator) line++; - return line; + return line; } /** * Returns the count of numeric numbers in a CSV line. @@ -434,22 +435,22 @@ static const char* skipNonNumbers(const char* line, char separator) */ static int countNumbers(const char* line, char separator){ line = skipNonNumbers(line, separator); - bool again = true; - int rc = 0; + bool again = true; + int rc = 0; char cc; while(again && (cc = *line) != '\0' && cc != '\n' && cc != '\r'){ - int length = RplString::lengthOfNumber(line, true); - if (length == 0){ - rc = 0; - again = false; - } else { + int length = ReStringUtil::lengthOfNumber(line, true); + if (length == 0){ + rc = 0; + again = false; + } else { line += length; - rc++; - if (*line == separator) - line++; - } - } - return rc; + rc++; + if (*line == separator) + line++; + } + } + return rc; } /** * Reads a file with the CSV (comma separated values) format @@ -462,7 +463,7 @@ void RplMatrix::readFromCvs(const char* filename, int maxLineLength) throw RplMatrixException(*this, "Cannot open %s (%d)", filename, errno); char* buffer = new char[maxLineLength + 1]; const char* line; - char separator = RplString::findCsvSeparator(fp, buffer, maxLineLength); + char separator = ReStringUtil::findCsvSeparator(fp, buffer, maxLineLength); int rows = 0; int cols = 0; int nCols; @@ -488,7 +489,7 @@ void RplMatrix::readFromCvs(const char* filename, int maxLineLength) int col = -1; int length; const char* ptr; - while( (length = RplString::lengthOfNumber(line, true)) > 0){ + while( (length = ReStringUtil::lengthOfNumber(line, true)) > 0){ col++; ptr = line; line += length; @@ -508,7 +509,7 @@ void RplMatrix::readFromCvs(const char* filename, int maxLineLength) delete buffer; } void RplMatrix::readFromXml(const char* filename, const char* tagCol, - const char* tagRow, const char* tagTable, + const char* tagRow, const char* tagTable, int maxLineLength) { throw RplMatrixException(*this, "readFromXml not implementes: %s %s %s %s %d", diff --git a/rplmath/rplmatrix.hpp b/math/ReMatrix.hpp similarity index 98% rename from rplmath/rplmatrix.hpp rename to math/ReMatrix.hpp index 9082408..d0f168d 100644 --- a/rplmath/rplmatrix.hpp +++ b/math/ReMatrix.hpp @@ -13,7 +13,7 @@ class RplMatrix; /** * Implements a RplMatrix specific exception. */ -class RplMatrixException : public RplException +class RplMatrixException : public ReException { public: RplMatrixException(const RplMatrix& RplMatrix, const char* format, ...); diff --git a/rplmath/rplrandom.cpp b/math/ReRandom.cpp similarity index 77% rename from rplmath/rplrandom.cpp rename to math/ReRandom.cpp index 5662f0d..4d38a4f 100644 --- a/rplmath/rplrandom.cpp +++ b/math/ReRandom.cpp @@ -10,13 +10,14 @@ * * @brief Implements pseudo random generators. */ -/** @file rplmath/rplrandom.hpp +/** @file math/ReRandom.hpp * * @brief Definitions for pseudo random generators. */ -#include "rplmath.hpp" +#include "base/rebase.hpp" +#include "math/remath.hpp" -/** @class RplRandom rplrandom.hpp "rplmath/rplrandom.hpp" +/** @class ReRandom ReRandom.hpp "math/ReRandom.hpp" * * @brief Implements a portable pseudo random generator. * @@ -25,14 +26,14 @@ /** * @brief Constructor. */ -RplRandom::RplRandom() : +ReRandom::ReRandom() : m_seed(0) { } /** * @brief Destructor. */ -RplRandom::~RplRandom() { +ReRandom::~ReRandom() { } /** @@ -40,7 +41,7 @@ RplRandom::~RplRandom() { * * @return the next random number. */ -u_int64_t RplRandom::nextInt64() { +uint64_t ReRandom::nextInt64() { // Donald Knuth recommands (for 64-Bit): m_seed = m_seed * 6364136223846793005L + 1442695040888963407L; return m_seed; @@ -50,7 +51,7 @@ u_int64_t RplRandom::nextInt64() { * * @param seed the new seed. */ -void RplRandom::setSeed(u_int64_t seed) { +void ReRandom::setSeed(uint64_t seed) { m_seed = seed; } /** @@ -58,7 +59,7 @@ void RplRandom::setSeed(u_int64_t seed) { * * @param seed the XOR operand. */ -void RplRandom::xorSeed(u_int64_t seed) { +void ReRandom::xorSeed(uint64_t seed) { m_seed ^= seed; } @@ -67,10 +68,10 @@ void RplRandom::xorSeed(u_int64_t seed) { * * @return a pseudo random value 0..255 */ -quint8 RplRandom::nextByte() { - u_int64_t value = nextInt64(); +uint8_t ReRandom::nextByte() { + uint64_t value = nextInt64(); // forget the last 3 bits: - quint8 rc = (quint8)(value >> 3) % 256; + uint8_t rc = (uint8_t)(value >> 3) % 256; return rc; } @@ -81,9 +82,9 @@ quint8 RplRandom::nextByte() { * @param maxValue the maximal result (includeing) * @return the next integer */ -int RplRandom::nextInt(int minValue, int maxValue) { - u_int64_t value = nextInt64(); - u_int64_t diff = maxValue - minValue; +int ReRandom::nextInt(int minValue, int maxValue) { + uint64_t value = nextInt64(); + uint64_t diff = maxValue - minValue; int rc; if(diff <= 0) rc = minValue; @@ -100,7 +101,7 @@ int RplRandom::nextInt(int minValue, int maxValue) { * @param maxChar all characters of the result are lower or equal than this value * @return a random string */ -QByteArray RplRandom::nextString(int length, char minChar, char maxChar) { +QByteArray ReRandom::nextString(int length, char minChar, char maxChar) { QByteArray rc; rc.resize(length); for(int ii = 0; ii < length; ii++) { @@ -116,7 +117,7 @@ QByteArray RplRandom::nextString(int length, char minChar, char maxChar) { * @param charSet a string with all allowed characters * @return a random string with characters from the given set */ -QByteArray RplRandom::nextString(int length, char* charSet) { +QByteArray ReRandom::nextString(int length, char* charSet) { QByteArray rc; rc.resize(length); int ubound = strlen(charSet) - 1; diff --git a/math/ReRandom.hpp b/math/ReRandom.hpp new file mode 100644 index 0000000..14e04f7 --- /dev/null +++ b/math/ReRandom.hpp @@ -0,0 +1,26 @@ +#ifndef RERANDOM_HPP +#define RERANDOM_HPP + +class ReRandom { +public: + ReRandom(); + virtual ~ReRandom(); +private: + // No copy constructor: no implementation! + ReRandom(const ReRandom& source); + // Prohibits assignment operator: no implementation! + ReRandom& operator =(const ReRandom& source); +public: + virtual uint64_t nextInt64(); + virtual void setSeed(uint64_t seed); + void xorSeed(uint64_t seed); + uint8_t nextByte(); + int nextInt(int minValue, int maxValue); + QByteArray nextString(int length = 8, char minChar = ' ', char maxChar = 127); + QByteArray nextString(int length, char* charSet); +protected: + uint64_t m_seed; +}; + + +#endif // RERANDOM_HPP diff --git a/rplmath/rplmath.hpp b/math/remath.hpp similarity index 65% rename from rplmath/rplmath.hpp rename to math/remath.hpp index 81819e9..236f3fd 100644 --- a/rplmath/rplmath.hpp +++ b/math/remath.hpp @@ -8,11 +8,10 @@ #ifndef RPLMATH_HPP #define RPLMATH_HPP -#ifndef RPLCORE_HPP -#include "rplcore/rplcore.hpp" -#endif -#include "rplmath/rplrandom.hpp" -#include "rplmath/rplenigma.hpp" -#include "rplmath/rplmatrix.hpp" +#include +#include +#include "math/ReRandom.hpp" +#include "math/ReEnigma.hpp" +#include "math/ReMatrix.hpp" #endif // RPLMATH_HPP diff --git a/net/ReNetConfig.cpp b/net/ReNetConfig.cpp new file mode 100644 index 0000000..da7bcc1 --- /dev/null +++ b/net/ReNetConfig.cpp @@ -0,0 +1,15 @@ +/* + * 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 "base/rebase.hpp" +#include "math/remath.hpp" +#include "net/renet.hpp" + +const char* ReNetConfig::IP = "connection.ip"; +const char* ReNetConfig::PORT = "connection.port"; +const char* ReNetConfig::SLEEP_MILLISEC = "connection.sleepmillisec"; diff --git a/rplnet/rplnetconfig.hpp b/net/ReNetConfig.hpp similarity index 95% rename from rplnet/rplnetconfig.hpp rename to net/ReNetConfig.hpp index 4d58ef0..9cef175 100644 --- a/rplnet/rplnetconfig.hpp +++ b/net/ReNetConfig.hpp @@ -10,7 +10,7 @@ #ifndef RPLNETCONFIG_HPP #define RPLNETCONFIG_HPP -class RplNetConfig +class ReNetConfig { public: static const char* IP; diff --git a/rplnet/rpltcpclient.cpp b/net/ReTCPClient.cpp similarity index 75% rename from rplnet/rpltcpclient.cpp rename to net/ReTCPClient.cpp index 7ae57df..8912fe9 100644 --- a/rplnet/rpltcpclient.cpp +++ b/net/ReTCPClient.cpp @@ -5,10 +5,12 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#include "rplnet.hpp" +#include "base/rebase.hpp" +#include "math/remath.hpp" +#include "net/renet.hpp" enum { - LOC_1 = RPL_FIRST_OF(RPLMODULE_TCPCLIENT), // 10701 + LOC_1 = LOC_FIRST_OF(LOC_TCPCLIENT), // 10701 LOC_HANDLE_ERROR_1, LOC_SET_REMOTE_ADDRESS_1, }; @@ -17,7 +19,7 @@ enum { * * @brief Implements a TCP client. * - * Use the protocol defined at RplTcpServer. + * Use the protocol defined at ReTCPServer. */ /** * @brief Constructor. @@ -27,14 +29,14 @@ enum { * @param terminator NULL or for controlled termination * @param logger a logger */ -RplTcpClient::RplTcpClient(RplConfigurator& configurator, QThread* thread, - RplTerminator* terminator, - RplLogger* logger) : - m_peer(new RplTcpPeer(configurator, thread, terminator, false, logger)), +RplTcpClient::RplTcpClient(ReConfigurator& configurator, QThread* thread, + ReTerminator* terminator, + ReLogger* logger) : + m_peer(new ReTCPPeer(configurator, thread, terminator, false, logger)), m_logger(logger), m_configurator(configurator){ - QByteArray ip = configurator.asString(RplNetConfig::IP, "localhost"); - int port = configurator.asInt(RplNetConfig::PORT, 12345); + QByteArray ip = configurator.asString(ReNetConfig::IP, "localhost"); + int port = configurator.asInt(ReNetConfig::PORT, 12345); if(! ip.isEmpty() && port != 0) setRemoteAddress(ip.constData(), port); } @@ -65,7 +67,7 @@ void RplTcpClient::setRemoteAddress(const char* ip, int port) { m_peer->setAddress(ip, port); m_logger->logv(LOG_INFO, LOC_SET_REMOTE_ADDRESS_1, "connect with %s:%d", ip, port); - socket->connectToHost(QString(ip), port); + socket->connectToHost(ReString(ip), port); socket->waitForConnected(); } } @@ -74,7 +76,7 @@ void RplTcpClient::setRemoteAddress(const char* ip, int port) { * @brief Returns the peer info. * @return the peer info */ -RplTcpPeer* RplTcpClient::getPeer() const { +ReTCPPeer* RplTcpClient::getPeer() const { return m_peer; } @@ -93,8 +95,8 @@ void RplTcpClient::handleError(QAbstractSocket::SocketError socketError) { * * @brief Implements a thread usable for a tcp client. * - * Each RplTcpPeer needs a thread. Therefore this class provides all things - * needed for a RplTcpClient which uses a RplTcpPeer. + * Each ReTCPPeer needs a thread. Therefore this class provides all things + * needed for a RplTcpClient which uses a ReTCPPeer. */ /** @@ -103,8 +105,8 @@ void RplTcpClient::handleError(QAbstractSocket::SocketError socketError) { * @param configurator delivers some connection parameters * @param logger the logger. If NULL a default logger will be used */ -RplClientThread::RplClientThread(RplConfigurator& configurator, - RplLogger* logger) : +RplClientThread::RplClientThread(ReConfigurator& configurator, + ReLogger* logger) : m_client(NULL), m_logger(logger), m_configurator(configurator), @@ -127,7 +129,7 @@ RplClientThread::~RplClientThread() { * * @return the peer */ -RplTcpPeer* RplClientThread::getPeer() const { +ReTCPPeer* RplClientThread::getPeer() const { return m_client->getPeer(); } @@ -135,7 +137,7 @@ RplTcpPeer* RplClientThread::getPeer() const { * @brief Returns the logger of the thread. * @return the logger */ -RplLogger* RplClientThread::getLogger() const { +ReLogger* RplClientThread::getLogger() const { return m_logger; } diff --git a/rplnet/rpltcpclient.hpp b/net/ReTCPClient.hpp similarity index 73% rename from rplnet/rpltcpclient.hpp rename to net/ReTCPClient.hpp index 7ba45a5..227df7c 100644 --- a/rplnet/rpltcpclient.hpp +++ b/net/ReTCPClient.hpp @@ -9,17 +9,17 @@ #define RPLTCPCLIENT_HPP #ifndef RPLNET_HPP -#include "rplnet.hpp" +#include "renet.hpp" #endif -class RplTcpPeer; +class ReTCPPeer; class RplTcpClient : public QObject { Q_OBJECT public: - RplTcpClient(RplConfigurator& configurator, QThread* thread, - RplTerminator* terminator, - RplLogger* logger = NULL); + RplTcpClient(ReConfigurator& configurator, QThread* thread, + ReTerminator* terminator, + ReLogger* logger = NULL); virtual ~RplTcpClient(); private: // No copy constructor: no implementation! @@ -27,21 +27,21 @@ private: // Prohibits assignment operator: no implementation! RplTcpClient& operator =(const RplTcpClient& source); public: - RplTcpPeer* getPeer() const; + ReTCPPeer* getPeer() const; private: void setRemoteAddress(const char* ip, int port); public slots: void handleError(QAbstractSocket::SocketError socketError); private: - RplTcpPeer* m_peer; - RplLogger* m_logger; - RplConfigurator& m_configurator; + ReTCPPeer* m_peer; + ReLogger* m_logger; + ReConfigurator& m_configurator; }; class RplClientThread : public QThread { public: - RplClientThread(RplConfigurator& configurator, - RplLogger* logger = NULL); + RplClientThread(ReConfigurator& configurator, + ReLogger* logger = NULL); virtual ~RplClientThread(); private: // No copy constructor: no implementation! @@ -57,14 +57,14 @@ public: * to send and receive messages. */ virtual void doIt() = 0; - RplTcpPeer* getPeer() const; - RplLogger* getLogger() const; + ReTCPPeer* getPeer() const; + ReLogger* getLogger() const; private: virtual void run(); protected: RplTcpClient* m_client; - RplLogger* m_logger; - RplConfigurator& m_configurator; + ReLogger* m_logger; + ReConfigurator& m_configurator; private: bool m_ownsLogger; }; diff --git a/rplnet/rpltcppeer.cpp b/net/ReTCPPeer.cpp similarity index 82% rename from rplnet/rpltcppeer.cpp rename to net/ReTCPPeer.cpp index d45946f..cd8dcf6 100644 --- a/rplnet/rpltcppeer.cpp +++ b/net/ReTCPPeer.cpp @@ -5,10 +5,12 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#include "rplnet.hpp" +#include "base/rebase.hpp" +#include "math/remath.hpp" +#include "net/renet.hpp" enum { - LOC_SEND_1 = RPL_FIRST_OF(RPLMODULE_TCPPEER), // 10801 + LOC_SEND_1 = LOC_FIRST_OF(LOC_TCPPEER), // 10801 LOC_READ_BYTES_1, LOC_READ_BYTES_2, LOC_READ_BYTES_3, @@ -19,7 +21,7 @@ enum { static int s_dummy = 0; -/** @class RplTcpPeer rpltcppeer.hpp "rplnet/rpltcppeer.hpp" +/** @class ReTCPPeer rpltcppeer.hpp "rplnet/rpltcppeer.hpp" * * @brief Implements the common things for TCP server and client. * @@ -42,19 +44,19 @@ static int s_dummy = 0; */ /** - * @brief Creates an instance of a RplTcpPeer. + * @brief Creates an instance of a ReTCPPeer. * * @param configurator delivers some connection parameters * @param thread the current thread. Used for sleep() * @param terminator NULL or for controlled thread termination * @param logger logger. If Null the global logger will be taken (not thread safe!) - * @return an instance of RplTcpPeer + * @return an instance of ReTCPPeer */ -RplTcpPeer* RplTcpPeer::createPeer(RplConfigurator& configurator, +ReTCPPeer* ReTCPPeer::createPeer(ReConfigurator& configurator, QThread* thread, - RplTerminator* terminator, - RplLogger* logger) { - return new RplTcpPeer(configurator, thread, terminator, logger); + ReTerminator* terminator, + ReLogger* logger) { + return new ReTCPPeer(configurator, thread, terminator, logger); } /** @@ -66,12 +68,12 @@ RplTcpPeer* RplTcpPeer::createPeer(RplConfigurator& configurator, * @param isServer true: the receiving does have a timeout * @param logger logger. If Null the global logger will be taken (not thread safe!) */ -RplTcpPeer::RplTcpPeer(RplConfigurator& configurator, QThread* thread, - RplTerminator* terminator, +ReTCPPeer::ReTCPPeer(ReConfigurator& configurator, QThread* thread, + ReTerminator* terminator, bool isServer, - RplLogger* logger) : + ReLogger* logger) : m_socket(NULL), - m_logger(logger == NULL ? RplLogger::globalLogger() : logger), + m_logger(logger == NULL ? ReLogger::globalLogger() : logger), m_thread(thread), m_random(), m_timeout(isServer ? 0 : configurator.asInt("connection.timeout", 60)), @@ -81,14 +83,14 @@ RplTcpPeer::RplTcpPeer(RplConfigurator& configurator, QThread* thread, m_dataLocker(QMutex::NonRecursive), m_waitForData() { // Simulate a true random with time, and addresses from stack and code segment: - m_random.setSeed(time(NULL) + ((qint64) this << 8) + ((qint64) &s_dummy << 16) - + ((qint64) &createPeer << 24)); + m_random.setSeed(time(NULL) + ((int64_t) this << 8) + ((int64_t) &s_dummy << 16) + + ((int64_t) &createPeer << 24)); } /** * @brief Destructor. */ -RplTcpPeer::~RplTcpPeer() { +ReTCPPeer::~ReTCPPeer() { } @@ -101,11 +103,11 @@ RplTcpPeer::~RplTcpPeer() { * @return true: success
* false: error occurred */ -bool RplTcpPeer::send(qint8 flags, const char* command, +bool ReTCPPeer::send(qint8 flags, const char* command, const QByteArray& data) { bool rc = false; QByteArray header; - QByteArray data2 = RplString::toCString(data.constData(), 20); + QByteArray data2 = ReStringUtil::toCString(data.constData(), 20); m_logger->logv(LOG_INFO, LOC_SEND_1, "send: flags: %x %s %s (%d)", flags, command, data2.constData(), data.length()); header.reserve(16); @@ -128,8 +130,8 @@ bool RplTcpPeer::send(qint8 flags, const char* command, while(length++ < 5) { header.append(' '); } - qint64 written = m_socket->write(header.constData(), header.length()); - qint64 written2 = m_socket->write(data); + int64_t written = m_socket->write(header.constData(), header.length()); + int64_t written2 = m_socket->write(data); m_socket->flush(); int count = 0; if(written != header.length() || written2 != data.length()) { @@ -147,7 +149,7 @@ bool RplTcpPeer::send(qint8 flags, const char* command, if(m_logger->isActive(LOG_DEBUG)) m_logger->logv(LOG_DEBUG, LOC_SEND_1, "send %s: %s len=%d loops=%d %s", m_address.constData(), command, data.length(), count, - RplString::hexDump((const void*) data.constData(), 16, 16).constData()); + ReStringUtil::hexDump((const void*) data.constData(), 16, 16).constData()); return rc; } @@ -161,11 +163,11 @@ bool RplTcpPeer::send(qint8 flags, const char* command, * @return "": read not successful: timeout or termination or error
* otherwise: the read bytes */ -QByteArray RplTcpPeer::readBytes(int bytes, time_t maxTime, int& loops) { +QByteArray ReTCPPeer::readBytes(int bytes, time_t maxTime, int& loops) { QAbstractSocket* socket = getSocket(); bool success = true; - qint64 available; - long msec = m_configurator.asInt(RplNetConfig::SLEEP_MILLISEC, 1); + int64_t available; + long msec = m_configurator.asInt(ReNetConfig::SLEEP_MILLISEC, 1); int divider = 1000L / (msec == 0 ? 1 : msec); if (divider < 1) divider = 1; @@ -220,7 +222,7 @@ int getInt(const QByteArray& data, int offset, int size) { * @return true: success
* false: error occurred */ -bool RplTcpPeer::receive(QByteArray& command, QByteArray& data) { +bool ReTCPPeer::receive(QByteArray& command, QByteArray& data) { bool rc = true; command.clear(); data.clear(); @@ -229,7 +231,7 @@ bool RplTcpPeer::receive(QByteArray& command, QByteArray& data) { int minHeaderSize = 8; int loops = 0; time_t maxTime = 0; - quint8 flags = 0; + uint8_t flags = 0; header = readBytes(minHeaderSize, maxTime, loops); if(header.length() > 0) { flags = header.at(0); @@ -271,7 +273,7 @@ bool RplTcpPeer::receive(QByteArray& command, QByteArray& data) { * @return true: success
* false: error occurred */ -bool RplTcpPeer::sendAndReceive(quint8 flags, char command [4], +bool ReTCPPeer::sendAndReceive(uint8_t flags, char command [4], QByteArray* data, QByteArray& answer, QByteArray& answerData) { answer.clear(); @@ -287,7 +289,7 @@ bool RplTcpPeer::sendAndReceive(quint8 flags, char command [4], * * @param socket the socket to set */ -void RplTcpPeer::setSocket(QAbstractSocket* socket) { +void ReTCPPeer::setSocket(QAbstractSocket* socket) { m_socket = socket; if (socket != NULL) connect( m_socket, SIGNAL(readyRead()), SLOT(readTcpData()) ); @@ -296,7 +298,7 @@ void RplTcpPeer::setSocket(QAbstractSocket* socket) { /** * @brief Reads the (ready) data from the socket. */ -void RplTcpPeer::readTcpData() { +void ReTCPPeer::readTcpData() { m_waitForData.wakeOne(); } @@ -305,7 +307,7 @@ void RplTcpPeer::readTcpData() { * * @param socketError the error code */ -void RplTcpPeer::handleError(QTcpSocket::SocketError socketError) { +void ReTCPPeer::handleError(QTcpSocket::SocketError socketError) { m_logger->logv(LOG_ERROR, LOC_HANDLE_ERROR_1, "Network error %d", socketError); } @@ -314,7 +316,7 @@ void RplTcpPeer::handleError(QTcpSocket::SocketError socketError) { * @brief Returns a human readable peer address. * @return a string with the peer address: e.g. "192.16.2.3:44335" */ -QByteArray RplTcpPeer::getPeerAddress() { +QByteArray ReTCPPeer::getPeerAddress() { QByteArray rc; if(m_socket == NULL) rc = ""; @@ -328,7 +330,7 @@ QByteArray RplTcpPeer::getPeerAddress() { * * @return the socket */ -QAbstractSocket* RplTcpPeer::getSocket() const { +QAbstractSocket* ReTCPPeer::getSocket() const { return m_socket; } @@ -336,8 +338,8 @@ QAbstractSocket* RplTcpPeer::getSocket() const { * @brief Returns the port. * @return the port of the peer. */ -int RplTcpPeer::getPort(){ - int port = m_configurator.asInt(RplNetConfig::PORT, 12345); +int ReTCPPeer::getPort(){ + int port = m_configurator.asInt(ReNetConfig::PORT, 12345); return port; } /** @@ -345,8 +347,8 @@ int RplTcpPeer::getPort(){ * @return "": all addresses (for listening)
* otherwise: the address (e.g. 127.0.0.1) */ -QByteArray RplTcpPeer::getIp(){ - QByteArray ip = m_configurator.asString(RplNetConfig::IP, ""); +QByteArray ReTCPPeer::getIp(){ + QByteArray ip = m_configurator.asString(ReNetConfig::IP, ""); return ip; } /** @@ -354,7 +356,7 @@ QByteArray RplTcpPeer::getIp(){ * @param ip the ip address * @param port the port */ -void RplTcpPeer::setAddress(const char* ip, int port) +void ReTCPPeer::setAddress(const char* ip, int port) { m_address = QByteArray(ip) + ":" + QByteArray::number(port); } diff --git a/rplnet/rpltcppeer.hpp b/net/ReTCPPeer.hpp similarity index 75% rename from rplnet/rpltcppeer.hpp rename to net/ReTCPPeer.hpp index d040496..51f7dea 100644 --- a/rplnet/rpltcppeer.hpp +++ b/net/ReTCPPeer.hpp @@ -9,10 +9,10 @@ #define RPLTCPPEER_HPP #ifndef RPLNET_HPP -#include "rplnet.hpp" +#include "renet.hpp" #endif -class RplTcpPeer : public QObject { +class ReTCPPeer : public QObject { Q_OBJECT public: enum { @@ -28,25 +28,25 @@ public: ///> connection initialization of } flag_t; public: - static RplTcpPeer* createPeer(RplConfigurator& configurator, + static ReTCPPeer* createPeer(ReConfigurator& configurator, QThread* thread, - RplTerminator* terminator, - RplLogger* logger = NULL); + ReTerminator* terminator, + ReLogger* logger = NULL); public: - RplTcpPeer(RplConfigurator& configurator, QThread* thread, - RplTerminator* terminator, + ReTCPPeer(ReConfigurator& configurator, QThread* thread, + ReTerminator* terminator, bool isServer, - RplLogger* logger = NULL); - virtual ~RplTcpPeer(); + ReLogger* logger = NULL); + virtual ~ReTCPPeer(); private: // No copy constructor: no implementation! - RplTcpPeer(const RplTcpPeer& source); + ReTCPPeer(const ReTCPPeer& source); // No assignment operator: no implementation! - RplTcpPeer& operator =(const RplTcpPeer& source); + ReTCPPeer& operator =(const ReTCPPeer& source); public: virtual bool send(qint8 flags, const char* command, const QByteArray& data); virtual bool receive(QByteArray& command, QByteArray& data); - virtual bool sendAndReceive(quint8 flags, char command [4], + virtual bool sendAndReceive(uint8_t flags, char command [4], QByteArray* data, QByteArray& answer, QByteArray& answerData); void setSocket(QAbstractSocket* socket); QAbstractSocket* getSocket() const; @@ -65,17 +65,17 @@ private: QAbstractSocket* m_socket; // : QByteArray m_address; - RplLogger* m_logger; + ReLogger* m_logger; QByteArray m_received; int m_expected; QThread* m_thread; // Only used for salt generation: - RplRandom m_random; + ReRandom m_random; ///> maximum allowed time (in seconds) for sending/receiving one info unit int m_timeout; ///> for controlled termination - RplTerminator* m_terminator; - RplConfigurator& m_configurator; + ReTerminator* m_terminator; + ReConfigurator& m_configurator; bool m_isServer; QMutex m_dataLocker; QWaitCondition m_waitForData; diff --git a/rplnet/rpltcpserver.cpp b/net/ReTCPServer.cpp similarity index 70% rename from rplnet/rpltcpserver.cpp rename to net/ReTCPServer.cpp index c9ba87f..83a1326 100644 --- a/rplnet/rpltcpserver.cpp +++ b/net/ReTCPServer.cpp @@ -5,20 +5,22 @@ * You also can use the licence from http://www.wtfpl.net/. * The original sources can be found on https://github.com/republib. */ -#include "rplnet.hpp" +#include "base/rebase.hpp" +#include "math/remath.hpp" +#include "net/renet.hpp" enum { - LOC_RUN_1 = RPL_FIRST_OF(RPLMODULE_TCPSERVER), // 10601 + LOC_RUN_1 = LOC_FIRST_OF(LOC_TCPSERVER), // 10601 LOC_TCP_TREAD_RUN_1, LOC_TCP_TREAD_RUN_2, LOC_TCP_INCOMING_CONNECTION_1, }; -/** @class RplTcpThread rpltcpserver.hpp "rplcore/rpltcpserver.hpp" +/** @class ReTCPThread rpltcpserver.hpp "rplcore/rpltcpserver.hpp" * * @brief Serves one connection of a multihreaded TCP server. * - * Note: The real thing is done by the RplTaskHandler instance. + * Note: The real thing is done by the ReTaskHandler instance. */ /** @@ -29,9 +31,9 @@ enum { * @param threadId an unique id for the thread * @param handler does the work */ -RplTcpThread::RplTcpThread(RplConfigurator& configurator, +ReTCPThread::ReTCPThread(ReConfigurator& configurator, qintptr socketDescriptor, int threadId, - RplTaskHandler* handler) : + ReTaskHandler* handler) : m_threadId(threadId), m_taskHandler(handler), m_socketDescriptor(socketDescriptor), @@ -40,7 +42,7 @@ RplTcpThread::RplTcpThread(RplConfigurator& configurator, /** * @brief Destructor. */ -RplTcpThread::~RplTcpThread() { +ReTCPThread::~ReTCPThread() { } @@ -49,24 +51,24 @@ RplTcpThread::~RplTcpThread() { * * Initializes the socket and loops for incoming commands. */ -void RplTcpThread::run() { +void ReTCPThread::run() { QTcpSocket socket; if(!socket.setSocketDescriptor(getSocketDescriptor())) { emit error(socket.error()); } else { - RplTcpPeer peer(m_configurator, this, m_taskHandler->getTerminator(), + ReTCPPeer peer(m_configurator, this, m_taskHandler->getTerminator(), true, m_taskHandler->getLogger()); peer.setSocket(&socket); QByteArray addr = peer.getPeerAddress(); m_taskHandler->getLogger()->logv(LOG_DEBUG, LOC_TCP_TREAD_RUN_1, - "RplTcpThread::run(): start Peer: %s", addr.constData()); + "ReTCPThread::run(): start Peer: %s", addr.constData()); while(m_taskHandler->handle(&peer)) { // do nothing } socket.disconnectFromHost(); socket.waitForDisconnected(); m_taskHandler->getLogger()->logv(LOG_DEBUG, LOC_TCP_TREAD_RUN_1, - "RplTcpThread::run(): end Peer: %s", addr.constData()); + "ReTCPThread::run(): end Peer: %s", addr.constData()); } } @@ -75,7 +77,7 @@ void RplTcpThread::run() { * * @return the thread id */ -int RplTcpThread::getThreadId() const { +int ReTCPThread::getThreadId() const { return m_threadId; } /** @@ -83,7 +85,7 @@ int RplTcpThread::getThreadId() const { * * @return the task handler */ -RplTaskHandler* RplTcpThread::getTaskHandler() const { +ReTaskHandler* ReTCPThread::getTaskHandler() const { return m_taskHandler; } /** @@ -91,11 +93,11 @@ RplTaskHandler* RplTcpThread::getTaskHandler() const { * * @return the socket */ -qintptr RplTcpThread::getSocketDescriptor() const { +qintptr ReTCPThread::getSocketDescriptor() const { return m_socketDescriptor; } -/** @class RplTcpServer rpltcpserver.hpp "rplcore/rpltcpserver" +/** @class ReTCPServer rpltcpserver.hpp "rplcore/rpltcpserver" * * @brief Implements a multithreaded TCP server. */ @@ -109,10 +111,10 @@ qintptr RplTcpThread::getSocketDescriptor() const { * @param logger NULL or logger * @param parent NULL or the parent which deletes the childen */ -RplTcpServer::RplTcpServer(RplConfigurator& configurator, - RplTaskHandler* taskHandler, - RplVMThreadFactory& threadFactory, - RplLogger* logger, +ReTCPServer::ReTCPServer(ReConfigurator& configurator, + ReTaskHandler* taskHandler, + ReVMThreadFactory& threadFactory, + ReLogger* logger, QObject* parent) : QTcpServer(parent), m_taskHandler(taskHandler), @@ -126,8 +128,8 @@ RplTcpServer::RplTcpServer(RplConfigurator& configurator, * * @param socketDescriptor the tcp socket */ -void RplTcpServer::incomingConnection(qintptr socketDescriptor) { - RplTcpThread* thread = m_threadFactory.create(m_configurator, +void ReTCPServer::incomingConnection(qintptr socketDescriptor) { + ReTCPThread* thread = m_threadFactory.create(m_configurator, socketDescriptor, ++m_threadId, m_taskHandler); m_taskHandler->getLogger()->log(LOG_DEBUG, LOC_TCP_INCOMING_CONNECTION_1, "Connection detected"); @@ -135,13 +137,13 @@ void RplTcpServer::incomingConnection(qintptr socketDescriptor) { thread->start(); } -/** @class RplTcpThread rpltcpserver.hpp "rplcore/rpltcpserver.hpp" +/** @class ReTCPThread rpltcpserver.hpp "rplcore/rpltcpserver.hpp" * - * @brief Defines a function pointer type to create a RplTcpThread instance. + * @brief Defines a function pointer type to create a ReTCPThread instance. * */ -/** @class RplTaskHandler rpltcpserver.hpp "rplcore/rpltcpserver.hpp" +/** @class ReTaskHandler rpltcpserver.hpp "rplcore/rpltcpserver.hpp" * * @brief An abstract base class for an handler processing an data unit. * @@ -154,8 +156,8 @@ void RplTcpServer::incomingConnection(qintptr socketDescriptor) { * @param terminator external controller for thread termination * @param logger the logger */ -RplTaskHandler::RplTaskHandler(RplConfigurator& configurator, - RplTerminator* terminator, RplLogger* logger) : +ReTaskHandler::ReTaskHandler(ReConfigurator& configurator, + ReTerminator* terminator, ReLogger* logger) : m_answerFlags(0), m_logger(logger), m_terminator(terminator), @@ -165,7 +167,7 @@ RplTaskHandler::RplTaskHandler(RplConfigurator& configurator, /** * @brief Destructor. */ -RplTaskHandler::~RplTaskHandler() { +ReTaskHandler::~ReTaskHandler() { } /** @@ -175,7 +177,7 @@ RplTaskHandler::~RplTaskHandler() { * @return false: the application should stop
* true: processing remains */ -bool RplTaskHandler::handle(RplTcpPeer* peer) { +bool ReTaskHandler::handle(ReTCPPeer* peer) { QByteArray command; QByteArray data; QByteArray answer; @@ -195,7 +197,7 @@ bool RplTaskHandler::handle(RplTcpPeer* peer) { * * @param id the thread id */ -void RplTaskHandler::setThreadId(int id) { +void ReTaskHandler::setThreadId(int id) { m_threadId = id; } @@ -204,7 +206,7 @@ void RplTaskHandler::setThreadId(int id) { * * @return the thread id */ -int RplTaskHandler::getThreadId() const { +int ReTaskHandler::getThreadId() const { return m_threadId; } @@ -213,7 +215,7 @@ int RplTaskHandler::getThreadId() const { * * @return the logger */ -RplLogger* RplTaskHandler::getLogger() const { +ReLogger* ReTaskHandler::getLogger() const { return m_logger; } @@ -222,7 +224,7 @@ RplLogger* RplTaskHandler::getLogger() const { * * @return the termination controller */ -RplTerminator* RplTaskHandler::getTerminator() const { +ReTerminator* ReTaskHandler::getTerminator() const { return m_terminator; } diff --git a/rplnet/rpltcpserver.hpp b/net/ReTCPServer.hpp similarity index 56% rename from rplnet/rpltcpserver.hpp rename to net/ReTCPServer.hpp index 2683346..bcbe5d0 100644 --- a/rplnet/rpltcpserver.hpp +++ b/net/ReTCPServer.hpp @@ -10,19 +10,19 @@ // the sources generated from QT include this file directly: #ifndef RPLNET_HPP -#include "rplnet.hpp" +#include "renet.hpp" #endif -class RplTcpPeer; -class RplTaskHandler { +class ReTCPPeer; +class ReTaskHandler { public: - RplTaskHandler(RplConfigurator& configurator, - RplTerminator* terminator, - RplLogger* logger); - virtual ~RplTaskHandler(); + ReTaskHandler(ReConfigurator& configurator, + ReTerminator* terminator, + ReLogger* logger); + virtual ~ReTaskHandler(); public: - virtual bool handle(RplTcpPeer* peer); + virtual bool handle(ReTCPPeer* peer); /** * @brief Processes one data unit from the socket. * @@ -37,33 +37,33 @@ public: QByteArray& answer, QByteArray& answerData) = 0; void setThreadId(int id); int getThreadId() const; - RplLogger* getLogger() const; - RplTerminator* getTerminator() const; + ReLogger* getLogger() const; + ReTerminator* getTerminator() const; protected: - quint8 m_answerFlags; + uint8_t m_answerFlags; private: int m_threadId; - RplLogger* m_logger; - RplTerminator* m_terminator; - RplConfigurator& m_configurator; + ReLogger* m_logger; + ReTerminator* m_terminator; + ReConfigurator& m_configurator; }; -class RplTcpThread : public QThread { +class ReTCPThread : public QThread { Q_OBJECT public: - RplTcpThread(RplConfigurator& m_configurator, + ReTCPThread(ReConfigurator& m_configurator, qintptr socketDescriptor, int threadId, - RplTaskHandler* handler); - virtual ~RplTcpThread(); + ReTaskHandler* handler); + virtual ~ReTCPThread(); private: // No copy constructor: no implementation! - RplTcpThread(const RplTcpThread& source); + ReTCPThread(const ReTCPThread& source); // No assignment operator: no implementation! - RplTcpThread& operator=(const RplTcpThread& source); + ReTCPThread& operator=(const ReTCPThread& source); public: void run(); int getThreadId() const; - RplTaskHandler* getTaskHandler() const; + ReTaskHandler* getTaskHandler() const; qintptr getSocketDescriptor() const; signals: @@ -73,45 +73,45 @@ private: // a unique id for the thread int m_threadId; // this handler interprets the info from the TCP connection - RplTaskHandler* m_taskHandler; + ReTaskHandler* m_taskHandler; // the assigned socket qintptr m_socketDescriptor; - RplConfigurator& m_configurator; + ReConfigurator& m_configurator; }; -class RplThreadFactory { +class ReThreadFactory { public: - virtual RplTcpThread* create(RplConfigurator& configurator, + virtual ReTCPThread* create(ReConfigurator& configurator, qintptr socketDescriptor, int threadId, - RplTaskHandler* handler) = 0; + ReTaskHandler* handler) = 0; }; -class RplTcpPeer; -class RplTcpServer : public QTcpServer, public RplTerminator { +class ReTCPPeer; +class ReTCPServer : public QTcpServer, public ReTerminator { Q_OBJECT public: - explicit RplTcpServer(RplConfigurator& configurator, - RplTaskHandler* taskHandler, - RplThreadFactory& threadFactory, - RplLogger* logger = NULL, QObject* parent = 0); + explicit ReTCPServer(ReConfigurator& configurator, + ReTaskHandler* taskHandler, + ReThreadFactory& threadFactory, + ReLogger* logger = NULL, QObject* parent = 0); private: // No copy constructor: no implementation! - RplTcpServer(const RplTcpServer& source); + ReTCPServer(const ReTCPServer& source); // No assignment operator: no implementation! - RplTcpServer& operator=(const RplTcpServer& source); + ReTCPServer& operator=(const ReTCPServer& source); public: - RplTcpPeer* getPeer() const; + ReTCPPeer* getPeer() const; bool handleTask(); protected slots: void incomingConnection(qintptr socketDescriptor); private: - RplTaskHandler* m_taskHandler; + ReTaskHandler* m_taskHandler; int m_threadId; - RplTcpPeer* m_peer; - RplThreadFactory& m_threadFactory; - RplConfigurator& m_configurator; + ReTCPPeer* m_peer; + ReThreadFactory& m_threadFactory; + ReConfigurator& m_configurator; }; #endif // RPLTCPSERVER_HPP diff --git a/rplnet/rplnet.hpp b/net/renet.hpp similarity index 71% rename from rplnet/rplnet.hpp rename to net/renet.hpp index f9c4731..f151faa 100644 --- a/rplnet/rplnet.hpp +++ b/net/renet.hpp @@ -16,11 +16,9 @@ #include #include -//includes implicite rplcore.hpp: -#include "../rplmath/rplmath.hpp" -#include "rpltcppeer.hpp" -#include "rpltcpserver.hpp" -#include "rpltcpclient.hpp" -#include "rplnetconfig.hpp" +#include "net/ReTCPPeer.hpp" +#include "net/ReTCPServer.hpp" +#include "net/ReTCPClient.hpp" +#include "net/ReNetConfig.hpp" #endif // RPLNET_HPP diff --git a/remodules.hpp b/remodules.hpp new file mode 100644 index 0000000..4cd4dc3 --- /dev/null +++ b/remodules.hpp @@ -0,0 +1,29 @@ +#ifndef RPLMODULES_HPP +#define RPLMODULES_HPP + +enum { + LOC_LOGGER = 101, + LOC_CONFIG, + LOC_CONTAINER, + LOC_EXCEPTION, + LOC_TEST, // 105 + LOC_TCPSERVER, + LOC_TCPCLIENT, + LOC_TCPPEER, + LOC_TERMINATOR, + LOC_ASTREE, // 110 + LOC_ASCLASSES, + LOC_LEXER, + LOC_SOURCE, + LOC_VM, + LOC_MFPARSER, // 115 +}; +#define LOC_FIRST_OF(moduleNo) (moduleNo*100+1) +class RplModules{ +public: + static int fileToNumber(const char* file); + static const char* numberToFile(int location); +}; + + +#endif // RPLMODULES_HPP diff --git a/rplcore/rplexception.hpp b/rplcore/rplexception.hpp deleted file mode 100644 index 64fd530..0000000 --- a/rplcore/rplexception.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 RPLEXCEPTION_HPP -#define RPLEXCEPTION_HPP - -// the sources generated from QT include this file directly: -#ifndef RPLCORE_HPP -#include -#endif - -class RplException { -protected: - RplException(); -public: - RplException(const char* message, ...); - RplException(RplLoggerLevel level, int location, const char* message, - RplLogger* logger = NULL); - RplException(RplLoggerLevel level, int location, RplLogger* logger, - const char* message, ...); - const QByteArray& getMessage() const { - return m_message; - } -protected: - QByteArray m_message; -}; - -class RplRangeException : public RplException { -public: - RplRangeException(RplLoggerLevel level, int location, size_t current, - size_t lbound, size_t ubound, - const char* message = NULL, RplLogger* logger = NULL); -}; - -class RplInvalidDataException : public RplException { -public: - RplInvalidDataException(RplLoggerLevel level, int location, const char* message, - const void* data = NULL, size_t dataSize = 0, RplLogger* logger = NULL); -}; - -#endif // RPLEXCEPTION_HPP diff --git a/rplexpr/rplastree.hpp b/rplexpr/rplastree.hpp deleted file mode 100644 index 899dfa4..0000000 --- a/rplexpr/rplastree.hpp +++ /dev/null @@ -1,755 +0,0 @@ -/* - * Licence: - * You can use and modify this file without any restriction. - * There is no warranty. - * You also can use the licence from http://www.wtwriterl.net/. - * The original sources can be found on https://github.com/republib. -*/ - - -#ifndef RPLASTREE_HPP -#define RPLASTREE_HPP - -enum RplASItemType { - AST_UNDEF, - AST_CONSTANT, - AST_LIST_CONSTANT, - AST_LIST_ENTRY, - AST_MAP_CONSTANT, - AST_MAP_ENTRY, - AST_NAMED_VALUE, - AST_CONVERSION, - AST_INDEXED_VALUE, - AST_FIELD, - AST_VAR_DEFINITION, - AST_EXPR_STATEMENT, - AST_METHOD, - AST_ARGUMENT, - AST_INTRINSIC_METHOD, - AST_PRE_UNARY_OP, - AST_POST_UNARY_OP, - AST_BINARY_OP, - AST_METHOD_CALL, - AST_WHILE, - AST_REPEAT, - AST_IF, - AST_CONDITION, - AST_ITERATED_FOR, - AST_COUNTED_FOR, - AST_SWITCH, - AST_LEAVE, - AST_CONTINUE -}; - -class RplASException : public RplException { -public: - RplASException(); - RplASException(const RplSourcePosition* position, const char* format, ...); -protected: - void build(const RplSourcePosition* position, const char* format, - va_list varList); -}; - -class RplASClass; -class RplASNamedValue; -class RplASItem; -class RplASCondition; - -class RplASVariant { - /* The VM uses some tricks (performance): Therefore this class - * must not be virtual! - */ -public: - enum VariantType { - VT_UNDEF, - VT_FLOAT, - VT_INTEGER, - VT_BOOL, - VT_OBJECT - }; - enum VariantFlags { - VF_UNDEF, - /// if DT_OBJECT: object is a copy, don't free at method end - VF_IS_COPY = 1 << 1, - /// debugger: action if changed - VF_WATCH_POINT = 1 << 2 - }; - - friend class RplASCondition; -public: - RplASVariant(); - ~RplASVariant(); - RplASVariant(const RplASVariant& source); - RplASVariant& operator=(const RplASVariant& source); - qreal asFloat() const; - int asInt() const; - bool asBool() const; - void* asObject(const RplASClass** clazz) const; - const QByteArray* asString() const; - void setFloat(qreal number); - void setInt(int integer); - void setBool(bool value); - void setObject(void* object, const RplASClass* clazz); - void setString(const QByteArray& string); - QByteArray toString(int maxLength = 80) const; - VariantType variantType() const; - const char* nameOfType() const; - const RplASClass* getClass() const; - void copyValue(const RplASVariant& source); - void destroyValue(); -private: - VariantType m_variantType:8; - /// bitmap of VF_... flags: - int m_flags:8; - union { - qreal m_float; - int m_int; - bool m_bool; - void* m_object; - } m_value; - const RplASClass* m_class; -}; - -class RplASTree; -class RplParser; -class RplVMThread; - -class RplASItem -{ -public: - enum NodeFlags { - NF_UNDEF, - /// the node calculates a value: - NF_CALCULABLE = 1 << 1, - /// the node calculates a value: - NF_STATEMENT = 1 << 2, - /// the tree under this node is complete checked for data type correctness - NF_TYPECHECK_COMPLETE = 1 << 3, - /// debugger: this node is a breakpoint - NF_BREAKPOINT = 1 << 5 - }; - -public: - friend class RplASTree; - RplASItem(RplASItemType type); - virtual ~RplASItem(); -public: - virtual bool check(RplParser& parser) = 0; -public: - bool checkAsCalculable(const char* description, RplASClass* expectedClass, - RplParser& parser); - const RplSourcePosition* position() const; - void setPosition(const RplSourcePosition* position); - unsigned int id() const; - char* positionStr(char buffer[], size_t bufferSize) const; - void error(RplLogger* logger, int location, const char* format, ...); -public: - /** - * @brief Writes the content of the instance into an output medium. - * - * @param writer writes to output media - * @param indent nesting level: so many tabs will be used as prefix - */ - virtual void dump(RplWriter& writer,int indent) = 0; -public: - static void reset(); - static bool checkStatementList(RplASItem* list, RplParser& parser); - static int calcAsInteger(RplASItem* expr, RplVMThread& thread); - static bool calcAsBoolean(RplASItem* expr, RplVMThread& thread); -public: - RplASItemType nodeType() const; - const char* nameOfItemType() const; - - 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, const char* info); -protected: - unsigned int m_id:16; - RplASItemType m_nodeType:8; - int m_flags:5; - int m_dataType: 3; - const RplSourcePosition* m_position; -private: - static unsigned int m_nextId; -}; - -class RplASNode1; -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 : public RplASCalculable { -}; -class RplVMThread; -class RplASConstant : public RplASItem, public RplASCalculable -{ -public: - RplASConstant(); -public: - virtual void calc(RplVMThread& thread); - virtual bool check(RplParser& parser); -public: - virtual void dump(RplWriter& writer,int indent); - RplASVariant& value(); -private: - RplASVariant m_value; -}; - - -class RplASNode1 : public RplASItem -{ -public: - RplASNode1(RplASItemType type); - virtual ~RplASNode1(); -public: - RplASItem* child() const; - void setChild(RplASItem* child); -public: - static void dumpStatements(RplWriter& writer, int indent, RplASItem* statements); -protected: - RplASItem* m_child; -}; - -class RplASNode2 : public RplASNode1 -{ -public: - RplASNode2(RplASItemType type); - virtual ~RplASNode2(); -public: - RplASItem* child2() const; - void setChild2(RplASItem* child2); - -protected: - RplASItem* m_child2; -}; - -class RplASNode3 : public RplASNode2 -{ -public: - RplASNode3(RplASItemType type); - virtual ~RplASNode3(); -public: - RplASItem* child3() const; - void setChild3(RplASItem* child3); - -protected: - RplASItem* m_child3; -}; - -class RplASNode4 : public RplASNode3 -{ -public: - RplASNode4(RplASItemType type); - virtual ~RplASNode4(); -public: - RplASItem* child4() const; - void setChild4(RplASItem* child4); - -protected: - RplASItem* m_child4; -}; - -class RplASNode5 : public RplASNode4 -{ -public: - RplASNode5(RplASItemType type); - virtual ~RplASNode5(); -public: - RplASItem*child5() const; - void setChild5(RplASItem* child5); -protected: - RplASItem* m_child5; -}; -class RplASNode6 : public RplASNode5 -{ -public: - RplASNode6(RplASItemType type); - virtual ~RplASNode6(); -public: - RplASItem*child6() const; - void setChild6(RplASItem* child5); -protected: - RplASItem* m_child6; -}; - -typedef QList RplASListOfVariants; -typedef QMap RplASMapOfVariants; - -class RplASListConstant : public RplASNode1, public RplASCalculable -{ -public: - RplASListConstant(); -public: - virtual void calc(RplVMThread& thread); - virtual bool check(RplParser& parser); - -public: - virtual void dump(RplWriter& writer,int indent); - RplASVariant& value(); - RplASListOfVariants* list(); -private: - RplASVariant m_value; -}; -class RplASMapConstant : public RplASNode1, public RplASCalculable -{ -public: - RplASMapConstant(); -public: - virtual void calc(RplVMThread& thread); - virtual bool check(RplParser& parser); -public: - virtual void dump(RplWriter& writer,int indent); - RplASVariant& value(); - RplASMapOfVariants* map(); -private: - RplASVariant m_value; -}; - -class RplSymbolSpace; -class RplASNamedValue : public RplASItem, public RplASStorable -{ - friend class RplASVarDefinition; -public: - enum Attributes { - A_NONE, - /// the value cannot be changed. - A_CONST = 1<<1, - /// the variable/constant is found in the global namespace, not in a method - A_GLOBAL = 1<<2, - /// the variable/constant is found in the module namespace, not in a method - A_MODULE_STATIC = 1<<3, - /// the evaluation should be lazy - A_LAZY = 1<<4, - /// parameter of a method - A_PARAM = 1<<5, - /// a automatic variable in counted for loops: - A_LOOP = 1<<6 - }; - -public: - RplASNamedValue(RplASClass* clazz, 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); - void dump(RplWriter& writer, int indent); - RplSymbolSpace* symbolSpace() const; - int variableNo() const; - void setVariableNo(int variableNo); -protected: - QByteArray m_name; - int m_attributes; - 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, bool& isCorrect); - static Conversion findConversion(RplASClass* from, RplASClass* to); -private: - Conversion m_conversion; -}; - -class RplASIndexedValue : public RplASNode2, public RplASCalculable { -public: - RplASIndexedValue(); -public: - virtual void calc(RplVMThread& thread); - virtual bool check(RplParser& parser); -public: - void dump(RplWriter& writer, int indent); -}; - -class RplASStatement -{ -public: - RplASStatement(); -public: - virtual int execute(RplVMThread& thread) = 0; -public: - static int executeStatementList(RplASItem* list, RplVMThread& thread); -}; - - -class RplASVarDefinition : public RplASNode3, public RplASStatement -{ -public: - RplASVarDefinition(); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); -public: - void dump(RplWriter& writer, int indent); - const QByteArray& name() 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 - /// Note: the source unit is stored in RplASItem::m_sourcePosition - int m_endOfScope; -}; - -class RplASExprStatement : public RplASNode2, public RplASStatement -{ -public: - RplASExprStatement(); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); -public: - void dump(RplWriter& writer, int indent); -}; - -class RplASUnaryOp : public RplASNode1, RplASCalculable -{ -public: - enum UnaryOp { - UOP_UNDEF, - UOP_PLUS, - UOP_MINUS_INT, - UOP_MINUS_FLOAT, - UOP_NOT_BOOL, - UOP_NOT_INT, - UOP_INC, - UOP_DEC - }; -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: - static const char* nameOfOp(UnaryOp op); -private: - UnaryOp m_operator; -}; -class RplASBinaryOp : public RplASNode2, public RplASCalculable -{ -public: - enum BinOperator { - BOP_UNDEF, - BOP_ASSIGN, - BOP_PLUS_ASSIGN, - BOP_MINUS_ASSIGN, - BOP_TIMES_ASSIGN, - BOP_DIV_ASSIGN, - BOP_MOD_ASSIGN, - BOP_POWER_ASSIGN, - BOP_LOG_OR_ASSIGN, - BOP_LOG_AND_ASSIGN, - BOP_LOG_XOR_ASSIGN, - BOP_BIT_OR_ASSIGN, - BOP_BIT_AND_ASSIGN, - BOP_BIT_XOR_ASSIGN, - BOP_LSHIFT_ASSIGN, - BOP_LOG_RSHIFT_ASSIGN, - BOP_ARTITH_RSHIFT_ASSIGN, - BOP_PLUS, - BOP_MINUS, - BOP_TIMES, - BOP_DIV, - BOP_MOD, - BOP_POWER, - BOP_LOG_OR, - BOP_LOG_AND, - BOP_LOG_XOR, - BOP_BIT_OR, - BOP_BIT_AND, - BOP_BIT_XOR, - BOP_LSHIFT, - BOP_LOG_RSHIFT, - BOP_ARTITH_RSHIFT, - BOP_EQ, - BOP_NE, - BOP_LE, - BOP_LT, - BOP_GE, - BOP_GT, - BOB_COUNT - }; -private: - inline bool isAssignment() const { - return m_operator >= BOP_ASSIGN - && m_operator <= BOP_ARTITH_RSHIFT_ASSIGN; - } -public: - RplASBinaryOp(); -public: - virtual void calc(RplVMThread& thread); - virtual bool check(RplParser& parser); -public: - BinOperator getOperator() const; - void setOperator(BinOperator op); - void dump(RplWriter& writer, int indent); -private: - void assign(RplVMThread& thread); -public: - static const char* nameOfOp(BinOperator op); -private: - BinOperator m_operator; -}; - -class RplASIf : public RplASNode4, public RplASStatement -{ -public: - RplASIf(); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); - virtual void dump(RplWriter& writer, int indent); -}; - -class RplASForIterated : public RplASNode4, public RplASStatement -{ -public: - RplASForIterated(RplASVarDefinition* variable); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); - virtual void dump(RplWriter& writer, int indent); -}; - -class RplASForCounted : public RplASNode6, public RplASStatement -{ -public: - RplASForCounted(RplASVarDefinition* variable); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); - virtual void dump(RplWriter& writer, int indent); -}; - -class RplASWhile : public RplASNode3, public RplASStatement -{ -public: - RplASWhile(); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); - virtual void dump(RplWriter& writer, int indent); -}; - -class RplASRepeat : public RplASNode3, public RplASStatement -{ -public: - RplASRepeat(); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); - virtual void dump(RplWriter& writer, int indent); -}; - -class RplASMethod; -class RplASMethodCall : public RplASNode3, public RplASStatement -{ -public: - RplASMethodCall(const QByteArray& name, RplASItem* parent); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); -public: - void dump(RplWriter& writer, int indent); - -public: - RplASMethod* method() const; - void setMethod(RplASMethod* method); - - RplASExprStatement* arg1() const; -private: - QByteArray m_name; - RplASMethod* m_method; -}; - -class RplParameter : RplASItem -{ -public: - RplParameter(); - virtual ~RplParameter(); -private: - QByteArray m_name; - RplASNamedValue* m_default; -}; - -class RplASField : public RplASNode1 -{ -public: - RplASField(const QByteArray& name); -public: - virtual bool check(RplParser& parser); -public: - void dump(RplWriter& writer, int indent); -private: - QByteArray m_name; -}; - - -class RplASClass; -class RplSymbolSpace; -class RplASMethod : public RplASNode2 -{ -public: - RplASMethod(const QByteArray& name, RplASTree& tree); -public: - virtual bool check(RplParser& parser); - virtual int execute(RplVMThread& thread); -public: - void dump(RplWriter& writer, int indent); - RplSymbolSpace* symbols() const; - void setSymbols(); - const QByteArray& name() const; - bool equalSignature(RplASMethod& other) const; - RplASMethod* sibling() const; - void setSibling(RplASMethod* sibling); - -private: - QByteArray m_name; - RplASClass* m_resultType; - RplSymbolSpace* m_symbols; - // chain over all overloaded methods (same name, other signature): - RplASMethod* m_sibling; - RplASTree& m_tree; -}; - -class RplASClass { -public: - typedef QMap MethodMap; -public: - RplASClass(const QByteArray& name, RplASTree& m_tree); - virtual ~RplASClass(); -public: - /** - * @brief Creates a value object (used in RplASVariant). - * - * @param source NULL or a source to copy - * @return a new value object (specific for the class) - */ - virtual void* newValueInstance(void* source = NULL) const = 0; - /** - * @brief Destroys the given object. - * - * The object must be created by newValueInstance(). - * - * @param object object to destroy - */ - virtual void destroyValueInstance(void* object) const = 0; - /** - * @brief Returns the boolean value of a class specific value. - * - * Example: the boolean value of an the empty string is false - * - * @param object object to test - * @return false: the object represents the false value
- * true: otherwise - */ - virtual bool boolValueOf(void* object) const = 0; - /** - * @brief Returns a string representation of an instance. - * - * @param object the object to convert - * @param maxLength the maximum length of the result (string) - * @return a string describing the object - */ - virtual QByteArray toString(void *object, int maxLength = 80) const = 0; -public: - const QByteArray& name() const; - virtual void dump(RplWriter& writer, int indent); - void setSymbols(); -protected: - QByteArray m_name; - RplSymbolSpace* m_symbols; - const RplASClass* m_superClass; - RplASTree& m_tree; -}; - -#include "rplexpr/rplasclasses.hpp" - -#include "rplparser.hpp" -class RplSymbolSpace; -class RplASTree -{ -public: - enum { - DMP_NONE, - DMP_GLOBALS = 1<<1, - DMP_MODULES = 1<<2, - DMP_SPACE_STACK = 1<<3, - DMP_SPACE_HEAP = 1<<4, - DMP_ALL = DMP_GLOBALS | DMP_MODULES | DMP_SPACE_STACK | DMP_SPACE_HEAP, - DMP_NO_GLOBALS = DMP_MODULES | DMP_SPACE_STACK | DMP_SPACE_HEAP - }; - typedef QMap SymbolSpaceMap; - typedef QList SymbolSpaceStack; -public: - RplASTree(); - ~RplASTree(); -public: - bool startModule(RplSourceUnitName name); - void finishModule(RplSourceUnitName name); - RplSymbolSpace* startClassOrMethod(const QByteArray& name, - RplSymbolSpace::SymbolSpaceType type); - void finishClassOrMethod(const QByteArray& name); - SymbolSpaceStack& symbolSpaces(); - RplSymbolSpace* currentSpace() const; - RplASClass* findClass(const QByteArray& name); - void clear(); - void dump(const char* filename, int flags = DMP_ALL, - const char* header = NULL); - RplSymbolSpace*findmodule(const QByteArray& name); - RplSourcePosition* copyPosition(); - RplByteStorage& store(); - -protected: - void init(); - void destroy(); -private: - // the mother of all symbol spaces. - RplSymbolSpace* m_global; - // contains all hit modules - SymbolSpaceMap m_modules; - // nested modules (import), classes and methods build this stack: - SymbolSpaceStack m_symbolSpaces; - // top of the stack: - RplSymbolSpace* m_currentSpace; - // contain all ever built symbol spaces: - SymbolSpaceMap m_symbolSpaceHeap; - RplByteStorage m_store; -}; - -#endif // RPLASTREE_HPP diff --git a/rplexpr/rplvm.hpp b/rplexpr/rplvm.hpp deleted file mode 100644 index a22d860..0000000 --- a/rplexpr/rplvm.hpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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 RPLVM_HPP -#define RPLVM_HPP - -class RplVmException : public RplException { -public: - RplVmException(const char* message, ...); -}; -class RplStackFrame { -public: - RplStackFrame(RplSymbolSpace* symbols); - ~RplStackFrame(); -public: - RplASVariant& valueOfVariable(int index); - RplSymbolSpace* symbols() const; - -private: - int m_countVariables; - RplASVariant* m_variables; - RplSymbolSpace* m_symbols; -}; - -class RplVirtualMachine; -class RplVMThread -{ - friend class RplASItem; - friend class RplASStatement; - friend class RplASCalculable; - friend class RplASCondition; -public: - typedef QList StackFrameList; -public: - RplVMThread(int maxStack, RplVirtualMachine* vm); -public: - void execute(RplASNode1* statements, RplSymbolSpace* space); - virtual void debug(RplASNode1* statement); - RplWriter* errorWriter() const; - void setErrorWriter(RplWriter* errorWriter); - RplLogger* logger() const; - RplASVariant& reserveValue(); - RplASVariant& topOfValues(); - RplASVariant& top2OfValues(); - RplASVariant& popValue(); - 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; - QList m_valueStack; - int m_topOfValues; - RplVirtualMachine* m_vm; - RplLogger* m_logger; -private: - static int m_nextId; -}; - -class RplVirtualMachine -{ -public: - enum VMFlag { - VF_UNDEF, - VF_TRACE_STATEMENTS = 1<<1, - VF_TRACE_LOCALS = 1<<2, - VF_TRACE_AUTO_VARIABLES = 1<<3 - - }; - typedef QList LineList; -public: - RplVirtualMachine(RplASTree& tree, RplSource& source, int maxStack = 1024); -public: - void executeModule(const char* module); - void addThread(RplASItem* initialization, - RplSymbolSpace* spaceInitialization, - RplASItem* statements, RplSymbolSpace* space, - int maxStack = 0); - bool hasFlag(VMFlag flag) const; - void setFlag(VMFlag flag); - void clearFlag(VMFlag flag); - RplWriter* traceWriter() const; - void setTraceWriter(RplWriter* traceWriter); - RplASTree& tree() const; - -private: - int m_maxStack; - QList m_threads; - int m_flags; - RplSource& m_source; - RplASTree& m_tree; - LineList m_trace; - RplWriter* m_traceWriter; -}; - -#endif // RPLVM_HPP diff --git a/rplmath/rplrandom.hpp b/rplmath/rplrandom.hpp deleted file mode 100644 index a041fb6..0000000 --- a/rplmath/rplrandom.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef RPLRANDOM_HPP -#define RPLRANDOM_HPP - -#include -class RplRandom { -public: - RplRandom(); - virtual ~RplRandom(); -private: - // No copy constructor: no implementation! - RplRandom(const RplRandom& source); - // Prohibits assignment operator: no implementation! - RplRandom& operator =(const RplRandom& source); -public: - virtual u_int64_t nextInt64(); - virtual void setSeed(u_int64_t seed); - void xorSeed(u_int64_t seed); - quint8 nextByte(); - int nextInt(int minValue, int maxValue); - QByteArray nextString(int length = 8, char minChar = ' ', char maxChar = 127); - QByteArray nextString(int length, char* charSet); -protected: - u_int64_t m_seed; -}; - - -#endif // RPLRANDOM_HPP diff --git a/rplmodules.hpp b/rplmodules.hpp deleted file mode 100644 index 86ff3b9..0000000 --- a/rplmodules.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef RPLMODULES_HPP -#define RPLMODULES_HPP - -enum { - RPLMODULE_LOGGER = 101, - RPLMODULE_CONFIG, - RPLMODULE_CONTAINER, - RPLMODULE_EXCEPTION, - RPLMODULE_TEST, // 105 - RPLMODULE_TCPSERVER, - RPLMODULE_TCPCLIENT, - RPLMODULE_TCPPEER, - RPLMODULE_TERMINATOR, - RPL_MODULE_ASTREE, // 110 - RPL_MODULE_ASCLASSES, - RPL_MODULE_LEXER, - RPL_MODULE_SOURCE, - RPL_MODULE_VM, - RPL_MODULE_MFPARSER, // 115 - // last element: - RPLMODULE_COUNT -}; -#define RPL_FIRST_OF(moduleNo) (moduleNo*100+1) -class RplModules{ -public: - static int fileToNumber(const char* file); - static const char* numberToFile(int location); -}; - - -#endif // RPLMODULES_HPP diff --git a/rplnet/rplnetconfig.cpp b/rplnet/rplnetconfig.cpp deleted file mode 100644 index bdb28d5..0000000 --- a/rplnet/rplnetconfig.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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 "rplnetconfig.hpp" - -const char* RplNetConfig::IP = "connection.ip"; -const char* RplNetConfig::PORT = "connection.port"; -const char* RplNetConfig::SLEEP_MILLISEC = "connection.sleepmillisec"; diff --git a/rplstatic/getsrc.pl b/rplstatic/getsrc.pl deleted file mode 100644 index 7618a1f..0000000 --- a/rplstatic/getsrc.pl +++ /dev/null @@ -1,29 +0,0 @@ -#! /usr/bin/perl - -use strict; - -my @rc; -push @rc, &oneDir("../rplcore/*.hpp"); -push @rc, &oneDir("../rplmath/*.hpp"); -push @rc, &oneDir("../rplnet/*.hpp"); -push @rc, "\n"; -push @rc, &oneDir("../rplcore/*.cpp"); -push @rc, &oneDir("../rplmath/*.cpp"); -push @rc, &oneDir("../rplnet/*.cpp"); - -print @rc; -exit 0; - -sub oneDir{ - my $pattern = shift; - my @rc; - open (my $INP, "ls -1 $pattern|") || die "ls -1 $pattern: $!"; - while(<$INP>) { - if (/(\S+)/){ - push(@rc, " $1 \\\n"); - } - } - return @rc; -} - - diff --git a/rplstatic/rplstatic.pro b/rplstatic/rplstatic.pro deleted file mode 100644 index 2263c8d..0000000 --- a/rplstatic/rplstatic.pro +++ /dev/null @@ -1,84 +0,0 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2014-05-30T21:36:15 -# -#------------------------------------------------- - -QT += network testlib - -QT -= gui - -TARGET = rplstatic -TEMPLATE = lib -CONFIG += staticlib - -INCLUDEPATH = .. - -SOURCES += \ - ../rplcore/rplconfig.cpp \ - ../rplcore/rplcontainer.cpp \ - ../rplcore/rplexception.cpp \ - ../rplcore/rpllogger.cpp \ - ../rplcore/rplstring.cpp \ - ../rplcore/rplterminator.cpp \ - ../rplcore/rpltest.cpp \ - ../rplmath/rplenigma.cpp \ - ../rplmath/rplmatrix.cpp \ - ../rplmath/rplmatrix_test.cpp \ - ../rplmath/rplrandom.cpp \ - ../rplnet/rplnetconfig.cpp \ - ../rplnet/rpltcpclient.cpp \ - ../rplnet/rpltcppeer.cpp \ - ../rplnet/rpltcpserver.cpp \ - ../rplexpr/rpllexer.cpp \ - ../rplexpr/rplsource.cpp \ - ../rplcore/rplqstring.cpp \ - ../rplexpr/rplastree.cpp \ - ../rplexpr/rplasclasses.cpp \ - ../rplexpr/rplmfparser.cpp \ - ../rplexpr/rplvm.cpp \ - ../rplexpr/rplparser.cpp \ - ../rplcore/rplbytestorage.cpp \ - ../rplcore/rplwriter.cpp \ - ../rplcore/rplcharptrmap.cpp - -HEADERS += ../rplmodules.hpp \ - ../rplcore/rplconfig.hpp \ - ../rplcore/rplconfigurator.hpp \ - ../rplcore/rplcontainer.hpp \ - ../rplcore/rplcore.hpp \ - ../rplcore/rplexception.hpp \ - ../rplcore/rpllogger.hpp \ - ../rplcore/rplstring.hpp \ - ../rplcore/rplterminator.hpp \ - ../rplcore/rpltest.hpp \ - ../rplmath/rplenigma.hpp \ - ../rplmath/rplmath.hpp \ - ../rplmath/rplmatrix.hpp \ - ../rplmath/rplrandom.hpp \ - ../rplnet/rplnetconfig.hpp \ - ../rplnet/rplnet.hpp \ - ../rplnet/rpltcpclient.hpp \ - ../rplnet/rpltcppeer.hpp \ - ../rplnet/rpltcpserver.hpp \ - ../rplexpr/rpllexer.hpp \ - ../rplexpr/rplexpr.hpp \ - ../rplexpr/rplsource.hpp \ - ../rplcore/rplqstring.hpp \ - ../rplexpr/rplastree.hpp \ - ../rplexpr/rplasclasses.hpp \ - ../rplexpr/rplmfparser.hpp \ - ../rplexpr/rplvm.hpp \ - ../rplexpr/rplparser.hpp \ - ../rplcore/rplbytestorage.hpp \ - ../rplcore/rplwriter.hpp \ - ../rplcore/rplcharptrmap.hpp - -unix:!symbian { - maemo5 { - target.path = /opt/usr/lib - } else { - target.path = /usr/lib - } - INSTALLS += target -} diff --git a/static/rplstatic.pro b/static/rplstatic.pro new file mode 100644 index 0000000..82c9e9b --- /dev/null +++ b/static/rplstatic.pro @@ -0,0 +1,83 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-30T21:36:15 +# +#------------------------------------------------- + +QT += network testlib + +QT -= gui + +TARGET = rplstatic +TEMPLATE = lib +CONFIG += staticlib + +INCLUDEPATH = .. /usr/include/c++/4.9 + +SOURCES += \ + ../base/ReConfig.cpp \ + ../base/ReContainer.cpp \ + ../base/ReException.cpp \ + ../base/ReLogger.cpp \ + ../base/ReStringUtil.cpp \ + ../base/ReTerminator.cpp \ + ../base/ReTest.cpp \ + ../math/ReEnigma.cpp \ + ../math/ReMatrix.cpp \ + ../math/ReRandom.cpp \ + ../net/ReNetConfig.cpp \ + ../net/ReTCPClient.cpp \ + ../net/ReTCPPeer.cpp \ + ../net/ReTCPServer.cpp \ + ../expr/ReLexer.cpp \ + ../expr/ReSource.cpp \ + ../base/ReQString.cpp \ + ../expr/ReASTree.cpp \ + ../expr/ReASClasses.cpp \ + ../expr/ReMFParser.cpp \ + ../expr/ReVM.cpp \ + ../expr/ReParser.cpp \ + ../base/ReByteStorage.cpp \ + ../base/ReWriter.cpp \ + ../base/ReCharPtrMap.cpp + +HEADERS += ../remodules.hpp \ + ../base/ReConfig.hpp \ + ../base/ReConfigurator.hpp \ + ../base/ReContainer.hpp \ + ../base/rebase.hpp \ + ../base/ReException.hpp \ + ../base/ReLogger.hpp \ + ../base/ReStringUtil.hpp \ + ../base/ReTerminator.hpp \ + ../base/ReTest.hpp \ + ../math/ReEnigma.hpp \ + ../math/remath.hpp \ + ../math/ReMatrix.hpp \ + ../math/ReRandom.hpp \ + ../net/ReNetConfig.hpp \ + ../net/renet.hpp \ + ../net/ReTCPClient.hpp \ + ../net/ReTCPPeer.hpp \ + ../net/ReTCPServer.hpp \ + ../expr/ReLexer.hpp \ + ../expr/reexpr.hpp \ + ../expr/ReSource.hpp \ + ../base/ReQString.hpp \ + ../expr/ReASTree.hpp \ + ../expr/ReASClasses.hpp \ + ../expr/ReMFParser.hpp \ + ../expr/ReVM.hpp \ + ../expr/ReParser.hpp \ + ../base/ReByteStorage.hpp \ + ../base/ReWriter.hpp \ + ../base/ReCharPtrMap.hpp + +unix:!symbian { + maemo5 { + target.path = /opt/usr/lib + } else { + target.path = /usr/lib + } + INSTALLS += target +} diff --git a/rplstatic/rplstaticlib.cpp b/static/rplstaticlib.cpp similarity index 87% rename from rplstatic/rplstaticlib.cpp rename to static/rplstaticlib.cpp index e4c28bf..dfb4013 100644 --- a/rplstatic/rplstaticlib.cpp +++ b/static/rplstaticlib.cpp @@ -7,7 +7,7 @@ */ -#include "rplstaticlib.hpp" +#include "../static/rplstaticlib.hpp" RplStaticLib::RplStaticLib() diff --git a/rplstatic/rplstaticlib.hpp b/static/rplstaticlib.hpp similarity index 100% rename from rplstatic/rplstaticlib.hpp rename to static/rplstaticlib.hpp diff --git a/unittests/rplastree_test.cpp b/unittests/rplastree_test.cpp deleted file mode 100644 index 7ace6e3..0000000 --- a/unittests/rplastree_test.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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. -*/ - -/** @file - * @brief Unit test of the abstract syntax tree. - */ - - -#include "rplcore/rplcore.hpp" -#include "rplexpr/rplexpr.hpp" -#include "rplcore/rpltest.hpp" - -class TestRplASTree : public RplTest{ -private: - RplSource m_source; - RplStringReader m_reader; - RplStringSourceUnit m_unit; - RplASTree m_tree; -public: - TestRplASTree() : - RplTest("RplASTree"), - m_source(), - m_reader(m_source), - m_unit("
", "", &m_reader), - m_tree() - {} -public: - void testRplASException() { - try{ - m_reader.addSource("
", "12"); - m_source.addReader(&m_reader); - m_source.addSourceUnit(m_reader.currentSourceUnit()); - const RplSourcePosition* pos = m_source.newPosition(2); - throw RplASException(pos, "simple string: %s", "Hi"); - checkF(true); - } catch (RplASException exc){ - checkE("
:0:2: simple string: Hi", exc.getMessage().constData()); - } - } - void testRplASVariant(){ - RplASVariant val1; - val1.setFloat(2.5E-2); - checkE(2.5E-2, val1.asFloat()); - RplASVariant val2(val1); - checkE(2.5E-2, val2.asFloat()); - - val1.setInt(4321); - checkE(4321, val1.asInt()); - val2 = val1; - checkE(4321, val2.asInt()); - - val1.setBool(false); - checkF(val1.asBool()); - val2 = val1; - checkF(val2.asBool()); - - val1.setBool(true); - checkT(val1.asBool()); - val2 = val1; - checkT(val2.asBool()); - - val1.setString("High noon!"); - checkE("High noon!", *val1.asString()); - val2 = val1; - val1.setString("Bye"); - checkE("High noon!", *val2.asString()); - RplASVariant val3(val1); - checkE("Bye", *val3.asString()); - } - void testRplASConstant(){ - RplASConstant constant; - //constant.value().setString("Jonny"); - RplASVariant value; - //constant.calc(value); - //checkE("Jonny", *value.asString()); - } - void testRplASNamedValue(){ - RplASNamedValue value(NULL, m_tree.symbolSpaces()[0], "gugo", - RplASNamedValue::A_GLOBAL); - checkE("gugo", value.name()); - } - virtual void doIt() { - testRplASNamedValue(); - testRplASConstant(); - testRplASException(); - testRplASVariant(); - } -}; -void testRplASTree() { - TestRplASTree test; - test.run(); -} - - - - - - diff --git a/unittests/rplqstring_test.cpp b/unittests/rplqstring_test.cpp deleted file mode 100644 index bdadd09..0000000 --- a/unittests/rplqstring_test.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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. -*/ -/** @file - * @brief Unit test of the QString tools. - */ - -#include "rplcore/rplcore.hpp" -#include "rplcore/rpltest.hpp" - -class TestRplQString : public RplTest { -public: - TestRplQString() : - RplTest("RplQString") - {} - -public: - void testLengthOfUInt64(){ - quint64 value = -3; - checkE(1, RplQString::lengthOfUInt64(QString("0"), 0, 10, &value)); - checkE(0LL, value); - checkE(3, RplQString::lengthOfUInt64("x432", 1, 10, &value)); - checkE(432LL, value); - checkE(3, RplQString::lengthOfUInt64("x432 x", 1, 10, &value)); - checkE(432LL, value); - checkE(3, RplQString::lengthOfUInt64("x432fabc x", 1, 10, &value)); - checkE(432LL, value); - checkE(16, RplQString::lengthOfUInt64("a1234567890123567", 1, 10, &value)); - checkE(1234567890123567LL, value); - checkE(10, RplQString::lengthOfUInt64("x1234abcdef", 1, 16, &value)); - checkE(0x1234abcdefLL, value); - checkE(3, RplQString::lengthOfUInt64("432", 0, 8, &value)); - checkE(0432LL, value); - checkE(6, RplQString::lengthOfUInt64(" 765432 ", 1, 8, &value)); - checkE(0765432LL, value); - - checkE(0, RplQString::lengthOfUInt64("1 ", 1, 8, &value)); - checkE(0, RplQString::lengthOfUInt64("", 1, 8, &value)); - } - void testLengthOfUInt(){ - uint value = 3; - checkE(1, RplQString::lengthOfUInt(QString("0"), 0, 10, &value)); - checkE(0, value); - checkE(3, RplQString::lengthOfUInt("x432", 1, 10, &value)); - checkE(432, value); - checkE(3, RplQString::lengthOfUInt("x432 x", 1, 10, &value)); - checkE(432, value); - checkE(3, RplQString::lengthOfUInt("x432fabc x", 1, 10, &value)); - checkE(432, value); - checkE(3, RplQString::lengthOfUInt("432", 0, 8, &value)); - checkE(0432, value); - checkE(6, RplQString::lengthOfUInt(" 765432 ", 1, 8, &value)); - checkE(0765432, value); - - checkE(0, RplQString::lengthOfUInt("1 ", 1, 8, &value)); - checkE(0, RplQString::lengthOfUInt("", 1, 8, &value)); - } - void testLengthOfReal(){ - qreal value; - checkE(4, RplQString::lengthOfReal(QString("0.25"), 0, &value)); - checkE(0.25, value); - checkE(3, RplQString::lengthOfReal(QString("X.25"), 1, &value)); - checkE(0.25, value); - checkE(1, RplQString::lengthOfReal(QString(" 0"), 1, &value)); - checkE(0.0, value); - checkE(17, RplQString::lengthOfReal(QString("X12345678901234567"), 1, &value)); - checkE(12345678901234567.0, value); - checkE(2, RplQString::lengthOfReal(QString(".5"), 0, &value)); - checkE(0.5, value); - checkE(5, RplQString::lengthOfReal(QString("2.5e2x"), 0, &value)); - checkE(250.0, value); - checkE(6, RplQString::lengthOfReal(QString("2.5e+2"), 0, &value)); - checkE(250.0, value); - checkE(7, RplQString::lengthOfReal(QString("2.5E-33"), 0, &value)); - checkE(2.5e-33, value); - - checkE(3, RplQString::lengthOfReal(QString("2.5E"), 0, &value)); - checkE(2.5, value); - checkE(3, RplQString::lengthOfReal(QString("2.5E+"), 0, &value)); - checkE(2.5, value); - checkE(3, RplQString::lengthOfReal(QString("2.5E-a"), 0, &value)); - checkE(2.5, value); - } - - void testValueOfHexDigit(){ - checkE(0, RplQString::valueOfHexDigit('0')); - checkE(9, RplQString::valueOfHexDigit('9')); - checkE(10, RplQString::valueOfHexDigit('a')); - checkE(15, RplQString::valueOfHexDigit('f')); - checkE(10, RplQString::valueOfHexDigit('A')); - checkE(15, RplQString::valueOfHexDigit('F')); - - checkE(-1, RplQString::valueOfHexDigit('0' - 1)); - checkE(-1, RplQString::valueOfHexDigit('9' + 1)); - checkE(-1, RplQString::valueOfHexDigit('A' - 1)); - checkE(-1, RplQString::valueOfHexDigit('F' + 1)); - checkE(-1, RplQString::valueOfHexDigit('a' - 1)); - checkE(-1, RplQString::valueOfHexDigit('f' + 1)); - } - void testUtf8(){ - QString name = "Heinz Müller"; - char buffer[32]; - checkE("Heinz Müller", RplQString::utf8(name, buffer, sizeof buffer)); - memset(buffer, 'x', sizeof buffer); - checkE("Heinz", RplQString::utf8(name, buffer, (size_t) (5+1))); - checkE(buffer[6], 'x'); - } - - virtual void doIt(void) { - testUtf8(); - testLengthOfUInt64(); - testLengthOfUInt(); - testLengthOfReal(); - testValueOfHexDigit(); - } -}; -void testRplQString() { - TestRplQString test; - test.run(); -} - diff --git a/unittests/rplstring_test.cpp b/unittests/rplstring_test.cpp deleted file mode 100644 index 8983dc0..0000000 --- a/unittests/rplstring_test.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * 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. -*/ - -/** @file - * @brief Unit test of the QByteArray tools. - */ -#include "rplcore/rplcore.hpp" -#include "rplcore/rpltest.hpp" -/** - * @brief Unit test for RplString. - */ -class TestRplString : public RplTest { -public: - TestRplString() : RplTest("RplString") {} - -public: - void testCountChar(){ - checkE(1, RplString::countChar("x", 'x')); - checkE(0, RplString::countChar("X", 'x')); - checkE(2, RplString::countChar("xbxxbxx", 'b')); - } - - void testCount() { - checkE(0, RplString::count("abc", " ")); - checkE(1, RplString::count("abc", "b")); - checkE(2, RplString::count("axx", "x")); - - checkE(0, RplString::count("abbc", "bbb")); - checkE(1, RplString::count("\n\n", "\n\n")); - checkE(2, RplString::count(" a ", " ")); - } - - void testCutString() { - QByteArray source("123"); - QByteArray buffer; - checkE(QByteArray("123"), RplString::cutString(source, 4, buffer)); - checkE(QByteArray("123"), RplString::cutString(source, 3, buffer)); - checkE(QByteArray("12..."), RplString::cutString(source, 2, buffer)); - checkE(QByteArray("12"), RplString::cutString(source, 2, buffer, "")); - } - - void testHexDump() { - QByteArray data("abc123\nxyz"); - checkE(QByteArray("61 62 63 31 abc1\n" - "32 33 0a 78 23.x\n" - "79 7a yz\n"), - RplString::hexDump((uint8_t*) data.constData(), data.length(), 4)); - checkE(QByteArray("61 62 63 31 32 33 0a 78 79 7a abc123.xyz"), - RplString::hexDump((uint8_t*) data.constData(), data.length(), 10)); - checkE(QByteArray("61 62 63 31 32 33 0a 78 79 7a abc123.xyz"), - RplString::hexDump((uint8_t*) data.constData(), data.length(), 12)); - } - - void testReadWrite() { - QByteArray fn = getTempFile("test.dat"); - const char* content = "Hello world\nLine2\n"; - checkT(RplString::write(fn, content)); - checkE(content, RplString::read(fn, false)); - checkE(content, RplString::read(fn, true) + "\n"); - } - - void testToArray() { - QList array = RplString::toArray("1 abc 3", " "); - checkE(3, array.size()); - checkE("1", array.at(0)); - checkE("abc", array.at(1)); - checkE("3", array.at(2)); - } - - void testToNumber() { - checkE("3", RplString::toNumber(3)); - checkE("-33", RplString::toNumber(-33)); - checkE("003", RplString::toNumber(3, "%03d")); - } - - void testLengthOfNumber(){ - checkE(3, RplString::lengthOfNumber("0.3xxx")); - checkE(5, RplString::lengthOfNumber(" \t0.3xxx")); - checkE(3, RplString::lengthOfNumber("-.3xxx")); - checkE(2, RplString::lengthOfNumber(".3exxx")); - checkE(2, RplString::lengthOfNumber(".3e+xxx")); - checkE(16, RplString::lengthOfNumber("1234567.9012E+77")); - checkE(17, RplString::lengthOfNumber("-1234567.9012E+77 ")); - checkE(18, RplString::lengthOfNumber("-1234567.9012E+77 ", true)); - checkE(18, RplString::lengthOfNumber("-1234567.9012E+77 x", true)); - checkE(20, RplString::lengthOfNumber(" -1234567.9012E+77 x", true)); - } - - void checkCsv(const char* content, char expected){ - QByteArray fn = getTempFile("testrplstring.csv"); - RplString::write(fn, content); - FILE* fp = fopen(fn, "r"); - checkNN(fp); - char buffer[256]; - checkE(expected, RplString::findCsvSeparator(fp, buffer, sizeof buffer)); - fclose(fp); - } - - void testFindCsvSeparator(){ - const char* content = ",,,\t;;;||||"; - checkCsv(content, '\t'); - - content = "col1,col2\n1.5,3,5\n"; - checkCsv(content, ','); - - content = "col1;col2\n1,50;3.5\n" - "7;8\n10;12\n13;14"; - checkCsv(content, ';'); - - content = "0.3 7.8 8.9\n7.8 9.4 8.3"; - checkCsv(content, ' '); - - content = "0.3|7.8|8.9\n7.8| 9.4|8.3"; - checkCsv(content, '|'); - - content = "0,3;7.8;8.9"; - checkCsv(content, ';'); - } - void testLengthOfUInt64(){ - quint64 value = -3; - checkE(1, RplString::lengthOfUInt64("0", 10, &value)); - checkE(0LL, value); - checkE(3, RplString::lengthOfUInt64("432", 10, &value)); - checkE(432LL, value); - checkE(3, RplString::lengthOfUInt64("432 x", 10, &value)); - checkE(432LL, value); - checkE(3, RplString::lengthOfUInt64("432fabc x", 10, &value)); - checkE(432LL, value); - checkE(16, RplString::lengthOfUInt64("1234567890123567", 10, &value)); - checkE(1234567890123567LL, value); - checkE(10, RplString::lengthOfUInt64("1234abcdef", 16, &value)); - checkE(0x1234abcdefLL, value); - checkE(3, RplString::lengthOfUInt64("432", 8, &value)); - checkE(0432LL, value); - checkE(6, RplString::lengthOfUInt64("765432 ", 8, &value)); - checkE(0765432LL, value); - - checkE(0, RplString::lengthOfUInt64(" ", 8, &value)); - checkE(0, RplString::lengthOfUInt64("", 8, &value)); - } - void testLengthOfReal(){ - qreal value; - checkE(1, RplString::lengthOfReal("0", &value)); - checkE(0.0, value); - checkE(1, RplString::lengthOfReal("0%", &value)); - checkE(0.0, value); - checkE(4, RplString::lengthOfReal("0.25", &value)); - checkE(0.25, value); - checkE(3, RplString::lengthOfReal(".25", &value)); - checkE(0.25, value); - checkE(17, RplString::lengthOfReal("12345678901234567", &value)); - checkE(12345678901234567.0, value); - checkE(2, RplString::lengthOfReal(".5", &value)); - checkE(0.5, value); - checkE(5, RplString::lengthOfReal("2.5e2x", &value)); - checkE(250.0, value); - checkE(6, RplString::lengthOfReal("2.5e+2", &value)); - checkE(250.0, value); - checkE(7, RplString::lengthOfReal("2.5E-33", &value)); - checkE(2.5e-33, value); - - checkE(3, RplString::lengthOfReal("2.5E", &value)); - checkE(2.5, value); - checkE(3, RplString::lengthOfReal("2.5E+", &value)); - checkE(2.5, value); - checkE(3, RplString::lengthOfReal("2.5E-a", &value)); - checkE(2.5, value); - } - - virtual void doIt() { - testLengthOfReal(); - testLengthOfUInt64(); - testCountChar(); - testCount(); - testCutString(); - testToNumber(); - testToArray(); - testHexDump(); - testReadWrite(); - testLengthOfNumber(); - testFindCsvSeparator(); - } -}; - -void testRplString() { - TestRplString test; - test.run(); -} - - - -- 2.39.5