Skip to content

Commit 7346d07

Browse files
committed
FEATURE: plane: hasExpr is improved and almost works
This new feature works on unit tests. I'm not sure there are no memory leak or dead locks for now.
1 parent 16bd274 commit 7346d07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+386
-426
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ BraceWrapping: {
5959
BeforeElse : 'true'
6060
IndentBraces : 'false'
6161
}
62+
SortIncludes: 'false'
6263
...
6364

CMakeLists.txt

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ OPTION(COVERAGE "Set this variable to ON to check coverage of tests" OFF)
88
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeScripts)
99

1010
FIND_PACKAGE(Readline REQUIRED)
11-
FIND_PACKAGE(CPPUNIT REQUIRED)
1211
FIND_PACKAGE(Lua REQUIRED)
12+
FIND_PACKAGE(RE2C REQUIRED)
13+
14+
IF (LUA_VERSION_MAJOR STREQUAL "5" AND LUA_VERSION_MINOR STREQUAL "1")
15+
MESSAGE("LUA 51")
16+
ADD_DEFINITIONS(-DLUA51)
17+
ENDIF()
1318

1419
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} elements parser stack bool
1520
${Readline_INCLUDE_DIR} ${LUA_INCLUDE_DIR} tasks)
@@ -35,7 +40,6 @@ ADD_SUBDIRECTORY(bool)
3540
ADD_SUBDIRECTORY(lemon)
3641
ADD_SUBDIRECTORY(parser)
3742
ADD_SUBDIRECTORY(elements)
38-
ADD_SUBDIRECTORY(tests)
3943
ADD_SUBDIRECTORY(stack)
4044
ADD_SUBDIRECTORY(tasks)
4145
#ADD_SUBDIRECTORY(rules)
@@ -54,5 +58,8 @@ TARGET_LINK_LIBRARIES(drpythagore bool elements parser stack
5458
${Readline_LIBRARY} ${LUA_LIBRARIES})
5559

5660
ENABLE_TESTING()
61+
FIND_PACKAGE(GTest REQUIRED)
62+
63+
ADD_SUBDIRECTORY(tests)
5764

58-
ADD_TEST(basic tests/test-dr-pythagore)
65+
ADD_TEST(tests tests/test-dr-pythagore)

CMakeScripts/FindRE2C.cmake

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# - Find re2c executable and provides macros to generate custom build rules
2+
# The module defines the following variables:
3+
#
4+
# RE2C_EXECUTABLE - path to the bison program
5+
# RE2C_VERSION - version of bison
6+
# RE2C_FOUND - true if the program was found
7+
#
8+
find_program(RE2C_EXECUTABLE NAMES re2c DOC "path to re2c executable")
9+
mark_as_advanced(RE2C_EXECUTABLE)
10+
11+
if(RE2C_EXECUTABLE)
12+
13+
execute_process(COMMAND ${RE2C_EXECUTABLE} --vernum
14+
RESULT_VARIABLE RE2C_version_result
15+
OUTPUT_VARIABLE RE2C_version_output
16+
ERROR_VARIABLE RE2C_version_error
17+
OUTPUT_STRIP_TRAILING_WHITESPACE)
18+
19+
set(RE2C_VERSION ${RE2C_version_output})
20+
21+
macro(RE2C_TARGET Re2cInput Re2cOutput Args)
22+
set(RE2C_EXECUTABLE_opts ${Args})
23+
24+
ADD_CUSTOM_COMMAND(OUTPUT ${Re2cOutput}
25+
COMMAND ${RE2C_EXECUTABLE}
26+
ARGS ${RE2C_EXECUTABLE_opts} -o ${Re2cOutput} ${Re2cInput}
27+
DEPENDS ${Re2cInput}
28+
COMMENT "[RE2C] Building re2c scanner with re2c ${RE2C_VERSION}"
29+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
30+
31+
endmacro(RE2C_TARGET)
32+
endif(RE2C_EXECUTABLE)
33+
34+
include(FindPackageHandleStandardArgs)
35+
find_package_handle_standard_args(RE2C DEFAULT_MSG RE2C_EXECUTABLE)

bool/andBoolExpr.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <sstream>
12
#include <iostream>
23
#include "andBoolExpr.h"
34

@@ -12,16 +13,20 @@ AndBoolExpr::AndBoolExpr(BoolExpr *a, BoolExpr *b, const string &descr)
1213

1314
bool AndBoolExpr::operator()() const
1415
{
16+
cout << "Evaluation of And..." << endl;
17+
cout << "Table: " << getString() << endl;
1518
for (BoolExpr *e : *this) {
1619
if (!(*e)())
1720
return false;
1821
}
1922
return true;
2023
}
2124

22-
string AndBoolExpr::getString()
25+
string AndBoolExpr::getString() const
2326
{
24-
cout << '(' << at(0)->getString() << ") And (" << at(1)->getString() << ')';
27+
stringstream ss;
28+
ss << '(' << at(0)->getString() << ") And (" << at(1)->getString() << ')';
29+
return ss.str();
2530
}
2631

2732
bool AndBoolExpr::fillResult(BoolTable &table, unsigned long input)

bool/andBoolExpr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class AndBoolExpr : public TreeBoolExpr
88
public:
99
AndBoolExpr(BoolExpr *a, BoolExpr *b, const std::string &descr = "");
1010
virtual bool operator() () const;
11-
virtual std::string getString();
11+
virtual std::string getString() const;
1212
virtual bool fillResult(BoolTable &table, unsigned long input);
1313
};
1414
}

