summaryrefslogtreecommitdiff
path: root/include/formula
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2017-06-16 00:18:57 +0300
committerTor Lillqvist <tml@collabora.com>2017-06-16 12:17:40 +0200
commit5c81adc51a05a016e754de7961d3a7bdb4494e01 (patch)
treefbfdca0ef841a545ed10d612df83631c50c24bfc /include/formula
parent468fc3847cfd65217949630e2ffd9fb0a89e9cbb (diff)
Get rid of the index inside FormulaTokenArray
Instead, use FormulaTokenArrrayPlainIterator everywhere, especially in the FormulaCompiler. This is the final step of a long chain of commits. (Split up into many "uncontroversial" bits, and then this, to make potential bisecting easier.) Also added a logging operator<< for FormulaTokenArray, for SAL_DEBUG, SAL_INFO etc goodness. Change-Id: I02fe29f3f1e0dc33e5cba69e594223b4178a12bc Reviewed-on: https://gerrit.libreoffice.org/38851 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'include/formula')
-rw-r--r--include/formula/FormulaCompiler.hxx6
-rw-r--r--include/formula/tokenarray.hxx37
2 files changed, 23 insertions, 20 deletions
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx
index f6650201bba1..a9b65671e4cd 100644
--- a/include/formula/FormulaCompiler.hxx
+++ b/include/formula/FormulaCompiler.hxx
@@ -29,6 +29,7 @@
#include <formula/grammar.hxx>
#include <formula/opcode.hxx>
#include <formula/token.hxx>
+#include <formula/tokenarray.hxx>
#include <formula/types.hxx>
#include <formula/paramclass.hxx>
#include <rtl/ustrbuf.hxx>
@@ -53,12 +54,12 @@ enum class FormulaError : sal_uInt16;
namespace formula
{
- class FormulaTokenArray;
struct FormulaArrayStack
{
FormulaArrayStack* pNext;
FormulaTokenArray* pArr;
+ sal_uInt16 nIndex;
FormulaTokenRef mpLastToken;
bool bTemp;
};
@@ -331,6 +332,7 @@ protected:
FormulaTokenRef pCurrentFactorToken; // current factor token (of Factor() method)
sal_uInt16 nCurrentFactorParam; // current factor token's parameter, 1-based
FormulaTokenArray* pArr;
+ FormulaTokenArrayPlainIterator maArrIterator;
FormulaTokenRef mpLastToken; // last token
FormulaToken** pCode;
@@ -416,6 +418,8 @@ private:
mutable NonConstOpCodeMapPtr mxSymbolsEnglish; // English symbols
mutable NonConstOpCodeMapPtr mxSymbolsEnglishXL; // English Excel symbols (for VBA formula parsing)
mutable NonConstOpCodeMapPtr mxSymbolsOOXML; // Excel OOXML symbols
+
+ static FormulaTokenArray smDummyTokenArray;
};
} // formula
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index 72cb0e5a400a..8a00c0287126 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -22,6 +22,7 @@
#include <climits>
#include <memory>
+#include <ostream>
#include <type_traits>
#include <unordered_set>
#include <unordered_map>
@@ -123,7 +124,6 @@ protected:
FormulaToken** pRPN; // RPN array
sal_uInt16 nLen; // Length of token array
sal_uInt16 nRPN; // Length of RPN array
- sal_uInt16 nIndex; // Current step index
FormulaError nError; // Error code
ScRecalcMode nMode; // Flags to indicate when to recalc this code
bool bHyperLink :1; // If HYPERLINK() occurs in the formula.
@@ -161,9 +161,7 @@ protected:
/** Remove a sequence of tokens from pCode array, and pRPN array if the
tokens are referenced there.
- This' nLen and nRPN are adapted, as is nIndex if it points behind
- nOffset. If nIndex points into the to be removed range
- (nOffset < nIndex < nOffset+nCount) it is set to nOffset+1.
+ nLen and nRPN are adapted.
@param nOffset
Start offset into pCode.
@@ -205,24 +203,10 @@ public:
void Clear();
void DelRPN();
- FormulaToken* First() { nIndex = 0; return Next(); }
FormulaToken* FirstToken() const;
- FormulaToken* Next();
- FormulaToken* NextNoSpaces();
- FormulaToken* GetNextName();
- FormulaToken* GetNextReference();
- FormulaToken* GetNextReferenceRPN();
- FormulaToken* GetNextReferenceOrName();
- FormulaToken* GetNextColRowName();
/// Peek at nIdx-1 if not out of bounds, decrements nIdx if successful. Returns NULL if not.
FormulaToken* PeekPrev( sal_uInt16 & nIdx );
- FormulaToken* PeekNext();
- FormulaToken* PeekPrevNoSpaces(); /// Only after Reset/First/Next/Last/Prev!
- FormulaToken* PeekNextNoSpaces(); /// Only after Reset/First/Next/Last/Prev!
FormulaToken* FirstRPNToken() const;
- FormulaToken* NextRPN();
- FormulaToken* LastRPN() { nIndex = nRPN; return PrevRPN(); }
- FormulaToken* PrevRPN();
bool HasReferences() const;
@@ -246,7 +230,6 @@ public:
FormulaToken** GetCode() const { return pRPN; }
sal_uInt16 GetLen() const { return nLen; }
sal_uInt16 GetCodeLen() const { return nRPN; }
- void Reset() { nIndex = 0; }
FormulaError GetCodeError() const { return nError; }
void SetCodeError( FormulaError n ) { nError = n; }
void SetHyperLink( bool bVal ) { bHyperLink = bVal; }
@@ -407,6 +390,22 @@ private:
const FormulaToken* GetNonEndOfPathToken( short nIdx ) const;
};
+// For use in SAL_INFO, SAL_WARN etc
+
+template<typename charT, typename traits>
+inline std::basic_ostream<charT, traits> & operator <<(std::basic_ostream<charT, traits> & stream, const FormulaTokenArray& point)
+{
+ stream <<
+ static_cast<const void*>(&point) <<
+ ":{nLen=" << point.GetLen() <<
+ ",nRPN=" << point.GetCodeLen() <<
+ ",pCode=" << static_cast<void*>(point.GetArray()) <<
+ ",pRPN=" << static_cast<void*>(point.GetCode()) <<
+ "}";
+
+ return stream;
+}
+
class FORMULA_DLLPUBLIC FormulaTokenArrayPlainIterator
{
friend class FormulaCompiler;