summaryrefslogtreecommitdiff
path: root/impl
diff options
context:
space:
mode:
Diffstat (limited to 'impl')
-rw-r--r--impl/Complete.hpp5
-rw-r--r--impl/EquationSystem.hpp13
-rw-r--r--impl/Expression.hpp8
-rw-r--r--impl/IdMap.hpp9
-rw-r--r--impl/Log.hpp1
-rw-r--r--impl/Makefile2
-rw-r--r--impl/MaxStrategy.hpp31
-rw-r--r--impl/Operator.hpp6
-rw-r--r--impl/VariableAssignment.hpp12
-rw-r--r--impl/gmon.outbin0 -> 82849 bytes
-rw-r--r--impl/main.cpp19
-rw-r--r--impl/systems/10
-rw-r--r--impl/systems/gmon.outbin0 -> 82405 bytes
-rw-r--r--impl/systems/test.eqns4
14 files changed, 64 insertions, 46 deletions
diff --git a/impl/Complete.hpp b/impl/Complete.hpp
index 81ced52..8c5559a 100644
--- a/impl/Complete.hpp
+++ b/impl/Complete.hpp
@@ -1,6 +1,7 @@
#ifndef COMPLETE_HPP
#define COMPLETE_HPP
+#include <cassert>
#include <ostream>
#include <istream>
@@ -15,9 +16,7 @@ struct Complete {
: _value(value), _infinity(false) { }
Complete(const T& value, const bool& infinity)
: _value(value), _infinity(infinity) {
- if (value == 0 && infinity == true) {
- throw "Zero infinity? Die die die!";
- }
+ assert(value != 0 || infinity == false);
}
Complete(const Complete& other)
: _value(other._value), _infinity(other._infinity) { }
diff --git a/impl/EquationSystem.hpp b/impl/EquationSystem.hpp
index 4c55bd7..2fd24bd 100644
--- a/impl/EquationSystem.hpp
+++ b/impl/EquationSystem.hpp
@@ -96,15 +96,12 @@ struct EquationSystem {
}
Variable<Domain>* varFromExpr(const Expression<Domain>& expr) const {
- if (_expr_to_var) { // we've indexed:
- auto* maxExpr = dynamic_cast<const MaxExpression<Domain>*>(&expr);
- if (maxExpr) {
- return (*_expr_to_var)[*maxExpr];
- } else {
- return NULL;
- }
+ assert(_expr_to_var); // make sure we've indexed
+ const MaxExpression<Domain>* maxExpr = expr.toMaxExpression();//dynamic_cast<const MaxExpression<Domain>*>(&expr);
+ if (maxExpr) {
+ return (*_expr_to_var)[*maxExpr];
} else {
- throw "Must index max expressions before attempting lookup";
+ return NULL;
}
}
diff --git a/impl/Expression.hpp b/impl/Expression.hpp
index eedaa52..00bc9cd 100644
--- a/impl/Expression.hpp
+++ b/impl/Expression.hpp
@@ -23,6 +23,10 @@ template<typename Domain>
struct Expression {
virtual ~Expression() { }
+ virtual const MaxExpression<Domain>* toMaxExpression() const {
+ return NULL;
+ }
+
virtual Domain eval(const VariableAssignment<Domain>&) const = 0;
virtual Domain eval(const VariableAssignment<Domain>& rho,
const MaxStrategy<Domain>&) const {
@@ -141,6 +145,10 @@ struct MaxExpression : public OperatorExpression<Domain> {
MaxExpression(const unsigned int& id, const Maximum<Domain>& op, const std::vector<Expression<Domain>*>& arguments)
: OperatorExpression<Domain>(op, arguments), _id(id) { }
+ const MaxExpression* toMaxExpression() const {
+ return this;
+ }
+
virtual Domain eval(const VariableAssignment<Domain>& rho, const MaxStrategy<Domain>& strat) const {
return this->_arguments[strat.get(*this)]->eval(rho, strat);
}
diff --git a/impl/IdMap.hpp b/impl/IdMap.hpp
index b265e37..8cb25f8 100644
--- a/impl/IdMap.hpp
+++ b/impl/IdMap.hpp
@@ -1,6 +1,7 @@
#ifndef ID_MAP_HPP
#define ID_MAP_HPP
+#include <cassert>
#include <ostream>
template<typename T, typename V>
@@ -32,15 +33,11 @@ struct IdMap {
return *this;
}
virtual const V& operator[] (const T& x) const {
- if (x.id() >= _length) {
- throw "Array out of bounds";
- }
+ assert(x.id() < _length);
return _assignment[x.id()];
}
virtual V& operator[] (const T& x) {
- if (x.id() >= _length) {
- throw "Array out of bounds";
- }
+ assert(x.id() < _length);
return _assignment[x.id()];
}
diff --git a/impl/Log.hpp b/impl/Log.hpp
index b595105..f7fe6b6 100644
--- a/impl/Log.hpp
+++ b/impl/Log.hpp
@@ -9,6 +9,7 @@
#include <string>
#include <iostream>
#include <map>
+#include <cstdio>
namespace log {
diff --git a/impl/Makefile b/impl/Makefile
index 213657b..6fc6f3b 100644
--- a/impl/Makefile
+++ b/impl/Makefile
@@ -2,7 +2,7 @@ CC=gcc
CPP=g++
BUILD=build
PARSER=parser
-FLAGS=-Wall -Werror -Wextra -pedantic -lantlr3c -std=c++11
+FLAGS=-Wall -Werror -Wextra -pedantic -lantlr3c -fno-exceptions
NORMAL_FLAGS=$(FLAGS) -g -pg
OPTIMISED_FLAGS=$(FLAGS) -O3
diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp
index d15884c..f330f3b 100644
--- a/impl/MaxStrategy.hpp
+++ b/impl/MaxStrategy.hpp
@@ -36,9 +36,9 @@ struct DynamicMaxStrategy : public MaxStrategy<Domain> {
_values(system.maxExpressionCount(), 0),
_stable(system.maxExpressionCount()),
_influence(system.maxExpressionCount(),
- IdSet<MaxExpression<Domain>>(system.maxExpressionCount())),
+ IdSet<MaxExpression<Domain> >(system.maxExpressionCount())),
_var_influence(system.variableCount(),
- IdSet<MaxExpression<Domain>>(system.maxExpressionCount()))
+ IdSet<MaxExpression<Domain> >(system.maxExpressionCount()))
{}
void setRho(DynamicVariableAssignment<Domain>& rho) {
@@ -54,11 +54,14 @@ struct DynamicMaxStrategy : public MaxStrategy<Domain> {
log::strategy << indent() << "Invalidating " << v << " - " << *_system[v] << std::endl;
_stable.filter(_var_influence[v]);
- for (auto it = _var_influence[v].begin();
- it != _var_influence[v].end();
+ for (typename IdSet<MaxExpression<Domain> >::iterator
+ it = _var_influence[v].begin(),
+ end = _var_influence[v].end();
+ it != end;
++it) {
solve(_system.maxExpression(*it));
}
+ _var_influence[v].clear();
}
private:
@@ -75,7 +78,7 @@ private:
if (val != _values[x]) {
log::strategy << x << " => " << *x.arguments()[val] << std::endl;
- auto oldInfluence = _influence[x];
+ IdSet<MaxExpression<Domain> > oldInfluence = _influence[x];
_influence[x].clear();
_values[x] = val;
@@ -83,16 +86,20 @@ private:
_stable.filter(oldInfluence);
- for (auto it = oldInfluence.begin();
- it != oldInfluence.end();
+ for (typename IdSet<MaxExpression<Domain> >::iterator
+ it = oldInfluence.begin(),
+ end = oldInfluence.end();
+ it != end;
++it) {
solve(_system.maxExpression(*it));
}
} else {
- log::strategy << indent() << x << " did not change" << std::endl;
+ log::strategy << indent() << x << " did not change: "
+ << x << " => " << *x.arguments()[val] << std::endl;
}
} else {
- log::strategy << indent() << x << " is stable" << std::endl;
+ log::strategy << indent() << x << " is stable: "
+ << x << " => " << *x.arguments()[_values[x]] << std::endl;
}
}
@@ -135,9 +142,9 @@ private:
const EquationSystem<Domain>& _system;
mutable DynamicVariableAssignment<Domain>* _rho;
mutable IdMap<MaxExpression<Domain>,unsigned int> _values;
- mutable IdSet<MaxExpression<Domain>> _stable;
- mutable IdMap<MaxExpression<Domain>,IdSet<MaxExpression<Domain>>> _influence;
- mutable IdMap<Variable<Domain>,IdSet<MaxExpression<Domain>>> _var_influence;
+ mutable IdSet<MaxExpression<Domain> > _stable;
+ mutable IdMap<MaxExpression<Domain>,IdSet<MaxExpression<Domain> > > _influence;
+ mutable IdMap<Variable<Domain>,IdSet<MaxExpression<Domain> > > _var_influence;
};
/*template<typename Domain>
diff --git a/impl/Operator.hpp b/impl/Operator.hpp
index e8d6ca7..64ef096 100644
--- a/impl/Operator.hpp
+++ b/impl/Operator.hpp
@@ -1,6 +1,7 @@
#ifndef OPERATOR_HPP
#define OPERATOR_HPP
+#include <cassert>
#include <vector>
template<typename Domain>
@@ -47,8 +48,7 @@ struct Minimum : public Operator<Domain> {
template<typename Domain>
struct Negation : public Operator<Domain> {
virtual Domain eval(const std::vector<Domain>& arguments) const {
- if (arguments.size() > 1)
- throw "Too many arguments to a negation.";
+ assert(arguments.size() == 1);
return -arguments[0];
}
void print(std::ostream& cout) const {
@@ -95,7 +95,7 @@ template<typename Domain>
struct Multiplication : public Operator<Domain> {
virtual Domain eval(const std::vector<Domain>& arguments) const {
Domain result = 1;
- for (auto it = arguments.begin(),
+ for (typename std::vector<Domain>::const_iterator it = arguments.begin(),
end = arguments.end();
it != end;
++it) {
diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp
index 371ba56..907b5ab 100644
--- a/impl/VariableAssignment.hpp
+++ b/impl/VariableAssignment.hpp
@@ -25,7 +25,7 @@ struct DynamicVariableAssignment : public VariableAssignment<Domain> {
_values(system.variableCount(), infinity<Domain>()),
_stable(system.variableCount()),
_influence(system.variableCount(),
- IdSet<Variable<Domain>>(system.variableCount()))
+ IdSet<Variable<Domain> >(system.variableCount()))
{ }
const Domain& operator[](const Variable<Domain>& var) const {
@@ -54,7 +54,7 @@ private:
if (val != _values[x]) {
log::fixpoint << x << " = " << val << std::endl;
- auto oldInfluence = _influence[x];
+ IdSet<Variable<Domain> > oldInfluence = _influence[x];
_influence[x].clear();
_values[x] = val;
@@ -62,16 +62,18 @@ private:
_stable.filter(oldInfluence);
- for (auto it = oldInfluence.begin();
+ for (typename IdSet<Variable<Domain> >::iterator it = oldInfluence.begin();
it != oldInfluence.end();
++it) {
solve(_system.variable(*it));
}
} else {
- log::fixpoint << indent() << x << " did not change" << std::endl;
+ log::fixpoint << indent() << x << " did not change: "
+ << x << " = " << val << std::endl;
}
} else {
- log::fixpoint << indent() << x << " is stable" << std::endl;
+ log::fixpoint << indent() << x << " is stable: "
+ << x << " = " << _values[x] << std::endl;
}
}
diff --git a/impl/gmon.out b/impl/gmon.out
new file mode 100644
index 0000000..2c22b41
--- /dev/null
+++ b/impl/gmon.out
Binary files differ
diff --git a/impl/main.cpp b/impl/main.cpp
index b1d6984..6fbbda9 100644
--- a/impl/main.cpp
+++ b/impl/main.cpp
@@ -65,7 +65,8 @@ Expression<T>& treeToExpression(pANTLR3_BASE_TREE node, EquationSystem<T>& syste
} else if (name == "GUARD") {
op = new Guard<T>();
} else {
- throw "Parse error: Unknown operator";
+ std::cout << "throw exception" << *(char*)NULL;
+ //throw "Parse error: Unknown operator";
}
return system.expression(op, args);
}
@@ -75,8 +76,10 @@ template<typename T>
void treeToSystem(pANTLR3_BASE_TREE node, EquationSystem<T>& system) {
ANTLR3_UINT32 num = node->getChildCount(node);
- if (num % 2 == 1)
- throw "Big problem here.";
+ if (num % 2 == 1) {
+ std::cout << "throw exception" << *(char*)NULL;
+ //throw "Big problem here.";
+ }
pANTLR3_BASE_TREE varNode;
pANTLR3_BASE_TREE exprNode;
@@ -122,12 +125,12 @@ int main (int argc, char* argv[]) {
}
}
- auto input = antlr3FileStreamNew((pANTLR3_UINT8)argv[1], ANTLR3_ENC_8BIT);
- auto lex = EquationSystemLexerNew(input);
- auto tokens = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lex));
- auto parser = EquationSystemParserNew(tokens);
+ pANTLR3_INPUT_STREAM input = antlr3FileStreamNew((pANTLR3_UINT8)argv[1], ANTLR3_ENC_8BIT);
+ pEquationSystemLexer lex = EquationSystemLexerNew(input);
+ pANTLR3_COMMON_TOKEN_STREAM tokens = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lex));
+ pEquationSystemParser parser = EquationSystemParserNew(tokens);
- auto ret = parser -> equation_system(parser);
+ EquationSystemParser_equation_system_return ret = parser -> equation_system(parser);
EquationSystem<ZBar> system;
treeToSystem<ZBar>(ret.tree, system);
diff --git a/impl/systems/1 b/impl/systems/1
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/impl/systems/1
diff --git a/impl/systems/gmon.out b/impl/systems/gmon.out
new file mode 100644
index 0000000..4cb3fe1
--- /dev/null
+++ b/impl/systems/gmon.out
Binary files differ
diff --git a/impl/systems/test.eqns b/impl/systems/test.eqns
new file mode 100644
index 0000000..cc554d5
--- /dev/null
+++ b/impl/systems/test.eqns
@@ -0,0 +1,4 @@
+xup = max(0, min(xup + 1, 9 + 1))
+yup = max(0, min(xup + yup, 9 + yup))
+xlow = max(0, xlow-1)
+ylow = max(0, ylow + xlow)