$loops = 200 unless $loops;
print "count: $count loops: $loops\n";
-if ($lang =~ /^py/i){
+if ($lang =~ /^all/i){
+ &pyAssign;
+ &cppAssign;
+ &javaAssign;
+ &plAssign;
+ &mfAssign;
+} elsif ($lang =~ /^py/i){
&pyAssign;
} elsif ($lang =~ /^j/i){
&javaAssign;
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+
+#include "rplcore/rplcore.hpp"
+
+/** @class RplKeyCharPtr rplcharptrmap.hpp "rplcore/rplcharptrmap.hpp"
+ *
+ * @brief Allows using <code>char*</code> pointers as key in <code>QMap</code>.
+ *
+ * The template <code>QMap</code> uses the operator < to search in the map.
+ * But the <code>char*</code> pointers have no such an operator.
+ * The solution is the class <code>RplMapCharPtr</code> which implements
+ * this operator.
+ *
+ * <code>strcmp()</code> is used to implement the '<' operator.
+ */
+
+/**
+ * @brief Constructor.
+ *
+ * @param ptr the key used in the map.
+ */
+RplKeyCharPtr::RplKeyCharPtr(const char* ptr) :
+ m_ptr(ptr)
+{
+}
+
+
+/** @class RplCharPtrMap rplcharptrmap.hpp "rplcore/rplcharptrmap.hpp"
+ *
+ * @brief A template for a map using const char* as keys.
+ *
+ * The value type is dynamic (a parameter type of the template).
+ *
+ * <b>Usage:</b>
+ * <pre><code>
+ * RplCharPtrMap<int> ids;
+ * if (! id.contains("jonny"))
+ * ids["jonny"] = 1;
+ * </code></pre>
+ *
+ * <b>Important</b>:<br>
+ * Keys used with this class must be unchangable and must live during the
+ * whole life of the map.
+ *
+ * <b>Wrong example:</b>
+ * <pre><code>
+ * RplCharPtrMap<int> ids;
+ * void init(int keyNo, int value){
+ * char key[10];
+ * qsnprintf(buffer, sizeof buffer, "key%d", keyNo);
+ * ids[key] = value;
+ * }
+ * init(1, 100);
+ * </code></pre>
+ * The lifetime of the key is the body of the function <code>init()</code>.
+ * The key becomes invalid after the call.
+ */
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+
+#ifndef RPLCHARPTRMAP_HPP
+#define RPLCHARPTRMAP_HPP
+
+class RplKeyCharPtr {
+ friend bool operator <(RplKeyCharPtr const& op1, RplKeyCharPtr const& op2);
+public:
+ RplKeyCharPtr(const char* ptr);
+private:
+ const char* m_ptr;
+};
+/**
+ * @brief Compares two instances of the class <code>RplKeyCharPtr</code>.
+ * @param op1 1st operand
+ * @param op2 2nd operand
+ * @return true: op1 < op2<br>
+ * false: op1 >= op2
+ */
+inline bool operator <(RplKeyCharPtr const& op1, RplKeyCharPtr const& op2){
+ bool rc = strcmp(op1.m_ptr, op2.m_ptr) < 0;
+ return rc;
+}
+
+template <class ValueType>
+class RplCharPtrMap : public QMap<RplKeyCharPtr, ValueType>
+{
+};
+
+#endif // RPLCHARPTRMAP_HPP
#include "rplmodules.hpp"
#include "rplcore/rplbytestorage.hpp"
+#include "rplcore/rplcharptrmap.hpp"
#include "rplcore/rplwriter.hpp"
#include "rplcore/rpllogger.hpp"
#include "rplcore/rplexception.hpp"
*
* Finishes the "live" of the variables created in the ending scope.
*
- * @param scope the status of the scope at start.
+ * @param endOfScope line (inside the current source unit) which finishes the
+ * scope
+ * @param scope the status of the scope at start.
*/
void RplSymbolSpace::finishScope(int endOfScope, RplASScope& scope)
{
const char* format, va_list varList)
{
char buffer[64000];
- if (position != NULL)
+ if (position != NULL){
m_message = position->toString().toUtf8();
+ m_message += ": ";
+ }
qvsnprintf(buffer, sizeof buffer, format, varList);
m_message += buffer;
}
*
* @param dataType the data type (class)
* @param name the name of the variable
+ * @param space the current symbol space
* @param attributes the attributes of the variable
*/
RplASNamedValue::RplASNamedValue(RplASClass* dataType,RplSymbolSpace* space,
char buffer[256];
printf("token: %s pos: %s\n", m_currentToken->dump().constData(),
m_currentPosition->utf8(buffer, sizeof buffer));
- if (strcmp(buffer, "<test>:2:6") == 0)
+ if (strstr(buffer, "0:28") != NULL)
buffer[0] = 0;
}
#endif
#ifndef RPLLEXER_HPP
#define RPLLEXER_HPP
+//#define RPL_LEXER_TRACE
enum RplTokenType {
TOKEN_UNDEF,
bool isRightAssociative(int op) const;
const RplSourcePosition* currentPosition() const;
RplToken* currentToken() const;
+#if defined RPL_LEXER_TRACE
bool trace() const;
void setTrace(bool trace);
-
+#endif
private:
void prepareOperators(const char* operators, const char* rightAssociatives);
void initializeComments(const char* comments);
char m_prioOfOp[128];
char m_assocOfOp[128];
QList<QByteArray> m_opNames;
-//#define RPL_LEXER_TRACE
#if defined (RPL_LEXER_TRACE)
bool m_trace;
#endif
/**
* @brief Sets the current source unit.
*
- * @param sourceUnit the name of the new source unit
+ * @param sourceUnit the name of the new source unit
+ * @return true: source unit exists<br>
+ * false: source unit not found
*/
-bool RplReader::setCurrentSourceUnit(RplSourceUnitName sourceUnit) {
+bool RplReader::setCurrentSourceUnit(RplSourceUnitName& sourceUnit) {
bool rc = m_units.contains(sourceUnit);
if(rc) {
m_currentSourceUnit = m_units.value(sourceUnit);
if(! rc) {
m_source.popSourceUnit(this);
} else {
+ m_currentSourceUnit->setLineNo(m_currentSourceUnit->lineNo() + 1);
+ unit->m_currentPosition = 0;
unit->m_line = unit->m_textStream.readLine();
rc = fillBuffer(maxSize, buffer, hasMore);
}
/**
* @brief Adds a source file to the reader
*
- * @param dirEntry the file
+ * @param filename the file' name (relative or absolute)
*/
void RplFileReader::addSource(RplSourceUnitName filename) {
// Deleting in ~RplSourceUnit():
virtual void clear();
RplSource& source();
RplSourceUnit* currentSourceUnit() const;
- bool setCurrentSourceUnit(RplSourceUnitName currentSourceUnit);
+ bool setCurrentSourceUnit(RplSourceUnitName& currentSourceUnit);
protected:
void removeSourceUnit();
../rplexpr/rplvm.cpp \
../rplexpr/rplparser.cpp \
../rplcore/rplbytestorage.cpp \
- ../rplcore/rplwriter.cpp
+ ../rplcore/rplwriter.cpp \
+ ../rplcore/rplcharptrmap.cpp
HEADERS += ../rplmodules.hpp \
../rplcore/rplconfig.hpp \
../rplexpr/rplvm.hpp \
../rplexpr/rplparser.hpp \
../rplcore/rplbytestorage.hpp \
- ../rplcore/rplwriter.hpp
+ ../rplcore/rplwriter.hpp \
+ ../rplcore/rplcharptrmap.hpp
unix:!symbian {
maemo5 {
#include <QCoreApplication>
void testCore(){
+ extern void testRplCharPtrMap();
+ testRplCharPtrMap();
+
extern void testRplWriter();
testRplWriter();
}
void testExpr(){
+ extern void testRplSource();
+ testRplSource();
extern void testRplBenchmark();
- testRplBenchmark();
+ //testRplBenchmark();
extern void testRplVM();
- testRplVM();
+ //testRplVM();
extern void testRplMFParser();
testRplMFParser();
extern void testRplASTree();
testRplASTree();
- extern void testRplSource();
- testRplSource();
extern void testRplLexer();
testRplLexer();
}
void testStandard(){
- testExpr();
+ //testExpr();
testCore();
extern void testRplMatrix();
testRplMatrix();
}
+void labor(){
+}
+
int main(int argc, char *argv[])
{
+ //labor();
if (argc > 1)
printf("not used: %s\n", argv[1]);
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#include "rplcore/rplcore.hpp"
+#include "rplcore/rpltest.hpp"
+
+class TestRplCharPtrMap : public RplTest{
+public:
+ TestRplCharPtrMap() :
+ RplTest("RplCharPtrMap")
+ {
+ }
+protected:
+ void testBasic(){
+ RplCharPtrMap<const char*> map;
+ map["x"] = "x1";
+ checkT(map.contains("x"));
+ checkF(map.contains("y"));
+ checkE("x1", map["x"]);
+ }
+
+ virtual void doIt(void) {
+ testBasic();
+ }
+};
+void testRplCharPtrMap() {
+ TestRplCharPtrMap test;
+ test.run();
+}
}
public:
void baseTest(){
- setSource("Int a=2+3*4");
+ setSource("Int a=2+3*4;");
checkAST("baseTest.txt", __LINE__);
}
virtual void doIt(void) {
rplvm_test.cpp \
rplbytestorage_test.cpp \
rplwriter_test.cpp \
- rplbench.cpp
+ rplbench.cpp \
+ rplcharptrmap_test.cpp