sw/inc/calc.hxx | 4 + sw/source/core/bastyp/calc.cxx | 85 +++++++++++++++++++++++++---------------- 2 files changed, 57 insertions(+), 32 deletions(-)
New commits: commit a77223b281d79db60c6905e77538f077200b1af8 Author: Caolán McNamara <caol...@redhat.com> Date: Sat Oct 1 12:23:46 2016 +0100 rearrange SwCalc some more Change-Id: Ib1ffc112ddd006102b29536f7433a3f16bf63a3f diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx index 20f9901..8389861 100644 --- a/sw/inc/calc.hxx +++ b/sw/inc/calc.hxx @@ -174,6 +174,7 @@ class SwCalc SwCalcOper GetToken(); SwSbxValue Expr(); SwSbxValue Term(); + SwSbxValue PrimFunc(bool &rChkPow); SwSbxValue Prim(); SwSbxValue StdFunc(pfCalc pFnc, bool bChkTrig); diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx index 2f2e42f..c7bdf9f 100644 --- a/sw/source/core/bastyp/calc.cxx +++ b/sw/source/core/bastyp/calc.cxx @@ -1042,36 +1042,34 @@ SwSbxValue SwCalc::StdFunc(pfCalc pFnc, bool bChkTrig) return nErg; } -SwSbxValue SwCalc::Prim() +SwSbxValue SwCalc::PrimFunc(bool &rChkPow) { - SwSbxValue nErg; - - bool bChkPow = false; + rChkPow = false; switch (m_eCurrOper) { case CALC_SIN: - nErg = StdFunc(&sin, false); + return StdFunc(&sin, false); break; case CALC_COS: - nErg = StdFunc(&cos, false); + return StdFunc(&cos, false); break; case CALC_TAN: - nErg = StdFunc(&tan, false); + return StdFunc(&tan, false); break; case CALC_ATAN: - nErg = StdFunc(&atan, false); + return StdFunc(&atan, false); break; case CALC_ASIN: - nErg = StdFunc(&asin, true); + return StdFunc(&asin, true); break; case CALC_ACOS: - nErg = StdFunc(&acos, true); + return StdFunc(&acos, true); break; case CALC_NOT: { GetToken(); - nErg = Prim(); + SwSbxValue nErg = Prim(); if( SbxSTRING == nErg.GetType() ) { nErg.PutBool( nErg.GetOUString().isEmpty() ); @@ -1092,10 +1090,12 @@ SwSbxValue SwCalc::Prim() //!! computes a binary NOT nErg.Compute( SbxNOT, nErg ); } + return nErg; break; } case CALC_NUMBER: { + SwSbxValue nErg; if( GetToken() == CALC_PHD ) { double aTmp = m_nNumberValue.GetDouble(); @@ -1110,12 +1110,14 @@ SwSbxValue SwCalc::Prim() else { nErg = m_nNumberValue; - bChkPow = true; + rChkPow = true; } + return nErg; break; } case CALC_NAME: { + SwSbxValue nErg; switch(SwCalcOper eOper = GetToken()) { case CALC_ASSIGN: @@ -1132,19 +1134,24 @@ SwSbxValue SwCalc::Prim() if (nErg.IsVoidValue() && (eOper == CALC_LP)) m_eError = CALC_SYNTAX; else - bChkPow = true; + rChkPow = true; break; } + return nErg; break; } case CALC_MINUS: + { + SwSbxValue nErg; GetToken(); nErg.PutDouble( -(Prim().GetDouble()) ); + return nErg; break; + } case CALC_LP: { GetToken(); - nErg = Expr(); + SwSbxValue nErg = Expr(); if( m_eCurrOper != CALC_RP ) { m_eError = CALC_BRACK; @@ -1152,46 +1159,64 @@ SwSbxValue SwCalc::Prim() else { GetToken(); - bChkPow = true; // in order for =(7)^2 to work + rChkPow = true; // in order for =(7)^2 to work } + return nErg; break; } case CALC_MEAN: { m_nListPor = 1; GetToken(); - nErg = Expr(); + SwSbxValue nErg = Expr(); double aTmp = nErg.GetDouble(); aTmp /= m_nListPor; nErg.PutDouble( aTmp ); + return nErg; break; } case CALC_SQRT: { GetToken(); - nErg = Prim(); + SwSbxValue nErg = Prim(); if( nErg.GetDouble() < 0 ) m_eError = CALC_OVERFLOW; else nErg.PutDouble( sqrt( nErg.GetDouble() )); + return nErg; break; } case CALC_SUM: case CALC_DATE: case CALC_MIN: case CALC_MAX: + { GetToken(); - nErg = Expr(); + SwSbxValue nErg = Expr(); + return nErg; break; + } case CALC_ENDCALC: + { + SwSbxValue nErg; nErg.Clear(); + return nErg; break; + } default: m_eError = CALC_SYNTAX; break; } - if( bChkPow && m_eCurrOper == CALC_POW ) + return SwSbxValue(); +} + +SwSbxValue SwCalc::Prim() +{ + bool bChkPow; + SwSbxValue nErg = PrimFunc(bChkPow); + + if (bChkPow && m_eCurrOper == CALC_POW) { double dleft = nErg.GetDouble(); GetToken(); commit 9b2a24b9e32ded1b6dc111ddc06b7ed07c0b7d6d Author: Caolán McNamara <caol...@redhat.com> Date: Sat Oct 1 12:15:04 2016 +0100 rearrange SwCalc a little Change-Id: I42278cf63f3cf2a1c3362fcb8c4eeacab2a9de48 diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx index 4610eaf..20f9901 100644 --- a/sw/inc/calc.hxx +++ b/sw/inc/calc.hxx @@ -148,6 +148,8 @@ void DeleteHashTable( SwHash** ppTable, sal_uInt16 nTableSize ); struct CalcOp; CalcOp* FindOperator( const OUString& rSearch ); +extern "C" typedef double (*pfCalc)(double); + class SwCalc { SwHash* m_aVarTable[ TBLSZ ]; @@ -173,6 +175,7 @@ class SwCalc SwSbxValue Expr(); SwSbxValue Term(); SwSbxValue Prim(); + SwSbxValue StdFunc(pfCalc pFnc, bool bChkTrig); static OUString GetColumnName( const OUString& rName ); OUString GetDBName( const OUString& rName ); diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx index 6d8faa5..2f2e42f 100644 --- a/sw/source/core/bastyp/calc.cxx +++ b/sw/source/core/bastyp/calc.cxx @@ -1030,37 +1030,43 @@ SwSbxValue SwCalc::Term() } } -extern "C" typedef double (*pfCalc)( double ); +SwSbxValue SwCalc::StdFunc(pfCalc pFnc, bool bChkTrig) +{ + SwSbxValue nErg; + GetToken(); + double nVal = Prim().GetDouble(); + if( !bChkTrig || ( nVal > -1 && nVal < 1 ) ) + nErg.PutDouble( (*pFnc)( nVal ) ); + else + m_eError = CALC_OVERFLOW; + return nErg; +} SwSbxValue SwCalc::Prim() { SwSbxValue nErg; - pfCalc pFnc = nullptr; - - bool bChkTrig = false, bChkPow = false; + bool bChkPow = false; switch (m_eCurrOper) { case CALC_SIN: - pFnc = &sin; + nErg = StdFunc(&sin, false); break; case CALC_COS: - pFnc = &cos; + nErg = StdFunc(&cos, false); break; case CALC_TAN: - pFnc = &tan; + nErg = StdFunc(&tan, false); break; case CALC_ATAN: - pFnc = &atan; + nErg = StdFunc(&atan, false); break; case CALC_ASIN: - pFnc = &asin; - bChkTrig = true; + nErg = StdFunc(&asin, true); break; case CALC_ACOS: - pFnc = &acos; - bChkTrig = true; + nErg = StdFunc(&acos, true); break; case CALC_NOT: { @@ -1185,16 +1191,6 @@ SwSbxValue SwCalc::Prim() break; } - if( pFnc ) - { - GetToken(); - double nVal = Prim().GetDouble(); - if( !bChkTrig || ( nVal > -1 && nVal < 1 ) ) - nErg.PutDouble( (*pFnc)( nVal ) ); - else - m_eError = CALC_OVERFLOW; - } - if( bChkPow && m_eCurrOper == CALC_POW ) { double dleft = nErg.GetDouble();
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits