diff options
author | Mu Qiao <qiaomuf@gentoo.org> | 2011-06-10 11:16:36 +0800 |
---|---|---|
committer | Mu Qiao <qiaomuf@gentoo.org> | 2011-06-10 16:23:13 +0800 |
commit | adac84d440f2441e78ffb0175e2009ffc2656d58 (patch) | |
tree | 20ae601f50a6eb1ee4a3f3e82f02d75dfc25e55d /src/core/interpreter.h | |
parent | Utility: fix error counting (diff) | |
download | libbash-adac84d440f2441e78ffb0175e2009ffc2656d58.tar.gz libbash-adac84d440f2441e78ffb0175e2009ffc2656d58.tar.bz2 libbash-adac84d440f2441e78ffb0175e2009ffc2656d58.zip |
Walker: remove abstraction for arithmetic
Diffstat (limited to 'src/core/interpreter.h')
-rw-r--r-- | src/core/interpreter.h | 243 |
1 files changed, 0 insertions, 243 deletions
diff --git a/src/core/interpreter.h b/src/core/interpreter.h index 6aefc4c..b7274ca 100644 --- a/src/core/interpreter.h +++ b/src/core/interpreter.h @@ -24,8 +24,6 @@ #ifndef LIBBASH_CORE_INTERPRETER_H_ #define LIBBASH_CORE_INTERPRETER_H_ -#include <cmath> - #include <functional> #include <memory> #include <string> @@ -191,247 +189,6 @@ public: /// \return the value of node->text static std::string get_string(pANTLR3_BASE_TREE node); - /// \brief perform logic or - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int logicor(int left, int right) - { - return left || right; - } - - /// \brief perform logic and - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int logicand(int left, int right) - { - return left && right; - } - - /// \brief perform bitwise or - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int bitwiseor(int left, int right) - { - return left | right; - } - - /// \brief perform bitwise and - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int bitwiseand(int left, int right) - { - return left & right; - } - - /// \brief perform bitwise xor - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int bitwisexor(int left, int right) - { - return left ^ right; - } - - /// \brief perform left or equal to - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int less_equal_than(int left, int right) - { - return left <= right; - } - - /// \brief perform greater or equal to - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int greater_equal_than(int left, int right) - { - return left >= right; - } - - /// \brief perform less than - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int less_than(int left, int right) - { - return left < right; - } - - /// \brief perform greater than - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int greater_than(int left, int right) - { - return left > right; - } - - /// \brief perform not equal to - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int not_equal_to(int left, int right) - { - return left != right; - } - - /// \brief perform left shift - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int left_shift(int left, int right) - { - return left << right; - } - - /// \brief perform right shift - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int right_shift(int left, int right) - { - return left >> right; - } - - /// \brief perform plus - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int plus(int left, int right) - { - return left + right; - } - - /// \brief perform minus - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int minus(int left, int right) - { - return left - right; - } - - /// \brief perform multiply - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int multiply(int left, int right) - { - return left * right; - } - - /// \brief perform divide - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int divide(int left, int right) - { - // We are not handling division by zero right now - return left / right; - } - - /// \brief perform modulo - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int mod(int left, int right) - { - return left % right; - } - - /// \brief perform exponential operation - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int exp(int left, int right); - - /// \brief perform logic negation - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int negation(int element) - { - return !element; - } - - /// \brief perform bitwise negation - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int bitwise_negation(int element) - { - return ~element; - } - - - /// \brief perform the ternary operator - /// \param the condition - /// \param the first operand - /// \param the second operand - /// \return the calculated result - static int arithmetic_condition(int cnd, int left, int right) - { - return (cnd? left : right); - } - - /// \brief perform pre-increment - /// \param the variable name - /// \return the increased value - int pre_incr(const std::string& name, const unsigned index) - { - int value = resolve<int>(name, index); - set_value(name, ++value); - return value; - } - - /// \brief perform pre-decrement - /// \param the variable name - /// \return the decreased value - int pre_decr(const std::string& name, const unsigned index) - { - int value = resolve<int>(name, index); - set_value(name, --value); - return value; - } - - /// \brief perform post-increment - /// \param the variable name - /// \return the original value - int post_incr(const std::string& name, const unsigned index) - { - int value = resolve<int>(name, index); - set_value(name, value + 1); - return value; - } - - /// \brief perform post-decrement - /// \param the variable name - /// \return the original value - int post_decr(const std::string& name, const unsigned index) - { - int value = resolve<int>(name, index); - set_value(name, value - 1); - return value; - } - - /// \brief assign with an operator (for example multiply) - /// \param a function object to do an operation while assigning - /// \param the name of the variable - /// \param the value to assign - /// \return the new value of the variable - int assign(std::function<int(int,int)> f, const std::string& name, int value, const unsigned index) - { - int new_value = f(resolve<int>(name, index), value); - set_value(name, new_value, index); - return new_value; - } - /// \brief resolve string/int variable, local scope will be /// checked first, then global scope /// \param variable name |