From f6e759acb43649e278327a6b6a8a83fbf9af3fe5 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Sat, 7 Nov 2009 19:34:35 -0700 Subject: Check for different versions of boost in build math files (also fixes broken build math functions) --- linden/indra/llmath/llcalc.cpp | 6 +++ linden/indra/llmath/llcalcparser.cpp | 11 ++++- linden/indra/llmath/llcalcparser.h | 78 ++++++++++++++++++++++++------------ 3 files changed, 68 insertions(+), 27 deletions(-) (limited to 'linden/indra/llmath') diff --git a/linden/indra/llmath/llcalc.cpp b/linden/indra/llmath/llcalc.cpp index 526a116..74f9544 100644 --- a/linden/indra/llmath/llcalc.cpp +++ b/linden/indra/llmath/llcalc.cpp @@ -11,8 +11,14 @@ #include "llcalc.h" +#include +#if BOOST_VERSION >= 103600 +#include +#include +#else #include #include +#endif #include "llcalcparser.h" #include "llmath.h" diff --git a/linden/indra/llmath/llcalcparser.cpp b/linden/indra/llmath/llcalcparser.cpp index 1546c09..df2bc09 100644 --- a/linden/indra/llmath/llcalcparser.cpp +++ b/linden/indra/llmath/llcalcparser.cpp @@ -11,6 +11,13 @@ #include "llcalcparser.h" +#include +#if BOOST_VERSION >= 103600 +using namespace boost::spirit::classic; +#else +using namespace boost::spirit; +#endif + F32 LLCalcParser::lookup(const std::string::iterator& start, const std::string::iterator& end) const { LLCalc::calc_map_t::iterator iter; @@ -28,7 +35,7 @@ F32 LLCalcParser::lookup(const std::string::iterator& start, const std::string:: else { // This should never happen! - boost::spirit::throw_(end, std::string("Missing constants table")); + throw_(end, std::string("Missing constants table")); } if (mVariables) @@ -40,6 +47,6 @@ F32 LLCalcParser::lookup(const std::string::iterator& start, const std::string:: } } - boost::spirit::throw_(end, std::string("Unknown symbol " + name)); + throw_(end, std::string("Unknown symbol " + name)); return 0.f; } diff --git a/linden/indra/llmath/llcalcparser.h b/linden/indra/llmath/llcalcparser.h index c405b62..d8acc1f 100644 --- a/linden/indra/llmath/llcalcparser.h +++ b/linden/indra/llmath/llcalcparser.h @@ -10,24 +10,37 @@ #ifndef LL_CALCPARSER_H #define LL_CALCPARSER_H +#include +#if BOOST_VERSION >= 103600 +#include +#include +#include +#include +#include +#include +using namespace boost::spirit::classic; +#else #include #include #include #include #include -//#include +#include +using namespace boost::spirit; +#endif + #include #include #include "llcalc.h" #include "llmath.h" -struct LLCalcParser : boost::spirit::grammar +struct LLCalcParser : grammar { LLCalcParser(F32& result, LLCalc::calc_map_t* constants, LLCalc::calc_map_t* vars) : mResult(result), mConstants(constants), mVariables(vars) {}; - struct value_closure : boost::spirit::closure + struct value_closure : closure { member1 value; }; @@ -36,21 +49,20 @@ struct LLCalcParser : boost::spirit::grammar struct definition { // Rule declarations - boost::spirit::rule statement, identifier; - boost::spirit::rule expression, term, + rule statement, identifier; + rule expression, term, power, unary_expr, factor, - /*unary_func, - /binary_func,*/ + unary_func, + binary_func, group; // start() should return the starting symbol - boost::spirit::rule const& start() const { return statement; } + rule const& start() const { return statement; } definition(LLCalcParser const& self) { - using namespace boost::spirit; using namespace phoenix; assertion assert_domain("Domain error"); @@ -64,30 +76,30 @@ struct LLCalcParser : boost::spirit::grammar group = '(' >> expression[group.value = arg1] >> assert_syntax(ch_p(')')) ; - - /*unary_func = - ((str_p("SIN") >> '(' >> expression[unary_func.value = bind(&sin)(DEG_TO_RAD * arg1)]) | - (str_p("COS") >> '(' >> expression[unary_func.value = bind(&cos)(DEG_TO_RAD * arg1)]) | - (str_p("TAN") >> '(' >> expression[unary_func.value = bind(&tan)(DEG_TO_RAD * arg1)]) | - (str_p("ASIN") >> '(' >> expression[unary_func.value = (bind(&asin)(arg1)) * RAD_TO_DEG]) | - (str_p("ACOS") >> '(' >> expression[unary_func.value = bind(&acos)(arg1) * RAD_TO_DEG]) | - (str_p("ATAN") >> '(' >> expression[unary_func.value = bind(&atan)(arg1) * RAD_TO_DEG]) | - (str_p("SQRT") >> '(' >> expression[unary_func.value = bind(&sqrt)(arg1)]) | - (str_p("LOG") >> '(' >> expression[unary_func.value = bind(&log)(arg1)]) | - (str_p("EXP") >> '(' >> expression[unary_func.value = bind(&exp)(arg1)]) | - (str_p("ABS") >> '(' >> expression[unary_func.value = bind(&fabs)(arg1)]) + + unary_func = + ((str_p("SIN") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_sin)(self,arg1)]) | + (str_p("COS") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_cos)(self,arg1)]) | + (str_p("TAN") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_tan)(self,arg1)]) | + (str_p("ASIN") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_asin)(self,arg1)]) | + (str_p("ACOS") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_acos)(self,arg1)]) | + (str_p("ATAN") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_atan)(self,arg1)]) | + (str_p("SQRT") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_sqrt)(self,arg1)]) | + (str_p("LOG") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_log)(self,arg1)]) | + (str_p("EXP") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_exp)(self,arg1)]) | + (str_p("ABS") >> '(' >> expression[unary_func.value = bind(&LLCalcParser::_fabs)(self,arg1)]) ) >> assert_syntax(ch_p(')')) ; binary_func = ((str_p("ATAN2") >> '(' >> expression[binary_func.value = arg1] >> ',' >> - expression[binary_func.value = bind(&atan2)(binary_func.value, arg1) * RAD_TO_DEG]) | + expression[binary_func.value = bind(&LLCalcParser::_atan2)(self, binary_func.value, arg1)]) | (str_p("MIN") >> '(' >> expression[binary_func.value = arg1] >> ',' >> expression[binary_func.value = bind(&LLCalcParser::min)(self, binary_func.value, arg1)]) | (str_p("MAX") >> '(' >> expression[binary_func.value = arg1] >> ',' >> expression[binary_func.value = bind(&LLCalcParser::max)(self, binary_func.value, arg1)]) ) >> assert_syntax(ch_p(')')) - ;*/ + ; // *TODO: Localisation of the decimal point? // Problem, LLLineEditor::postvalidateFloat accepts a comma when appropriate @@ -96,8 +108,8 @@ struct LLCalcParser : boost::spirit::grammar factor = (ureal_p[factor.value = arg1] | group[factor.value = arg1] | - /*unary_func[factor.value = arg1] | - binary_func[factor.value = arg1] |*/ + unary_func[factor.value = arg1] | + binary_func[factor.value = arg1] | // Lookup throws an Unknown Symbol error if it is unknown, while this works fine, // would be "neater" to handle symbol lookup from here with an assertive parser. // constants_p[factor.value = arg1]| @@ -144,6 +156,22 @@ private: F32 max(const F32& a, const F32& b) const { return llmax(a, b); } bool checkNaN(const F32& a) const { return !llisnan(a); } + + //FIX* non ambigious function fix making SIN() work for calc -Cryogenic Blitz + F32 _sin(const F32& a) const { return sin(DEG_TO_RAD * a); } + F32 _cos(const F32& a) const { return cos(DEG_TO_RAD * a); } + F32 _tan(const F32& a) const { return tan(DEG_TO_RAD * a); } + F32 _asin(const F32& a) const { return asin(a * RAD_TO_DEG); } + F32 _acos(const F32& a) const { return acos(a * RAD_TO_DEG); } + F32 _atan(const F32& a) const { return atan(a * RAD_TO_DEG); } + F32 _sqrt(const F32& a) const { return sqrt(a); } + F32 _log(const F32& a) const { return log(a); } + F32 _exp(const F32& a) const { return exp(a); } + F32 _fabs(const F32& a) const { return fabs(a) * RAD_TO_DEG; } + + F32 _atan2(const F32& a,const F32& b) const { return atan2(a,b); } + + LLCalc::calc_map_t* mConstants; LLCalc::calc_map_t* mVariables; -- cgit v1.1