diff options
author | Ramreiso Kashung <ramreisog24@gmail.com> | 2022-02-20 13:13:27 +0530 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-02-22 09:34:20 +0100 |
commit | bcaf13205052a64373599245ae0b1020b04b1385 (patch) | |
tree | 42c3ad1a4ec231a5055eab2936b4ddc2ebd6a649 | |
parent | b77e806f937d769c58c6bd1c6fbb77fbaa11268c (diff) |
tdf#147132: Flatten Basic function implementations
Some SbRtl_* functions have been flattened at basic/source/runtime/methods.cxx
Change-Id: Id56485ddfaa972133c9b199d22b141d93df475f6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130206
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | basic/source/runtime/methods.cxx | 188 |
1 files changed, 82 insertions, 106 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 3839d84852ea..897f49d3144b 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -185,13 +185,11 @@ void SbRtl_CreateObject(StarBASIC * pBasic, SbxArray & rPar, bool) OUString aClass(rPar.Get(1)->GetOUString()); SbxObjectRef p = SbxBase::CreateObject( aClass ); if( !p.is() ) - StarBASIC::Error( ERRCODE_BASIC_CANNOT_LOAD ); - else - { - // Convenience: enter BASIC as parent - p->SetParent( pBasic ); - rPar.Get(0)->PutObject(p.get()); - } + return StarBASIC::Error( ERRCODE_BASIC_CANNOT_LOAD ); + + // Convenience: enter BASIC as parent + p->SetParent( pBasic ); + rPar.Get(0)->PutObject(p.get()); } // Error( n ) @@ -199,54 +197,51 @@ void SbRtl_CreateObject(StarBASIC * pBasic, SbxArray & rPar, bool) void SbRtl_Error(StarBASIC * pBasic, SbxArray & rPar, bool) { if( !pBasic ) - StarBASIC::Error( ERRCODE_BASIC_INTERNAL_ERROR ); + return StarBASIC::Error( ERRCODE_BASIC_INTERNAL_ERROR ); + + OUString aErrorMsg; + ErrCode nErr = ERRCODE_NONE; + sal_Int32 nCode = 0; + if (rPar.Count() == 1) + { + nErr = StarBASIC::GetErrBasic(); + aErrorMsg = StarBASIC::GetErrorMsg(); + } else { - OUString aErrorMsg; - ErrCode nErr = ERRCODE_NONE; - sal_Int32 nCode = 0; - if (rPar.Count() == 1) - { - nErr = StarBASIC::GetErrBasic(); - aErrorMsg = StarBASIC::GetErrorMsg(); - } - else + nCode = rPar.Get(1)->GetLong(); + if( nCode > 65535 ) { - nCode = rPar.Get(1)->GetLong(); - if( nCode > 65535 ) - { - StarBASIC::Error( ERRCODE_BASIC_CONVERSION ); - } - else - { - nErr = StarBASIC::GetSfxFromVBError( static_cast<sal_uInt16>(nCode) ); - } - } - - bool bVBA = SbiRuntime::isVBAEnabled(); - OUString tmpErrMsg; - if( bVBA && !aErrorMsg.isEmpty()) - { - tmpErrMsg = aErrorMsg; + StarBASIC::Error( ERRCODE_BASIC_CONVERSION ); } else { - StarBASIC::MakeErrorText( nErr, aErrorMsg ); - tmpErrMsg = StarBASIC::GetErrorText(); + nErr = StarBASIC::GetSfxFromVBError( static_cast<sal_uInt16>(nCode) ); } - // If this rtlfunc 'Error' passed an errcode the same as the active Err Objects's - // current err then return the description for the error message if it is set - // ( complicated isn't it ? ) - if (bVBA && rPar.Count() > 1) + } + bool bVBA = SbiRuntime::isVBAEnabled(); + OUString tmpErrMsg; + if( bVBA && !aErrorMsg.isEmpty()) + { + tmpErrMsg = aErrorMsg; + } + else + { + StarBASIC::MakeErrorText( nErr, aErrorMsg ); + tmpErrMsg = StarBASIC::GetErrorText(); + } + // If this rtlfunc 'Error' passed an errcode the same as the active Err Objects's + // current err then return the description for the error message if it is set + // ( complicated isn't it ? ) + if (bVBA && rPar.Count() > 1) + { + uno::Reference< ooo::vba::XErrObject > xErrObj( SbxErrObject::getUnoErrObject() ); + if ( xErrObj.is() && xErrObj->getNumber() == nCode && !xErrObj->getDescription().isEmpty() ) { - uno::Reference< ooo::vba::XErrObject > xErrObj( SbxErrObject::getUnoErrObject() ); - if ( xErrObj.is() && xErrObj->getNumber() == nCode && !xErrObj->getDescription().isEmpty() ) - { - tmpErrMsg = xErrObj->getDescription(); - } + tmpErrMsg = xErrObj->getDescription(); } - rPar.Get(0)->PutString(tmpErrMsg); } + rPar.Get(0)->PutString(tmpErrMsg); } // Sinus @@ -254,106 +249,87 @@ void SbRtl_Error(StarBASIC * pBasic, SbxArray & rPar, bool) void SbRtl_Sin(StarBASIC *, SbxArray & rPar, bool) { if (rPar.Count() < 2) - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); - else - { - SbxVariableRef pArg = rPar.Get(1); - rPar.Get(0)->PutDouble(sin(pArg->GetDouble())); - } + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + SbxVariableRef pArg = rPar.Get(1); + rPar.Get(0)->PutDouble(sin(pArg->GetDouble())); } void SbRtl_Cos(StarBASIC *, SbxArray & rPar, bool) { if (rPar.Count() < 2) - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); - else - { - SbxVariableRef pArg = rPar.Get(1); - rPar.Get(0)->PutDouble(cos(pArg->GetDouble())); - } + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + SbxVariableRef pArg = rPar.Get(1); + rPar.Get(0)->PutDouble(cos(pArg->GetDouble())); } void SbRtl_Atn(StarBASIC *, SbxArray & rPar, bool) { if (rPar.Count() < 2) - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); - else - { - SbxVariableRef pArg = rPar.Get(1); - rPar.Get(0)->PutDouble(atan(pArg->GetDouble())); - } + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + SbxVariableRef pArg = rPar.Get(1); + rPar.Get(0)->PutDouble(atan(pArg->GetDouble())); } void SbRtl_Abs(StarBASIC *, SbxArray & rPar, bool) { if (rPar.Count() < 2) - { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); - } - else - { - SbxVariableRef pArg = rPar.Get(1); - rPar.Get(0)->PutDouble(fabs(pArg->GetDouble())); - } + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + SbxVariableRef pArg = rPar.Get(1); + rPar.Get(0)->PutDouble(fabs(pArg->GetDouble())); } void SbRtl_Asc(StarBASIC *, SbxArray & rPar, bool) { if (rPar.Count() < 2) + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + SbxVariableRef pArg = rPar.Get(1); + OUString aStr( pArg->GetOUString() ); + if ( aStr.isEmpty()) { StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + rPar.Get(0)->PutEmpty(); + return; } - else - { - SbxVariableRef pArg = rPar.Get(1); - OUString aStr( pArg->GetOUString() ); - if ( aStr.isEmpty()) - { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); - rPar.Get(0)->PutEmpty(); - } - else - { - sal_Unicode aCh = aStr[0]; - rPar.Get(0)->PutLong(aCh); - } - } + sal_Unicode aCh = aStr[0]; + rPar.Get(0)->PutLong(aCh); } static void implChr( SbxArray& rPar, bool bChrW ) { if (rPar.Count() < 2) + return StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + + SbxVariableRef pArg = rPar.Get(1); + + OUString aStr; + if( !bChrW && SbiRuntime::isVBAEnabled() ) { - StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT ); + char c = static_cast<char>(pArg->GetByte()); + aStr = OUString(&c, 1, osl_getThreadTextEncoding()); } else { - SbxVariableRef pArg = rPar.Get(1); - - OUString aStr; - if( !bChrW && SbiRuntime::isVBAEnabled() ) + // Map negative 16-bit values to large positive ones, so that code like Chr(&H8000) + // still works after the fix for tdf#62326 changed those four-digit hex notations to + // produce negative values: + sal_Int32 aCh = pArg->GetLong(); + if (aCh < -0x8000 || aCh > 0xFFFF) { - char c = static_cast<char>(pArg->GetByte()); - aStr = OUString(&c, 1, osl_getThreadTextEncoding()); + StarBASIC::Error(ERRCODE_BASIC_MATH_OVERFLOW); + aCh = 0; } - else - { - // Map negative 16-bit values to large positive ones, so that code like Chr(&H8000) - // still works after the fix for tdf#62326 changed those four-digit hex notations to - // produce negative values: - sal_Int32 aCh = pArg->GetLong(); - if (aCh < -0x8000 || aCh > 0xFFFF) { - StarBASIC::Error(ERRCODE_BASIC_MATH_OVERFLOW); - aCh = 0; - } - aStr = OUString(static_cast<sal_Unicode>(aCh)); - } - rPar.Get(0)->PutString(aStr); + aStr = OUString(static_cast<sal_Unicode>(aCh)); } + rPar.Get(0)->PutString(aStr); } void SbRtl_Chr(StarBASIC *, SbxArray & rPar, bool) |