summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-11-07 14:16:48 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-11-11 16:17:28 -0500
commit3ac4277ba1ad8925329bbe8a1c5ed3684b9b8ee7 (patch)
tree70b27ea6a553f1922ecda72ca44d4fd194bc0126
parent6122a6c272436f0f1959f160406d2e4ecdd1a733 (diff)
Thread-safe way to check for presence of references in formula tokens.
Change-Id: I995668d1e183dc0dae4f354889bc13053e858723
-rw-r--r--formula/source/core/api/token.cxx27
-rw-r--r--include/formula/token.hxx5
-rw-r--r--include/formula/tokenarray.hxx2
-rw-r--r--sc/source/core/tool/rangenam.cxx3
4 files changed, 34 insertions, 3 deletions
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 8f0cfa828c5b..ae1655eb9365 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -130,6 +130,22 @@ bool FormulaToken::IsExternalRef() const
return bRet;
}
+bool FormulaToken::IsRef() const
+{
+ switch (eType)
+ {
+ case svSingleRef:
+ case svDoubleRef:
+ case svExternalSingleRef:
+ case svExternalDoubleRef:
+ return true;
+ default:
+ ;
+ }
+
+ return false;
+}
+
bool FormulaToken::operator==( const FormulaToken& rToken ) const
{
// don't compare reference count!
@@ -538,6 +554,17 @@ FormulaToken* FormulaTokenArray::PeekPrevNoSpaces()
return NULL;
}
+bool FormulaTokenArray::HasReferences() const
+{
+ for (sal_uInt16 i = 0; i < nLen; ++i)
+ {
+ if (pCode[i]->IsRef())
+ return true;
+ }
+
+ return false;
+}
+
bool FormulaTokenArray::HasExternalRef() const
{
for ( sal_uInt16 j=0; j < nLen; j++ )
diff --git a/include/formula/token.hxx b/include/formula/token.hxx
index 73f773bcff0e..002cefbb8a21 100644
--- a/include/formula/token.hxx
+++ b/include/formula/token.hxx
@@ -106,7 +106,10 @@ public:
inline void Delete() { delete this; }
inline StackVar GetType() const { return eType; }
bool IsFunction() const; // pure functions, no operators
- bool IsExternalRef() const;
+
+ bool IsExternalRef() const;
+ bool IsRef() const;
+
sal_uInt8 GetParamCount() const;
inline void IncRef() const
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index ddd7d81b5abe..9f8fed0ab27d 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -116,6 +116,8 @@ public:
FormulaToken* LastRPN() { nIndex = nRPN; return PrevRPN(); }
FormulaToken* PrevRPN();
+ bool HasReferences() const;
+
bool HasExternalRef() const;
bool HasOpCode( OpCode ) const;
bool HasOpCodeRPN( OpCode ) const;
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index 6096ecfddd51..c1e28652d2b4 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -518,8 +518,7 @@ sal_uInt16 ScRangeData::GetErrCode() const
bool ScRangeData::HasReferences() const
{
- pCode->Reset();
- return pCode->GetNextReference() != NULL;
+ return pCode->HasReferences();
}
sal_uInt32 ScRangeData::GetUnoType() const