bool/boolExpr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BoolExpr
1818
public:
1919
BoolExpr(const std::string &op, const std::string &descr);
2020
virtual bool operator() () const;
21-
virtual std::string getString() = 0;
21+
virtual std::string getString() const = 0;
2222
const std::string &getDescr() const;
2323
const std::string &getOp() const;
2424
void solve(BoolTable &table);

bool/boolTable.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <iostream>
12
#include <cassert>
23
#include <bitset>
34
#include <sstream>
@@ -14,6 +15,11 @@ BoolTable::BoolTable()
1415

1516
void BoolTable::addArg(SimpleExpr *expr)
1617
{
18+
for (SimpleExpr *e : _args) {
19+
if (*e == *expr) {
20+
return;
21+
}
22+
}
1723
_args.push_back(expr);
1824
}
1925

@@ -49,18 +55,26 @@ string BoolTable::getString()
4955
return ss.str();
5056
}
5157

52-
size_t BoolTable::findArgsIndex(BoolExpr *expr)
58+
size_t BoolTable::findArgsIndex(SimpleExpr *expr)
5359
{
5460
size_t i;
5561
for (i = 0; i < _args.size(); i++) {
56-
if (expr == _args[i])
62+
if (*expr == *(_args[i]))
5763
return i;
5864
}
5965
assert(1 == 0);
60-
return 0; // Should not arrive
66+
return 0; // Should not arrive
6167
}
6268

6369
void BoolTable::setResult(std::vector<bool> &result)
6470
{
6571
_result = result;
6672
}
73+
74+
bool BoolTable::isTrue() const
75+
{
76+
for (bool b : _result)
77+
if (!b)
78+
return false;
79+
return true;
80+
}

bool/boolTable.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class BoolTable
2121
size_t countArgs() const;
2222
std::list<std::vector<bool> > &getArray();
2323
std::string getString();
24-
size_t findArgsIndex(BoolExpr *expr);
24+
size_t findArgsIndex(SimpleExpr *expr);
2525
void setResult(std::vector<bool> &result);
26+
bool isTrue() const;
2627
};
2728
}
2829
#endif /* __BOOL_TABLE_H__ */

bool/notBoolExpr.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <sstream>
12
#include <iostream>
23
#include "notBoolExpr.h"
34

@@ -14,9 +15,11 @@ bool NotBoolExpr::operator()() const
1415
return !(*at(0))();
1516
}
1617

17-
string NotBoolExpr::getString()
18+
string NotBoolExpr::getString() const
1819
{
19-
cout << "Not (" << at(0)->getString() << ')';
20+
stringstream ss;
21+
ss << "Not (" << at(0)->getString() << ')';
22+
return ss.str();
2023
}
2124

2225
bool NotBoolExpr::fillResult(BoolTable &table, unsigned long input)

