[Libreoffice-commits] core.git: 2 commits - include/formula sc/source
Eike Rathke
erack at redhat.com
Mon Dec 2 13:06:46 PST 2013
include/formula/FormulaCompiler.hxx | 3 +
include/formula/grammar.hxx | 7 ++++
sc/source/core/tool/compiler.cxx | 56 +++++++++++++++++++++++++-----------
3 files changed, 49 insertions(+), 17 deletions(-)
New commits:
commit 0f8eef96d28245b4905ff9f1cfb18bc540f0f7b5
Author: Eike Rathke <erack at redhat.com>
Date: Mon Dec 2 21:55:43 2013 +0100
in .xlsx import append a parameter for CEILING, FLOOR and WEEKNUM again
7a3b8b1a5a753627c6518b9a5b8e2a041d4d6331 switched formula parsing from
API FormulaParser::importFormula() / ApiParserWrapper::parseFormula() to
ScCompiler, which means that also FormulaFinalizer::finalizeTokenArray()
is not executed anymore and processTokens() and processParameters() that
among others handled appending Calc-only and required parameters.
At least implement that parameter part at ScCompiler now.
Change-Id: Iaa2804c82ec43dd51f781485b0e2afab8c613638
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 55b10c3..496c151 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -3632,16 +3632,18 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
struct FunctionStack
{
OpCode eOp;
- short nPar;
+ short nSep;
};
- // FunctionStack only used if PODF!
+ // FunctionStack only used if PODF or OOXML!
bool bPODF = FormulaGrammar::isPODF( meGrammar);
+ bool bOOXML = FormulaGrammar::isOOXML( meGrammar);
+ bool bUseFunctionStack = (bPODF || bOOXML);
const size_t nAlloc = 512;
FunctionStack aFuncs[ nAlloc ];
- FunctionStack* pFunctionStack =
- (bPODF && static_cast<size_t>(rFormula.getLength()) > nAlloc ? new FunctionStack[rFormula.getLength()] : &aFuncs[0]);
+ FunctionStack* pFunctionStack = (bUseFunctionStack && static_cast<size_t>(rFormula.getLength()) > nAlloc ?
+ new FunctionStack[rFormula.getLength()] : &aFuncs[0]);
pFunctionStack[0].eOp = ocNone;
- pFunctionStack[0].nPar = 0;
+ pFunctionStack[0].nSep = 0;
size_t nFunction = 0;
short nBrackets = 0;
bool bInArray = false;
@@ -3657,11 +3659,11 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
case ocOpen:
{
++nBrackets;
- if (bPODF)
+ if (bUseFunctionStack)
{
++nFunction;
pFunctionStack[ nFunction ].eOp = eLastOp;
- pFunctionStack[ nFunction ].nPar = 0;
+ pFunctionStack[ nFunction ].nSep = 0;
}
}
break;
@@ -3678,14 +3680,14 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
}
else
nBrackets--;
- if (bPODF && nFunction)
+ if (bUseFunctionStack && nFunction)
--nFunction;
}
break;
case ocSep:
{
- if (bPODF)
- ++pFunctionStack[ nFunction ].nPar;
+ if (bUseFunctionStack)
+ ++pFunctionStack[ nFunction ].nSep;
}
break;
case ocArrayOpen:
@@ -3695,11 +3697,11 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
else
bInArray = true;
// Don't count following column separator as parameter separator.
- if (bPODF)
+ if (bUseFunctionStack)
{
++nFunction;
pFunctionStack[ nFunction ].eOp = eOp;
- pFunctionStack[ nFunction ].nPar = 0;
+ pFunctionStack[ nFunction ].nSep = 0;
}
}
break;
@@ -3718,7 +3720,7 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
aCorrectedSymbol = "";
}
}
- if (bPODF && nFunction)
+ if (bUseFunctionStack && nFunction)
--nFunction;
}
default:
@@ -3741,21 +3743,41 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
SetError(errCodeOverflow); break;
}
}
- if (bPODF)
+ if (bOOXML)
+ {
+ // Append a parameter for CEILING, FLOOR and WEEKNUM, all 1.0
+ // Function is already closed, parameter count is nSep+1
+ size_t nFunc = nFunction + 1;
+ if (eOp == ocClose && (
+ (pFunctionStack[ nFunc ].eOp == ocCeil && // 3rd Excel mode
+ pFunctionStack[ nFunc ].nSep == 1) ||
+ (pFunctionStack[ nFunc ].eOp == ocFloor && // 3rd Excel mode
+ pFunctionStack[ nFunc ].nSep == 1) ||
+ (pFunctionStack[ nFunc ].eOp == ocWeek && // 2nd week start
+ pFunctionStack[ nFunc ].nSep == 0)))
+ {
+ if ( !static_cast<ScTokenArray*>(pArr)->Add( new FormulaToken( svSep, ocSep)) ||
+ !static_cast<ScTokenArray*>(pArr)->Add( new FormulaDoubleToken( 1.0)))
+ {
+ SetError(errCodeOverflow); break;
+ }
+ }
+ }
+ else if (bPODF)
{
/* TODO: for now this is the only PODF adapter. If there were more,
* factor this out. */
// Insert ADDRESS() new empty parameter 4 if there is a 4th, now to be 5th.
if (eOp == ocSep &&
pFunctionStack[ nFunction ].eOp == ocAddress &&
- pFunctionStack[ nFunction ].nPar == 3)
+ pFunctionStack[ nFunction ].nSep == 3)
{
- if (!static_cast<ScTokenArray*>(pArr)->Add( new FormulaToken( svSep,ocSep)) ||
+ if ( !static_cast<ScTokenArray*>(pArr)->Add( new FormulaToken( svSep, ocSep)) ||
!static_cast<ScTokenArray*>(pArr)->Add( new FormulaDoubleToken( 1.0)))
{
SetError(errCodeOverflow); break;
}
- ++pFunctionStack[ nFunction ].nPar;
+ ++pFunctionStack[ nFunction ].nSep;
}
}
FormulaToken* pNewToken = static_cast<ScTokenArray*>(pArr)->Add( pRawToken->CreateToken());
commit 5a5b35c979acf303d99a365b6735148d4f0ab817
Author: Eike Rathke <erack at redhat.com>
Date: Mon Dec 2 20:18:43 2013 +0100
added isOOXML()
Change-Id: I9e088e1d6679297884d71604b03537b73ee3387c
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx
index a90bc82..591103a 100644
--- a/include/formula/FormulaCompiler.hxx
+++ b/include/formula/FormulaCompiler.hxx
@@ -156,6 +156,9 @@ public:
/// Is it an ODFF / ODF 1.2 mapping?
inline bool isODFF() const { return FormulaGrammar::isODFF( meGrammar); }
+ /// Is it an OOXML mapping?
+ inline bool isOOXML() const { return FormulaGrammar::isOOXML( meGrammar); }
+
/// Does it have external symbol/name mappings?
inline bool hasExternals() const { return !mpExternalHashMap->empty(); }
diff --git a/include/formula/grammar.hxx b/include/formula/grammar.hxx
index e3f29de..1971c4f 100644
--- a/include/formula/grammar.hxx
+++ b/include/formula/grammar.hxx
@@ -244,6 +244,13 @@ public:
::com::sun::star::sheet::FormulaLanguage::ODFF;
}
+ /// If grammar is of OOXML
+ static inline bool isOOXML( const Grammar eGrammar )
+ {
+ return extractFormulaLanguage( eGrammar) ==
+ ::com::sun::star::sheet::FormulaLanguage::OOXML;
+ }
+
};
// =============================================================================
} // formula
More information about the Libreoffice-commits
mailing list