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.hpp10
-rw-r--r--impl/MaxStrategy.hpp7
-rw-r--r--impl/Operator.hpp3
-rw-r--r--impl/VariableAssignment.hpp6
-rw-r--r--impl/main.cpp19
8 files changed, 36 insertions, 35 deletions
diff --git a/impl/Complete.hpp b/impl/Complete.hpp
index 5219c9e..9acb9d0 100644
--- a/impl/Complete.hpp
+++ b/impl/Complete.hpp
@@ -15,10 +15,7 @@ struct Complete {
: _value(value), _infinity(false) { }
Complete(const T& value, const bool& infinity)
: _value(value), _infinity(infinity) {
- if (value == 0 && infinity == true) {
- std::cout << "throw exception" << *(char*)NULL;
- //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 c0734aa..2fd24bd 100644
--- a/impl/EquationSystem.hpp
+++ b/impl/EquationSystem.hpp
@@ -96,17 +96,12 @@ struct EquationSystem {
}
Variable<Domain>* varFromExpr(const Expression<Domain>& expr) const {
- if (_expr_to_var) { // we've indexed:
- const MaxExpression<Domain>* 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 {
- std::cout << "throw exception" << *(char*)NULL;
return NULL;
- //throw "Must index max expressions before attempting lookup";
}
}
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 27c0806..ed0723e 100644
--- a/impl/IdMap.hpp
+++ b/impl/IdMap.hpp
@@ -32,17 +32,11 @@ struct IdMap {
return *this;
}
virtual const V& operator[] (const T& x) const {
- if (x.id() >= _length) {
- std::cout << "throw exception" << *(char*)NULL;
- //throw "Array out of bounds";
- }
+ assert(x.id() < _length);
return _assignment[x.id()];
}
virtual V& operator[] (const T& x) {
- if (x.id() >= _length) {
- std::cout << "throw exception" << *(char*)NULL;
- //throw "Array out of bounds";
- }
+ assert(x.id() < _length);
return _assignment[x.id()];
}
diff --git a/impl/MaxStrategy.hpp b/impl/MaxStrategy.hpp
index 667c127..f330f3b 100644
--- a/impl/MaxStrategy.hpp
+++ b/impl/MaxStrategy.hpp
@@ -61,6 +61,7 @@ struct DynamicMaxStrategy : public MaxStrategy<Domain> {
++it) {
solve(_system.maxExpression(*it));
}
+ _var_influence[v].clear();
}
private:
@@ -93,10 +94,12 @@ private:
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;
}
}
diff --git a/impl/Operator.hpp b/impl/Operator.hpp
index b67591f..cf3ffed 100644
--- a/impl/Operator.hpp
+++ b/impl/Operator.hpp
@@ -47,8 +47,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 {
diff --git a/impl/VariableAssignment.hpp b/impl/VariableAssignment.hpp
index 69eeef2..907b5ab 100644
--- a/impl/VariableAssignment.hpp
+++ b/impl/VariableAssignment.hpp
@@ -68,10 +68,12 @@ private:
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/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);