summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-07-10 11:58:49 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-07-11 00:25:37 -0400
commit217896aa33e40b113fafdaa109d02992f7d9506a (patch)
tree6fa3c21aa9c5fadca9f1e7ca9cdb56a44d370d6a /sc
parent9ed6e520afb8905596cd382e1e7fa79ba20063b5 (diff)
Generate Reverse Polish token array (RPN) at the start.
Change-Id: Idcac01820fab536cebebcc437e206b6900511600
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/formulagroup.hxx3
-rwxr-xr-xsc/source/core/opencl/formulagroupcl.cxx8
-rw-r--r--sc/source/core/tool/formulagroup.cxx13
3 files changed, 18 insertions, 6 deletions
diff --git a/sc/inc/formulagroup.hxx b/sc/inc/formulagroup.hxx
index e64596836c2a..9963fc96ad91 100644
--- a/sc/inc/formulagroup.hxx
+++ b/sc/inc/formulagroup.hxx
@@ -39,6 +39,9 @@ class SC_DLLPUBLIC FormulaGroupInterpreter
protected:
FormulaGroupInterpreter() {}
virtual ~FormulaGroupInterpreter() {}
+
+ static void generateRPNCode(ScDocument& rDoc, const ScAddress& rPos, ScTokenArray& rCode);
+
public:
static FormulaGroupInterpreter *getStatic();
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 8bc0224b874f..04a67d2ea372 100755
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -65,6 +65,8 @@ ScMatrixRef FormulaGroupInterpreterOpenCL::inverseMatrix(const ScMatrix& /* rMat
bool FormulaGroupInterpreterOpenCL::interpret(ScDocument& rDoc, const ScAddress& rTopPos,
const ScFormulaCellGroupRef& xGroup, ScTokenArray& rCode)
{
+ generateRPNCode(rDoc, rTopPos, rCode);
+
size_t rowSize = xGroup->mnLength;
fprintf(stderr,"rowSize at begin is ...%ld.\n",(long)rowSize);
// The row quantity can be gotten from p2->GetArrayLength()
@@ -193,9 +195,7 @@ bool FormulaGroupInterpreterOpenCL::interpret(ScDocument& rDoc, const ScAddress&
if(!getenv("SC_GPU")||!ocl_calc.GetOpenclState())
{
fprintf(stderr,"ccCPU flow...\n\n");
- ScCompiler aComp(&rDoc, aTmpPos, aCode2);
- aComp.SetGrammar(rDoc.GetGrammar());
- aComp.CompileTokenArray(); // Create RPN token array.
+ generateRPNCode(rDoc, aTmpPos, aCode2);
ScInterpreter aInterpreter(pDest, &rDoc, aTmpPos, aCode2);
aInterpreter.Interpret();
pDest->SetResultToken(aInterpreter.GetResultToken().get());
@@ -306,6 +306,8 @@ bool FormulaGroupInterpreterGroundwater::interpret(ScDocument& rDoc, const ScAdd
const ScFormulaCellGroupRef& xGroup,
ScTokenArray& rCode)
{
+ generateRPNCode(rDoc, rTopPos, rCode);
+
// Inputs: both of length xGroup->mnLength
OpCode eOp; // type of operation: ocAverage, ocMax, ocMin
const double *pArrayToSubtractOneElementFrom;
diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx
index 627c5f59db47..5a2351198310 100644
--- a/sc/source/core/tool/formulagroup.cxx
+++ b/sc/source/core/tool/formulagroup.cxx
@@ -96,9 +96,7 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres
if (!pDest)
return false;
- ScCompiler aComp(&rDoc, aTmpPos, aCode2);
- aComp.SetGrammar(rDoc.GetGrammar());
- aComp.CompileTokenArray(); // Create RPN token array.
+ generateRPNCode(rDoc, aTmpPos, aCode2);
ScInterpreter aInterpreter(pDest, &rDoc, aTmpPos, aCode2);
aInterpreter.Interpret();
aResults.push_back(aInterpreter.GetResultToken()->GetDouble());
@@ -190,6 +188,15 @@ FormulaGroupInterpreter *FormulaGroupInterpreter::getStatic()
return msInstance;
}
+void FormulaGroupInterpreter::generateRPNCode(ScDocument& rDoc, const ScAddress& rPos, ScTokenArray& rCode)
+{
+ // First, generate an RPN (reverse polish notation) token array.
+ ScCompiler aComp(&rDoc, rPos, rCode);
+ aComp.SetGrammar(rDoc.GetGrammar());
+ aComp.CompileTokenArray(); // Create RPN token array.
+ // Now, calling FirstRPN() and NextRPN() will return tokens from the RPN token array.
+}
+
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */