[Libreoffice-commits] core.git: 5 commits - formula/source include/formula sc/inc sc/source
Eike Rathke
erack at redhat.com
Fri Apr 17 15:48:54 PDT 2015
formula/source/core/api/FormulaCompiler.cxx | 60 +++++++++++--
include/formula/FormulaCompiler.hxx | 14 +--
sc/inc/compiler.hxx | 10 +-
sc/source/core/tool/compiler.cxx | 124 ++++++++++++++++++++--------
4 files changed, 153 insertions(+), 55 deletions(-)
New commits:
commit 6f0ac5ddf1eedc153e3e46836f885ff59e57fd1a
Author: Eike Rathke <erack at redhat.com>
Date: Sat Apr 18 00:44:06 2015 +0200
TableRef: set 3D flag if table is on different sheet
Change-Id: I1a25d603333b78dc89534e45fa23f99c18bd0ee6
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 64b566c..023e5dc 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -5120,6 +5120,8 @@ bool ScCompiler::HandleTableRef()
{
aRefData.SetRowRel( true);
}
+ if (aRange.aStart.Tab() != aPos.Tab())
+ aRefData.SetFlag3D( true);
aRefData.SetAddress( aRange.aStart, aPos);
pTR->SetAreaRefRPN( pNew->AddSingleReference( aRefData ));
}
@@ -5134,6 +5136,8 @@ bool ScCompiler::HandleTableRef()
aRefData.Ref1.SetRowRel( true);
aRefData.Ref2.SetRowRel( true);
}
+ if (aRange.aStart.Tab() != aPos.Tab())
+ aRefData.Ref1.SetFlag3D( true);
aRefData.SetRange( aRange, aPos);
pTR->SetAreaRefRPN( pNew->AddDoubleReference( aRefData ));
}
commit 8c2173d95c8fd626c5399144d5820a791147bdbf
Author: Eike Rathke <erack at redhat.com>
Date: Sat Apr 18 00:27:28 2015 +0200
TableRef: transform to reference if not supported, i.e. for ODFF
Change-Id: I64f751455fbba901bb41f91daaf64ee4878a19b4
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 64121e6..c8e4678 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1868,6 +1868,44 @@ const FormulaToken* FormulaCompiler::CreateStringFromToken( OUStringBuffer& rBuf
case svIndex:
CreateStringFromIndex( rBuffer, t );
+ if (t->GetOpCode() == ocTableRef && bAllowArrAdvance && mxSymbols->getSymbol( ocTableRefOpen).isEmpty())
+ {
+ // Suppress all TableRef related tokens, the resulting
+ // range was written by CreateStringFromIndex().
+ const FormulaToken* p = pArr->PeekNext();
+ if (p->GetOpCode() == ocTableRefOpen)
+ {
+ p = pArr->Next();
+ int nLevel = 0;
+ do
+ {
+ // Switch cases correspond with those in
+ // ScCompiler::HandleTableRef()
+ switch (p->GetOpCode())
+ {
+ case ocTableRefOpen:
+ ++nLevel;
+ break;
+ case ocTableRefClose:
+ --nLevel;
+ break;
+ case ocTableRefItemAll:
+ case ocTableRefItemHeaders:
+ case ocTableRefItemData:
+ case ocTableRefItemTotals:
+ case ocTableRefItemThisRow:
+ case ocSep:
+ case ocPush:
+ case ocRange:
+ case ocSpaces:
+ break;
+ default:
+ nLevel = 0;
+ bNext = false;
+ }
+ } while (nLevel && (p = pArr->Next()));
+ }
+ }
break;
case svExternal:
{
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 2e1ee10..64b566c 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -4527,13 +4527,52 @@ void ScCompiler::CreateStringFromIndex( OUStringBuffer& rBuffer, const FormulaTo
}
break;
case ocDBArea:
- case ocTableRef:
{
const ScDBData* pDBData = pDoc->GetDBCollection()->getNamedDBs().findByIndex(_pTokenP->GetIndex());
if (pDBData)
aBuffer.append(pDBData->GetName());
}
break;
+ case ocTableRef:
+ {
+ if (mxSymbols->getSymbol( ocTableRefOpen).isEmpty())
+ {
+ // Write the resulting reference if TableRef is not supported.
+ const ScTableRefToken* pTR = dynamic_cast<const ScTableRefToken*>(_pTokenP);
+ if (!pTR)
+ AppendErrorConstant( aBuffer, errNoCode);
+ else
+ {
+ const FormulaToken* pRef = pTR->GetAreaRefRPN();
+ if (!pRef)
+ AppendErrorConstant( aBuffer, errNoCode);
+ else
+ {
+ switch (pRef->GetType())
+ {
+ case svSingleRef:
+ CreateStringFromSingleRef( aBuffer, pRef);
+ break;
+ case svDoubleRef:
+ CreateStringFromDoubleRef( aBuffer, pRef);
+ break;
+ case svError:
+ AppendErrorConstant( aBuffer, pRef->GetError());
+ break;
+ default:
+ AppendErrorConstant( aBuffer, errNoCode);
+ }
+ }
+ }
+ }
+ else
+ {
+ const ScDBData* pDBData = pDoc->GetDBCollection()->getNamedDBs().findByIndex(_pTokenP->GetIndex());
+ if (pDBData)
+ aBuffer.append(pDBData->GetName());
+ }
+ }
+ break;
default:
; // nothing
}
commit 6f25c21eb5cf311d828b77e602a17390af19c962
Author: Eike Rathke <erack at redhat.com>
Date: Fri Apr 17 22:25:20 2015 +0200
const all CreateString... FormulaToken*
Change-Id: I0e0f064357543e5dc86b178ce30ee005e5483e04
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 78861b8..64121e6 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1762,7 +1762,7 @@ void FormulaCompiler::CreateStringFromTokenArray( OUStringBuffer& rBuffer )
if ( pArr->IsRecalcModeForced() )
rBuffer.append( '=');
- FormulaToken* t = pArr->First();
+ const FormulaToken* t = pArr->First();
while( t )
t = CreateStringFromToken( rBuffer, t, true );
@@ -1773,19 +1773,21 @@ void FormulaCompiler::CreateStringFromTokenArray( OUStringBuffer& rBuffer )
}
}
-FormulaToken* FormulaCompiler::CreateStringFromToken( OUString& rFormula, FormulaToken* pTokenP,bool bAllowArrAdvance )
+const FormulaToken* FormulaCompiler::CreateStringFromToken( OUString& rFormula, const FormulaToken* pTokenP,
+ bool bAllowArrAdvance )
{
OUStringBuffer aBuffer;
- FormulaToken* p = CreateStringFromToken( aBuffer, pTokenP, bAllowArrAdvance );
+ const FormulaToken* p = CreateStringFromToken( aBuffer, pTokenP, bAllowArrAdvance );
rFormula += aBuffer.makeStringAndClear();
return p;
}
-FormulaToken* FormulaCompiler::CreateStringFromToken( OUStringBuffer& rBuffer, FormulaToken* pTokenP, bool bAllowArrAdvance )
+const FormulaToken* FormulaCompiler::CreateStringFromToken( OUStringBuffer& rBuffer, const FormulaToken* pTokenP,
+ bool bAllowArrAdvance )
{
bool bNext = true;
bool bSpaces = false;
- FormulaToken* t = pTokenP;
+ const FormulaToken* t = pTokenP;
OpCode eOp = t->GetOpCode();
if( eOp >= ocAnd && eOp <= ocOr )
{
@@ -2116,23 +2118,23 @@ bool FormulaCompiler::HandleTableRef()
return true;
}
-void FormulaCompiler::CreateStringFromSingleRef( OUStringBuffer& /*rBuffer*/, FormulaToken* /*pTokenP*/) const
+void FormulaCompiler::CreateStringFromSingleRef( OUStringBuffer& /*rBuffer*/, const FormulaToken* /*pToken*/) const
{
}
-void FormulaCompiler::CreateStringFromDoubleRef( OUStringBuffer& /*rBuffer*/, FormulaToken* /*pTokenP*/) const
+void FormulaCompiler::CreateStringFromDoubleRef( OUStringBuffer& /*rBuffer*/, const FormulaToken* /*pToken*/) const
{
}
-void FormulaCompiler::CreateStringFromIndex( OUStringBuffer& /*rBuffer*/, FormulaToken* /*pTokenP*/) const
+void FormulaCompiler::CreateStringFromIndex( OUStringBuffer& /*rBuffer*/, const FormulaToken* /*pToken*/) const
{
}
-void FormulaCompiler::CreateStringFromMatrix( OUStringBuffer& /*rBuffer*/, FormulaToken* /*pTokenP*/) const
+void FormulaCompiler::CreateStringFromMatrix( OUStringBuffer& /*rBuffer*/, const FormulaToken* /*pToken*/) const
{
}
-void FormulaCompiler::CreateStringFromExternal( OUStringBuffer& /*rBuffer*/, FormulaToken* /*pTokenP*/) const
+void FormulaCompiler::CreateStringFromExternal( OUStringBuffer& /*rBuffer*/, const FormulaToken* /*pToken*/) const
{
}
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx
index 74d618f..4137e62 100644
--- a/include/formula/FormulaCompiler.hxx
+++ b/include/formula/FormulaCompiler.hxx
@@ -242,9 +242,9 @@ public:
void CreateStringFromTokenArray( OUString& rFormula );
void CreateStringFromTokenArray( OUStringBuffer& rBuffer );
- FormulaToken* CreateStringFromToken( OUString& rFormula, FormulaToken* pToken,
+ const FormulaToken* CreateStringFromToken( OUString& rFormula, const FormulaToken* pToken,
bool bAllowArrAdvance = false );
- FormulaToken* CreateStringFromToken( OUStringBuffer& rBuffer, FormulaToken* pToken,
+ const FormulaToken* CreateStringFromToken( OUStringBuffer& rBuffer, const FormulaToken* pToken,
bool bAllowArrAdvance = false );
void AppendBoolean( OUStringBuffer& rBuffer, bool bVal ) const;
@@ -285,11 +285,11 @@ protected:
virtual bool HandleDbData();
virtual bool HandleTableRef();
- virtual void CreateStringFromExternal(OUStringBuffer& rBuffer, FormulaToken* pTokenP) const;
- virtual void CreateStringFromSingleRef(OUStringBuffer& rBuffer,FormulaToken* pTokenP) const;
- virtual void CreateStringFromDoubleRef(OUStringBuffer& rBuffer,FormulaToken* pTokenP) const;
- virtual void CreateStringFromMatrix(OUStringBuffer& rBuffer,FormulaToken* pTokenP) const;
- virtual void CreateStringFromIndex(OUStringBuffer& rBuffer,FormulaToken* pTokenP) const;
+ virtual void CreateStringFromExternal( OUStringBuffer& rBuffer, const FormulaToken* pToken ) const;
+ virtual void CreateStringFromSingleRef( OUStringBuffer& rBuffer, const FormulaToken* pToken ) const;
+ virtual void CreateStringFromDoubleRef( OUStringBuffer& rBuffer, const FormulaToken* pToken ) const;
+ virtual void CreateStringFromMatrix( OUStringBuffer& rBuffer, const FormulaToken* pToken ) const;
+ virtual void CreateStringFromIndex( OUStringBuffer& rBuffer, const FormulaToken* pToken ) const;
virtual void LocalizeString( OUString& rName ) const; // modify rName - input: exact name
void AppendErrorConstant( OUStringBuffer& rBuffer, sal_uInt16 nError ) const;
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 03baa29..b0d9c71 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -475,11 +475,11 @@ private:
virtual bool HandleTableRef() SAL_OVERRIDE;
virtual formula::FormulaTokenRef ExtendRangeReference( formula::FormulaToken & rTok1, formula::FormulaToken & rTok2, bool bReuseDoubleRef ) SAL_OVERRIDE;
- virtual void CreateStringFromExternal(OUStringBuffer& rBuffer, formula::FormulaToken* pTokenP) const SAL_OVERRIDE;
- virtual void CreateStringFromSingleRef(OUStringBuffer& rBuffer,formula::FormulaToken* _pTokenP) const SAL_OVERRIDE;
- virtual void CreateStringFromDoubleRef(OUStringBuffer& rBuffer,formula::FormulaToken* _pTokenP) const SAL_OVERRIDE;
- virtual void CreateStringFromMatrix( OUStringBuffer& rBuffer, formula::FormulaToken* _pTokenP) const SAL_OVERRIDE;
- virtual void CreateStringFromIndex(OUStringBuffer& rBuffer,formula::FormulaToken* _pTokenP) const SAL_OVERRIDE;
+ virtual void CreateStringFromExternal( OUStringBuffer& rBuffer, const formula::FormulaToken* pToken ) const SAL_OVERRIDE;
+ virtual void CreateStringFromSingleRef( OUStringBuffer& rBuffer, const formula::FormulaToken* pToken ) const SAL_OVERRIDE;
+ virtual void CreateStringFromDoubleRef( OUStringBuffer& rBuffer, const formula::FormulaToken* pToken ) const SAL_OVERRIDE;
+ virtual void CreateStringFromMatrix( OUStringBuffer& rBuffer, const formula::FormulaToken* pToken ) const SAL_OVERRIDE;
+ virtual void CreateStringFromIndex( OUStringBuffer& rBuffer, const formula::FormulaToken* pToken ) const SAL_OVERRIDE;
virtual void LocalizeString( OUString& rName ) const SAL_OVERRIDE; // modify rName - input: exact name
/// Access the CharTable flags
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index c19b29f..2e1ee10 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -4393,9 +4393,9 @@ bool ScCompiler::IsCharFlagAllConventions(
return false;
}
-void ScCompiler::CreateStringFromExternal(OUStringBuffer& rBuffer, FormulaToken* pTokenP) const
+void ScCompiler::CreateStringFromExternal( OUStringBuffer& rBuffer, const FormulaToken* pTokenP ) const
{
- FormulaToken* t = pTokenP;
+ const FormulaToken* t = pTokenP;
sal_uInt16 nFileId = t->GetIndex();
ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
const OUString* pFileName = pRefMgr->getExternalFileName(nFileId);
@@ -4434,8 +4434,7 @@ void ScCompiler::CreateStringFromExternal(OUStringBuffer& rBuffer, FormulaToken*
}
}
-void ScCompiler::CreateStringFromMatrix(
- OUStringBuffer& rBuffer, FormulaToken* pTokenP) const
+void ScCompiler::CreateStringFromMatrix( OUStringBuffer& rBuffer, const FormulaToken* pTokenP ) const
{
const ScMatrix* pMatrix = pTokenP->GetMatrix();
SCSIZE nC, nMaxC, nR, nMaxR;
@@ -4479,7 +4478,7 @@ void ScCompiler::CreateStringFromMatrix(
rBuffer.append( mxSymbols->getSymbol(ocArrayClose) );
}
-void ScCompiler::CreateStringFromSingleRef(OUStringBuffer& rBuffer,FormulaToken* _pTokenP) const
+void ScCompiler::CreateStringFromSingleRef( OUStringBuffer& rBuffer, const FormulaToken* _pTokenP ) const
{
OUString aErrRef = GetCurrentOpCodeMap()->getSymbol(ocErrRef);
const OpCode eOp = _pTokenP->GetOpCode();
@@ -4507,14 +4506,14 @@ void ScCompiler::CreateStringFromSingleRef(OUStringBuffer& rBuffer,FormulaToken*
GetSetupTabNames(), aRef, true);
}
-void ScCompiler::CreateStringFromDoubleRef(OUStringBuffer& rBuffer,FormulaToken* _pTokenP) const
+void ScCompiler::CreateStringFromDoubleRef( OUStringBuffer& rBuffer, const FormulaToken* _pTokenP ) const
{
OUString aErrRef = GetCurrentOpCodeMap()->getSymbol(ocErrRef);
pConv->makeRefStr(rBuffer, meGrammar, aPos, aErrRef, GetSetupTabNames(),
*_pTokenP->GetDoubleRef(), false);
}
-void ScCompiler::CreateStringFromIndex(OUStringBuffer& rBuffer,FormulaToken* _pTokenP) const
+void ScCompiler::CreateStringFromIndex( OUStringBuffer& rBuffer, const FormulaToken* _pTokenP ) const
{
const OpCode eOp = _pTokenP->GetOpCode();
OUStringBuffer aBuffer;
commit aecf1ea0c8ba2cbbe40754d48f22f0a58dbe0cf3
Author: Eike Rathke <erack at redhat.com>
Date: Fri Apr 17 19:47:44 2015 +0200
TableRef: scan any column specifier
Change-Id: I9eb51741d8c5ace52cff70b1954ebde678e6b338
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index d2227cd..c19b29f 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -90,6 +90,7 @@ enum ScanState
ssSkipReference,
ssGetErrorConstant,
ssGetTableRefItem,
+ ssGetTableRefColumn,
ssStop
};
@@ -1901,7 +1902,12 @@ Label_MaskStateMachine:
case ssGetChar :
{
// Order is important!
- if( nMask & SC_COMPILER_C_ODF_LABEL_OP )
+ if (eLastOp == ocTableRefOpen && c != '[' && c != '#' && c != ']')
+ {
+ *pSym++ = c;
+ eState = ssGetTableRefColumn;
+ }
+ else if( nMask & SC_COMPILER_C_ODF_LABEL_OP )
{
// '!!' automatic intersection
if (GetCharTableFlags( pSrc[0], 0 ) & SC_COMPILER_C_ODF_LABEL_OP)
@@ -2213,6 +2219,26 @@ Label_MaskStateMachine:
}
}
break;
+ case ssGetTableRefColumn:
+ {
+ // Scan whatever up to the next unescaped ']' closer.
+ if (c != ']' || cLast == '\'')
+ {
+ if( pSym == &cSymbol[ MAXSTRLEN-1 ] )
+ {
+ SetError( errStringOverflow);
+ eState = ssStop;
+ }
+ else
+ *pSym++ = c;
+ }
+ else
+ {
+ --pSrc;
+ eState = ssStop;
+ }
+ }
+ break;
case ssGetReference:
if( pSym == &cSymbol[ MAXSTRLEN-1 ] )
{
commit c8b9b398fc74cb625f796a0e336c32be21c08b7a
Author: Eike Rathke <erack at redhat.com>
Date: Fri Apr 17 18:43:41 2015 +0200
TableRef: activate for OOXML import
Change-Id: I7ebe365c81af5ee9ea70b2efad8908b360a51a7c
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 63f2dd5..d2227cd 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -362,20 +362,9 @@ ScCompiler::Convention::Convention( FormulaGrammar::AddressConvention eConv )
}
else if (FormulaGrammar::CONV_XL_OOX == meConv)
{
-#if 1
- /* TODO: currently SC_COMPILER_C_CHAR doesn't work as long as the
- * table references aren't implemented. */
-/* [ */ t[91] = SC_COMPILER_C_CHAR_IDENT;
-/* \ */ // FREE
-/* ] */ t[93] = SC_COMPILER_C_IDENT;
-#else
- /* TODO: check if SC_COMPILER_C_CHAR_IDENT and SC_COMPILER_C_IDENT
- * were only added to be able to import table structured
- * reference of a whole table. If so, then remove here. */
/* [ */ t[91] = SC_COMPILER_C_CHAR | SC_COMPILER_C_CHAR_IDENT;
/* \ */ // FREE
/* ] */ t[93] = SC_COMPILER_C_CHAR | SC_COMPILER_C_IDENT;
-#endif
}
else if (FormulaGrammar::CONV_XL_A1 == meConv)
{
@@ -1959,8 +1948,20 @@ Label_MaskStateMachine:
}
else if( nMask & SC_COMPILER_C_CHAR )
{
- *pSym++ = c;
- eState = ssStop;
+ // '[' is a special case in OOXML, it can start an external
+ // reference ID like [1]Sheet1!A1 that needs to be scanned
+ // entirely, or can be ocTableRefOpen, of which the first
+ // transforms an ocDBArea into an ocTableRef.
+ if (c == '[' && FormulaGrammar::isOOXML( meGrammar) && eLastOp != ocDBArea && maTableRefs.empty())
+ {
+ nMask &= ~SC_COMPILER_C_CHAR;
+ goto Label_MaskStateMachine;
+ }
+ else
+ {
+ *pSym++ = c;
+ eState = ssStop;
+ }
}
else if( nMask & SC_COMPILER_C_ODF_LBRACKET )
{
@@ -3010,17 +3011,6 @@ bool ScCompiler::IsExternalNamedRange( const OUString& rSymbol, bool& rbInvalidE
bool ScCompiler::IsDBRange( const OUString& rName )
{
- if (rName == "[]")
- {
- OpCode eOp = maRawToken.GetOpCode();
- if (eOp == ocDBArea || eOp == ocTableRef)
- {
- // In OOXML, a database range is named Table1[], Table2[] etc.
- // Skip the [] part if the previous token is a valid db range.
- maRawToken.eOp = ocSkip;
- return true;
- }
- }
ScDBCollection::NamedDBs& rDBs = pDoc->GetDBCollection()->getNamedDBs();
const ScDBData* p = rDBs.findByUpperName(rName);
if (!p)
More information about the Libreoffice-commits
mailing list