diff options
author | Winfried Donkers <osc@dci-electronics.nl> | 2013-01-07 15:34:32 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2013-01-11 17:01:23 +0100 |
commit | 5fd9feafa5d73121636af9397d42e046cc394719 (patch) | |
tree | 8e21bfd21fe23e64a9eb3214c9c7ade60ce312a8 /formula/source | |
parent | 0f4afa41ec8e2f438fbea9e4d7a123f668b124ca (diff) |
fdo#56124 add functions IFERROR and IFNA to calc as in ODFF1.2
Change-Id: I6403b51ac8c710ad3b8d2625e1482971f50e6b1d
Diffstat (limited to 'formula/source')
-rw-r--r-- | formula/source/core/api/FormulaCompiler.cxx | 24 | ||||
-rw-r--r-- | formula/source/core/api/token.cxx | 22 | ||||
-rw-r--r-- | formula/source/core/resource/core_resource.src | 12 |
3 files changed, 42 insertions, 16 deletions
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx index f79201b6c673..e91912368a5c 100644 --- a/formula/source/core/api/FormulaCompiler.cxx +++ b/formula/source/core/api/FormulaCompiler.cxx @@ -824,7 +824,7 @@ sal_uInt16 FormulaCompiler::GetErrorConstant( const String& rName ) const { switch ((*iLook).second) { - // Not all may make sense in a formula, but these we know as + // Not all may make sense in a formula, but these we know as // opcodes. case ocErrNull: nError = errNoCode; @@ -1125,7 +1125,8 @@ void FormulaCompiler::Factor() || eOp == ocOr || eOp == ocBad || ( eOp >= ocInternalBegin && eOp <= ocInternalEnd ) - || (bCompileForFAP && ((eOp == ocIf) || (eOp == ocChose))) + || ( bCompileForFAP + && ( eOp == ocIf || eOp == ocIfError || eOp == ocIfNA || eOp == ocChose ) ) ) { pFacToken = mpToken; @@ -1174,14 +1175,16 @@ void FormulaCompiler::Factor() pFacToken->SetByte( nSepCount ); PutCode( pFacToken ); } - else if (eOp == ocIf || eOp == ocChose) + else if (eOp == ocIf || eOp == ocIfError || eOp == ocIfNA || eOp == ocChose) { // the PC counters are -1 pFacToken = mpToken; if ( eOp == ocIf ) pFacToken->GetJump()[ 0 ] = 3; // if, else, behind - else + else if ( eOp == ocChose ) pFacToken->GetJump()[ 0 ] = MAXJUMPCOUNT+1; + else + pFacToken->GetJump()[ 0 ] = 2; // if, else eOp = NextToken(); if (eOp == ocOpen) { @@ -1195,9 +1198,10 @@ void FormulaCompiler::Factor() // during AutoCorrect (since pArr->GetCodeError() is // ignored) an unlimited ocIf would crash because // ScRawToken::Clone() allocates the JumpBuffer according to - // nJump[0]*2+2, which is 3*2+2 on ocIf. - const short nJumpMax = - (pFacToken->GetOpCode() == ocIf ? 3 : MAXJUMPCOUNT); + // nJump[0]*2+2, which is 3*2+2 on ocIf and 2*2+2 ocIfError and ocIfNA. + OpCode eFacOpCode = pFacToken->GetOpCode(); + const short nJumpMax = ( eFacOpCode == ocIf ? 3 : + ( eFacOpCode == ocChose ? MAXJUMPCOUNT : 2 ) ); while ( (nJumpCount < (MAXJUMPCOUNT - 1)) && (eOp == ocSep) && (!pArr->GetCodeError() || bIgnoreErrors) ) { @@ -1216,8 +1220,10 @@ void FormulaCompiler::Factor() // always limit to nJumpMax, no arbitrary overwrites if ( ++nJumpCount <= nJumpMax ) pFacToken->GetJump()[ nJumpCount ] = pc-1; - if ((pFacToken->GetOpCode() == ocIf && (nJumpCount > 3)) || - (nJumpCount >= MAXJUMPCOUNT)) + eFacOpCode = pFacToken->GetOpCode(); + if ( ( eFacOpCode == ocIf && nJumpCount > 3) || + ( ( eFacOpCode == ocIfError || eFacOpCode == ocIfNA ) && nJumpCount > 2 ) || + ( nJumpCount >= MAXJUMPCOUNT ) ) SetError(errIllegalParameter); else pFacToken->GetJump()[ 0 ] = nJumpCount; diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index d187073b2f22..f6110e7ce5b3 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -76,7 +76,7 @@ bool FormulaToken::IsFunction() const eOp != ocColRowNameAuto && eOp != ocName && eOp != ocDBArea && (GetByte() != 0 // x parameters || (SC_OPCODE_START_NO_PAR <= eOp && eOp < SC_OPCODE_STOP_NO_PAR) // no parameter - || (ocIf == eOp || ocChose == eOp ) // @ jump commands + || (ocIf == eOp || ocIfError == eOp || ocIfNA == eOp || ocChose == eOp ) // @ jump commands || (SC_OPCODE_START_1_PAR <= eOp && eOp < SC_OPCODE_STOP_1_PAR) // one parameter || (SC_OPCODE_START_2_PAR <= eOp && eOp < SC_OPCODE_STOP_2_PAR) // x parameters (cByte==0 in // FuncAutoPilot) @@ -91,9 +91,10 @@ bool FormulaToken::IsFunction() const sal_uInt8 FormulaToken::GetParamCount() const { if ( eOp < SC_OPCODE_STOP_DIV && eOp != ocExternal && eOp != ocMacro && - eOp != ocIf && eOp != ocChose && eOp != ocPercentSign ) + eOp != ocIf && eOp != ocIfError && eOp != ocIfNA && eOp != ocChose && + eOp != ocPercentSign ) return 0; // parameters and specials - // ocIf and ocChose not for FAP, have cByte then + // ocIf, ocIfError, ocIfNA and ocChose not for FAP, have cByte then //2do: bool parameter whether FAP or not? else if ( GetByte() ) return GetByte(); // all functions, also ocExternal and ocMacro @@ -106,7 +107,7 @@ sal_uInt8 FormulaToken::GetParamCount() const return 0; // no parameter else if (SC_OPCODE_START_1_PAR <= eOp && eOp < SC_OPCODE_STOP_1_PAR) return 1; // one parameter - else if ( eOp == ocIf || eOp == ocChose ) + else if ( eOp == ocIf || eOp == ocIfError || eOp == ocIfNA || eOp == ocChose ) return 1; // only the condition counts as parameter else return 0; // all the rest, no Parameter, or @@ -842,8 +843,8 @@ bool FormulaTokenArray::HasMatrixDoubleRefOps() } if ( eOp == ocPush || lcl_IsReference( eOp, t->GetType() ) ) pStack[sp++] = t; - else if ( eOp == ocIf || eOp == ocChose ) - { // Jumps ignorieren, vorheriges Result (Condition) poppen + else if ( eOp == ocIf || eOp == ocIfError || eOp == ocIfNA || eOp == ocChose ) + { // ignore Jumps, pop previous Result (Condition) if ( sp ) --sp; } @@ -1178,10 +1179,17 @@ FormulaToken* FormulaTokenArray::AddOpCode( OpCode eOp ) pRet = new FormulaToken( svSep,eOp ); break; case ocIf: + case ocIfError: + case ocIfNA: case ocChose: { short nJump[MAXJUMPCOUNT + 1]; - nJump[ 0 ] = ocIf == eOp ? 3 : MAXJUMPCOUNT+1; + if ( eOp == ocIf ) + nJump[ 0 ] = 3; + else if ( eOp == ocChose ) + nJump[ 0 ] = MAXJUMPCOUNT + 1; + else + nJump[ 0 ] = 2; pRet = new FormulaJumpToken( eOp, (short*)nJump ); } break; diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src index 8b0ee14e9a5a..1852d5839ae4 100644 --- a/formula/source/core/resource/core_resource.src +++ b/formula/source/core/resource/core_resource.src @@ -24,6 +24,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF { String SC_OPCODE_IF { Text = "IF" ; }; + String SC_OPCODE_IF_NA { Text = "IFERROR" ; }; + String SC_OPCODE_IF_ERROR { Text = "IFNA" ; }; String SC_OPCODE_CHOSE { Text = "CHOOSE" ; }; String SC_OPCODE_OPEN { Text = "(" ; }; String SC_OPCODE_CLOSE { Text = ")" ; }; @@ -362,6 +364,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH { String SC_OPCODE_IF { Text = "IF" ; }; + String SC_OPCODE_IF_ERROR { Text = "IFERROR" ; }; + String SC_OPCODE_IF_NA { Text = "IFNA" ; }; String SC_OPCODE_CHOSE { Text = "CHOOSE" ; }; String SC_OPCODE_OPEN { Text = "(" ; }; String SC_OPCODE_CLOSE { Text = ")" ; }; @@ -700,6 +704,14 @@ Resource RID_STRLIST_FUNCTION_NAMES { Text [ en-US ] = "IF" ; }; + String SC_OPCODE_IF_ERROR + { + Text [ en-US ] = "IFERROR" ; + }; + String SC_OPCODE_IF_NA + { + Text [ en-US ] = "IFNA" ; + }; String SC_OPCODE_CHOSE { Text [ en-US ] = "CHOOSE" ; |