[Libreoffice-commits] core.git: 4 commits - formula/source include/formula sc/source
Eike Rathke
erack at redhat.com
Wed Jun 8 10:13:51 UTC 2016
formula/source/core/api/token.cxx | 26 ++++++++++++++++++++++++++
include/formula/token.hxx | 22 ++++++++++++++++++++++
sc/source/core/data/dptabsrc.cxx | 2 +-
sc/source/core/inc/interpre.hxx | 2 ++
sc/source/core/tool/interpr2.cxx | 24 ++++++++++++++----------
sc/source/core/tool/interpr4.cxx | 21 ++++++++++++++++++---
6 files changed, 83 insertions(+), 14 deletions(-)
New commits:
commit bd8d91e9deed91ca63b8149b1c32a2ce2c962c6b
Author: Eike Rathke <erack at redhat.com>
Date: Wed Jun 8 12:12:24 2016 +0200
use the new type information we now transport, tdf#35247 related
Change-Id: I47e9bf8e7012024f3bf715569ab0192f973d2a2f
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 343f571..1abe634 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -3311,12 +3311,16 @@ void ScInterpreter::ScGetPivotData()
* not be on a (even if locale independent) formatted string down
* below in pDPObj->GetPivotData(). */
- /* TODO: obtaining the current format before a double is popped
- * works only by chance, e.g. if the very recent function call was
- * DATE() or some such. We really need to transport format/type
- * information in tokens. */
- short nThisFmtType = nCurFmtType;
- sal_uInt32 nThisFmtIndex = nCurFmtIndex;
+ bool bEvaluateFormatIndex;
+ switch (GetRawStackType())
+ {
+ case svSingleRef:
+ case svDoubleRef:
+ bEvaluateFormatIndex = true;
+ break;
+ default:
+ bEvaluateFormatIndex = false;
+ }
double fDouble;
svl::SharedString aSharedString;
@@ -3330,14 +3334,14 @@ void ScInterpreter::ScGetPivotData()
if (bDouble)
{
sal_uInt32 nNumFormat;
- if (nThisFmtIndex)
- nNumFormat = nThisFmtIndex;
+ if (bEvaluateFormatIndex && nCurFmtIndex)
+ nNumFormat = nCurFmtIndex;
else
{
- if (nThisFmtType == css::util::NumberFormat::UNDEFINED)
+ if (nCurFmtType == css::util::NumberFormat::UNDEFINED)
nNumFormat = 0;
else
- nNumFormat = pFormatter->GetStandardFormat( nThisFmtType, ScGlobal::eLnge);
+ nNumFormat = pFormatter->GetStandardFormat( nCurFmtType, ScGlobal::eLnge);
}
Color* pColor;
pFormatter->GetOutputString( fDouble, nNumFormat, aFilters[i].MatchValueName, &pColor);
commit 86d8893c270dcca6b29a8b7dd15654089481af4d
Author: Eike Rathke <erack at redhat.com>
Date: Wed Jun 8 12:08:46 2016 +0200
use FormulaTypedDoubleToken in PushDouble() for temporary interim results
... and extract type information in PopDouble()
Change-Id: Ib184a8d893bf1072d051a80259b44f6e28fc9271
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 5b1c2fe..629c6c0 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -354,6 +354,8 @@ ScMatrixRef PopMatrix();
sc::RangeMatrix PopRangeMatrix();
void QueryMatrixType(ScMatrixRef& xMat, short& rRetTypeExpr, sal_uLong& rRetIndexExpr);
+formula::FormulaToken* CreateDoubleOrTypedToken( double fVal );
+
void PushDouble(double nVal);
void PushInt( int nVal );
void PushStringBuffer( const sal_Unicode* pString );
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index a9363a7..f846cef 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -812,7 +812,12 @@ double ScInterpreter::PopDouble()
nGlobalError = p->GetError();
break;
case svDouble:
- return p->GetDouble();
+ {
+ short nType = p->GetDoubleType();
+ if (nType && nType != css::util::NumberFormat::UNDEFINED)
+ nCurFmtType = nType;
+ return p->GetDouble();
+ }
case svEmptyCell:
case svMissing:
return 0.0;
@@ -1650,17 +1655,27 @@ void ScInterpreter::QueryMatrixType(ScMatrixRef& xMat, short& rRetTypeExpr, sal_
SetError( errUnknownStackVariable);
}
+formula::FormulaToken* ScInterpreter::CreateDoubleOrTypedToken( double fVal )
+{
+ // NumberFormat::NUMBER is the default untyped double.
+ if (nFuncFmtType && nFuncFmtType != css::util::NumberFormat::NUMBER &&
+ nFuncFmtType != css::util::NumberFormat::UNDEFINED)
+ return new FormulaTypedDoubleToken( fVal, nFuncFmtType);
+ else
+ return new FormulaDoubleToken( fVal);
+}
+
void ScInterpreter::PushDouble(double nVal)
{
TreatDoubleError( nVal );
if (!IfErrorPushError())
- PushTempTokenWithoutError( new FormulaDoubleToken( nVal ) );
+ PushTempTokenWithoutError( CreateDoubleOrTypedToken( nVal));
}
void ScInterpreter::PushInt(int nVal)
{
if (!IfErrorPushError())
- PushTempTokenWithoutError( new FormulaDoubleToken( nVal ) );
+ PushTempTokenWithoutError( CreateDoubleOrTypedToken( nVal));
}
void ScInterpreter::PushStringBuffer( const sal_Unicode* pString )
commit 1ec01a340a063ef6d1b773e6a693c09234bd4f27
Author: Eike Rathke <erack at redhat.com>
Date: Wed Jun 8 12:03:39 2016 +0200
introduce FormulaTypedDoubleToken to carry type information of a double
Change-Id: I88b4964ca95eefa41d415ed66fc106c834a686b6
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 360449f..a32853c 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -42,6 +42,8 @@ namespace formula
// Need a lot of FormulaDoubleToken
IMPL_FIXEDMEMPOOL_NEWDEL_DLL( FormulaDoubleToken )
+// Need quite some FormulaTypedDoubleToken
+IMPL_FIXEDMEMPOOL_NEWDEL_DLL( FormulaTypedDoubleToken )
// Need a lot of FormulaByteToken
IMPL_FIXEDMEMPOOL_NEWDEL_DLL( FormulaByteToken )
// Need several FormulaStringToken
@@ -199,6 +201,12 @@ double & FormulaToken::GetDoubleAsReference()
return fVal;
}
+short FormulaToken::GetDoubleType() const
+{
+ SAL_WARN( "formula.core", "FormulaToken::GetDoubleType: virtual dummy called" );
+ return 0;
+}
+
svl::SharedString FormulaToken::GetString() const
{
SAL_WARN( "formula.core", "FormulaToken::GetString: virtual dummy called" );
@@ -1656,11 +1664,29 @@ bool FormulaTokenIterator::IsEndOfPath() const
double FormulaDoubleToken::GetDouble() const { return fDouble; }
double & FormulaDoubleToken::GetDoubleAsReference() { return fDouble; }
+
+short FormulaDoubleToken::GetDoubleType() const
+{
+ // This is a plain double value without type information, don't emit a
+ // warning via FormulaToken::GetDoubleType().
+ return 0;
+}
+
bool FormulaDoubleToken::operator==( const FormulaToken& r ) const
{
return FormulaToken::operator==( r ) && fDouble == r.GetDouble();
}
+short FormulaTypedDoubleToken::GetDoubleType() const
+{
+ return mnType;
+}
+
+bool FormulaTypedDoubleToken::operator==( const FormulaToken& r ) const
+{
+ return FormulaDoubleToken::operator==( r ) && mnType == r.GetDoubleType();
+}
+
FormulaStringToken::FormulaStringToken( const svl::SharedString& r ) :
FormulaToken( svString ), maString( r )
{
diff --git a/include/formula/token.hxx b/include/formula/token.hxx
index 3d265f6..f195b68 100644
--- a/include/formula/token.hxx
+++ b/include/formula/token.hxx
@@ -151,6 +151,7 @@ public:
virtual void SetInForceArray( bool b );
virtual double GetDouble() const;
virtual double& GetDoubleAsReference();
+ virtual short GetDoubleType() const;
virtual svl::SharedString GetString() const;
virtual void SetString( const svl::SharedString& rStr );
virtual sal_uInt16 GetIndex() const;
@@ -270,11 +271,32 @@ public:
virtual FormulaToken* Clone() const override { return new FormulaDoubleToken(*this); }
virtual double GetDouble() const override;
virtual double& GetDoubleAsReference() override;
+ virtual short GetDoubleType() const override; ///< always returns 0 for "not typed"
virtual bool operator==( const FormulaToken& rToken ) const override;
DECL_FIXEDMEMPOOL_NEWDEL_DLL( FormulaDoubleToken )
};
+class FORMULA_DLLPUBLIC FormulaTypedDoubleToken : public FormulaDoubleToken
+{
+private:
+ short mnType; /**< Can hold, for example, a value
+ of css::util::NumberFormat, or by
+ contract any other
+ classification. */
+public:
+ FormulaTypedDoubleToken( double f, short nType ) :
+ FormulaDoubleToken( f ), mnType( nType ) {}
+ FormulaTypedDoubleToken( const FormulaTypedDoubleToken& r ) :
+ FormulaDoubleToken( r ), mnType( r.mnType ) {}
+
+ virtual FormulaToken* Clone() const override { return new FormulaTypedDoubleToken(*this); }
+ virtual short GetDoubleType() const override;
+ virtual bool operator==( const FormulaToken& rToken ) const override;
+
+ DECL_FIXEDMEMPOOL_NEWDEL_DLL( FormulaTypedDoubleToken )
+};
+
class FORMULA_DLLPUBLIC FormulaStringToken : public FormulaToken
{
commit e24bedbb73a000b204069dde432965b503a7120c
Author: Eike Rathke <erack at redhat.com>
Date: Tue Jun 7 21:15:38 2016 +0200
ScDPResultTree::ValuesType can be empty
Change-Id: I1a1213b6d887c1a2f0bfb5c8946e5bd67043cd01
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index b572614..eb6052c 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -400,7 +400,7 @@ uno::Sequence<double> ScDPSource::getFilteredResults(
// Get result values from the tree.
const ScDPResultTree::ValuesType* pVals = maResFilterSet.getResults(aFilters);
- if (pVals)
+ if (pVals && !pVals->empty())
{
size_t n = pVals->size();
uno::Sequence<double> aRet(n);
More information about the Libreoffice-commits
mailing list