[Libreoffice-commits] core.git: formula/source include/formula
Tor Lillqvist
tml at collabora.com
Tue Jun 6 18:13:59 UTC 2017
formula/source/core/api/token.cxx | 167 ++++++++++++++++++++++++++++++++++++++
include/formula/tokenarray.hxx | 69 +++++++++++++++
2 files changed, 236 insertions(+)
New commits:
commit c2b256084b086b63a13d16f65d1be2966f4febb3
Author: Tor Lillqvist <tml at collabora.com>
Date: Tue Jun 6 19:37:16 2017 +0300
Partial start of separating the iterator out from FormulaTokenArray
The plan is to drop the iterator functionality from FormulaTokenArray
and instead use separate iterator objects. This will make
parallelising code that uses these data structures easier. I call the
new separate iterator class FormulaTokenArrayPlainIterator for now,
feel free to come up with a better name.
No change to what code actually gets run yet, so yeah, this adds
"unused" code.
Change-Id: Ie86f80529354174f0ce8bde1085a54bc6c5ac67b
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 63afd00cfc36..703c0eca5c29 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -1757,6 +1757,173 @@ bool FormulaTokenIterator::IsEndOfPath() const
return GetNonEndOfPathToken( maStack.back().nPC + 1) == nullptr;
}
+FormulaToken* FormulaTokenArrayPlainIterator::GetNextReference()
+{
+ while( mnIndex < mrFTA.nLen )
+ {
+ FormulaToken* t = mrFTA.pCode[ mnIndex++ ];
+ switch( t->GetType() )
+ {
+ case svSingleRef:
+ case svDoubleRef:
+ case svExternalSingleRef:
+ case svExternalDoubleRef:
+ return t;
+ default:
+ {
+ // added to avoid warnings
+ }
+ }
+ }
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::GetNextColRowName()
+{
+ while( mnIndex < mrFTA.nLen )
+ {
+ FormulaToken* t = mrFTA.pCode[ mnIndex++ ];
+ if ( t->GetOpCode() == ocColRowName )
+ return t;
+ }
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::GetNextReferenceRPN()
+{
+ while( mnIndex < mrFTA.nRPN )
+ {
+ FormulaToken* t = mrFTA.pRPN[ mnIndex++ ];
+ switch( t->GetType() )
+ {
+ case svSingleRef:
+ case svDoubleRef:
+ case svExternalSingleRef:
+ case svExternalDoubleRef:
+ return t;
+ default:
+ {
+ // added to avoid warnings
+ }
+ }
+ }
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::GetNextReferenceOrName()
+{
+ if( mrFTA.pCode )
+ {
+ while ( mnIndex < mrFTA.nLen )
+ {
+ FormulaToken* t = mrFTA.pCode[ mnIndex++ ];
+ switch( t->GetType() )
+ {
+ case svSingleRef:
+ case svDoubleRef:
+ case svIndex:
+ case svExternalSingleRef:
+ case svExternalDoubleRef:
+ case svExternalName:
+ return t;
+ default:
+ {
+ // added to avoid warnings
+ }
+ }
+ }
+ }
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::Next()
+{
+ if( mrFTA.pCode && mnIndex < mrFTA.nLen )
+ return mrFTA.pCode[ mnIndex++ ];
+ else
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::NextNoSpaces()
+{
+ if( mrFTA.pCode )
+ {
+ while( (mnIndex < mrFTA.nLen) && (mrFTA.pCode[ mnIndex ]->GetOpCode() == ocSpaces) )
+ ++mnIndex;
+ if( mnIndex < mrFTA.nLen )
+ return mrFTA.pCode[ mnIndex++ ];
+ }
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::NextRPN()
+{
+ if( mrFTA.pRPN && mnIndex < mrFTA.nRPN )
+ return mrFTA.pRPN[ mnIndex++ ];
+ else
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::PrevRPN()
+{
+ if( mrFTA.pRPN && mnIndex )
+ return mrFTA.pRPN[ --mnIndex ];
+ else
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::PeekNext()
+{
+ if( mrFTA.pCode && mnIndex < mrFTA.nLen )
+ return mrFTA.pCode[ mnIndex ];
+ else
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::PeekNextNoSpaces() const
+{
+ if( mrFTA.pCode && mnIndex < mrFTA.nLen )
+ {
+ sal_uInt16 j = mnIndex;
+ while ( j < mrFTA.nLen && mrFTA.pCode[j]->GetOpCode() == ocSpaces )
+ j++;
+ if ( j < mrFTA.nLen )
+ return mrFTA.pCode[ j ];
+ else
+ return nullptr;
+ }
+ else
+ return nullptr;
+}
+
+FormulaToken* FormulaTokenArrayPlainIterator::PeekPrevNoSpaces() const
+{
+ if( mrFTA.pCode && mnIndex > 1 )
+ {
+ sal_uInt16 j = mnIndex - 2;
+ while ( mrFTA.pCode[j]->GetOpCode() == ocSpaces && j > 0 )
+ j--;
+ if ( j > 0 || mrFTA.pCode[j]->GetOpCode() != ocSpaces )
+ return mrFTA.pCode[ j ];
+ else
+ return nullptr;
+ }
+ else
+ return nullptr;
+}
+
+void FormulaTokenArrayPlainIterator::AfterRemoveToken( sal_uInt16 nOffset, sal_uInt16 nCount )
+{
+ const sal_uInt16 nStop = std::min( static_cast<sal_uInt16>(nOffset + nCount), mrFTA.nLen);
+
+ if (mnIndex >= nOffset)
+ {
+ if (mnIndex < nStop)
+ mnIndex = nOffset + 1;
+ else
+ mnIndex -= nStop - nOffset;
+ }
+}
// real implementations of virtual functions
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index f7a8228a0d0e..575ead626286 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -115,6 +115,7 @@ class FORMULA_DLLPUBLIC FormulaTokenArray
{
friend class FormulaCompiler;
friend class FormulaTokenIterator;
+ friend class FormulaTokenArrayPlainIterator;
friend class FormulaMissingContext;
protected:
@@ -404,6 +405,74 @@ public:
private:
const FormulaToken* GetNonEndOfPathToken( short nIdx ) const;
};
+
+class FORMULA_DLLPUBLIC FormulaTokenArrayPlainIterator
+{
+ friend class FormulaCompiler;
+
+private:
+ const FormulaTokenArray& mrFTA;
+ sal_uInt16 mnIndex; // Current step index
+
+public:
+ FormulaTokenArrayPlainIterator( const FormulaTokenArray& rFTA ) :
+ mrFTA( rFTA ),
+ mnIndex( 0 )
+ {
+ }
+
+ void Reset()
+ {
+ mnIndex = 0;
+ }
+
+ sal_uInt16 GetIndex() const
+ {
+ return mnIndex;
+ }
+
+ FormulaToken* First()
+ {
+ mnIndex = 0;
+ return Next();
+ }
+
+ void Jump(sal_uInt16 nIndex)
+ {
+ mnIndex = nIndex;
+ }
+
+ FormulaToken* Next();
+ FormulaToken* NextNoSpaces();
+ FormulaToken* GetNextName();
+ FormulaToken* GetNextReference();
+ FormulaToken* GetNextReferenceRPN();
+ FormulaToken* GetNextReferenceOrName();
+ FormulaToken* GetNextColRowName();
+ FormulaToken* PeekNext();
+ FormulaToken* PeekPrevNoSpaces() const; /// Only after Reset/First/Next/Last/Prev!
+ FormulaToken* PeekNextNoSpaces() const; /// Only after Reset/First/Next/Last/Prev!
+
+ FormulaToken* FirstRPN()
+ {
+ mnIndex = 0;
+ return NextRPN();
+ }
+
+ FormulaToken* NextRPN();
+
+ FormulaToken* LastRPN()
+ {
+ mnIndex = mrFTA.nRPN;
+ return PrevRPN();
+ }
+
+ FormulaToken* PrevRPN();
+
+ void AfterRemoveToken( sal_uInt16 nOffset, sal_uInt16 nCount );
+};
+
+
} // formula
#endif // INCLUDED_FORMULA_TOKENARRAY_HXX
More information about the Libreoffice-commits
mailing list