bool/notBoolExpr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class NotBoolExpr : public TreeBoolExpr
99
public:
1010
NotBoolExpr(BoolExpr *a, const std::string &descr = "");
1111
virtual bool operator() () const;
12-
virtual std::string getString();
12+
virtual std::string getString() const;
1313
virtual bool fillResult(BoolTable &table, unsigned long input);
1414
};
1515

bool/orBoolExpr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bool OrBoolExpr::operator()() const
2323
return false;
2424
}
2525

26-
string OrBoolExpr::getString()
26+
string OrBoolExpr::getString() const
2727
{
2828
stringstream ss;
2929
ss << '(' << at(0)->getString() << ") Or (" << at(1)->getString() << ')';

bool/orBoolExpr.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class OrBoolExpr : public TreeBoolExpr
1111
public:
1212
OrBoolExpr(BoolExpr *a, BoolExpr *b, const std::string &descr = "");
1313
virtual bool operator() () const;
14-
virtual std::string getString();
14+
virtual std::string getString() const;
1515
virtual bool fillResult(BoolTable &table, unsigned long int input);
1616
};
1717
}

bool/simpleExpr.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include "simpleExpr.h"
2-
#include "boolTable.h"
3-
#include "element.h"
1+
#include <iostream>
42
#include <list>
53
#include <sstream>
64
#include <string>
5+
#include "simpleExpr.h"
6+
#include "boolTable.h"
7+
#include "element.h"
78

89
using namespace std;
910
using namespace DP;
@@ -37,11 +38,11 @@ DP::SimpleExpr::SimpleExpr(const string &op, Element *a, Element *b, Element *c,
3738
at(2) = c;
3839
}
3940

40-
string DP::SimpleExpr::getString()
41+
string DP::SimpleExpr::getString() const
4142
{
4243
stringstream ss;
4344
ss << _op << '(';
44-
vector::iterator it = begin();
45+
vector::const_iterator it = begin();
4546
if (it != end()) {
4647
ss << (*it)->getName();
4748

@@ -58,6 +59,21 @@ void SimpleExpr::findArgs(BoolTable &table)
5859
table.addArg(this);
5960
}
6061

62+
bool SimpleExpr::operator==(const SimpleExpr &other)
63+
{
64+
if (this == &other)
65+
return true;
66+
if (getOp() != other.getOp())
67+
return false;
68+
if (size() != other.size())
69+
return false;
70+
for (uint32_t i = 0; i < size(); i++) {
71+
if (!(*(at(i)) == *(other[i])))
72+
return false;
73+
}
74+
return true;
75+
}
76+
6177
bool SimpleExpr::fillResult(BoolTable &table, unsigned long int input)
6278
{
6379
int idx = table.findArgsIndex(this);

bool/simpleExpr.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef _SIMPLE_EXPR_H_
22
#define _SIMPLE_EXPR_H_
3-
#include "boolExpr.h"
43
#include <deque>
54
#include <vector>
5+
#include "boolExpr.h"
66

77
namespace DP {
88

@@ -12,16 +12,16 @@ class BoolTable;
1212
class SimpleExpr : public BoolExpr, public std::vector<Element *>
1313
{
1414
protected:
15-
1615
public:
17-
SimpleExpr(const std::string &op, const std::string &descr);
18-
SimpleExpr(const std::string &op, Element *a, const std::string &descr);
19-
SimpleExpr(const std::string &op, Element *a, Element *b, const std::string &descr);
20-
SimpleExpr(const std::string &op, Element *a, Element *b, Element *c, const std::string &descr);
16+
SimpleExpr(const std::string &op, const std::string &descr = "");
17+
SimpleExpr(const std::string &op, Element *a, const std::string &descr = "");
18+
SimpleExpr(const std::string &op, Element *a, Element *b, const std::string &descr = "");
19+
SimpleExpr(const std::string &op, Element *a, Element *b, Element *c, const std::string &descr = "");
2120

22-
virtual std::string getString();
21+
virtual std::string getString() const;
2322
virtual bool fillResult(BoolTable &table, unsigned long input);
2423
virtual void findArgs(BoolTable &table);
24+
bool operator==(const SimpleExpr &other);
2525
};
2626
}
2727
#endif // _SIMPLE_EXPR_H_

bool/tree.cpp

-11
This file was deleted.

bool/tree.h

-36
This file was deleted.

0 commit comments

Comments
 (0)