diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-02-04 13:46:43 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-02-04 13:49:09 -0500 |
commit | 295a55b647e030d3705b930bde7508cd8b058b52 (patch) | |
tree | 0c3db5b3895d3c44f7bc89537ddb68013af225fb /sc | |
parent | 8c01b81e81bd0598932c32bd47e59a1029660dd4 (diff) |
Use CompileFormulaContext in CompileDBFormula() and CalcAfterLoad().
Also make some adjustment in order to handle formula cell's "temp grammar"
correctly.
Change-Id: I6fdd5c67bb95e4de90ea71db624c9610c1e2febf
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/column.hxx | 6 | ||||
-rw-r--r-- | sc/inc/compiler.hxx | 2 | ||||
-rw-r--r-- | sc/inc/formulacell.hxx | 6 | ||||
-rw-r--r-- | sc/inc/table.hxx | 6 | ||||
-rw-r--r-- | sc/inc/tokenstringcontext.hxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/column.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/column2.cxx | 11 | ||||
-rw-r--r-- | sc/source/core/data/documen4.cxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 24 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 5 | ||||
-rw-r--r-- | sc/source/core/data/table4.cxx | 5 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/tool/tokenstringcontext.cxx | 32 |
14 files changed, 94 insertions, 46 deletions
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 7621961af185..3c8a641bd3f5 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -59,7 +59,7 @@ class DocumentStreamAccess; class CellValues; struct RowSpan; class RowHeightContext; -struct CompileFormulaContext; +class CompileFormulaContext; } @@ -335,7 +335,7 @@ public: void SetDirtyAfterLoad(); void SetTableOpDirty( const ScRange& ); void CalcAll(); - void CalcAfterLoad(); + void CalcAfterLoad( sc::CompileFormulaContext& rCxt ); void CompileAll(); void CompileXML( ScProgress& rProgress ); @@ -463,7 +463,7 @@ public: void BroadcastRecalcOnRefMove(); void CompileDBFormula(); - void CompileDBFormula( bool bCreateFormulaString ); + void CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ); void CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ); void CompileColRowNameFormula(); diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index c9b4c2071eb6..a9f2d83edc3f 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -80,7 +80,7 @@ class ScTokenArray; namespace sc { -struct CompileFormulaContext; +class CompileFormulaContext; } diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 0c572c55f483..bd4f128f2dc0 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -44,7 +44,7 @@ struct RefUpdateContext; struct RefUpdateInsertTabContext; struct RefUpdateDeleteTabContext; struct RefUpdateMoveTabContext; -struct CompileFormulaContext; +class CompileFormulaContext; } @@ -230,7 +230,7 @@ public: void CompileTokenArray( bool bNoListening = false ); void CompileTokenArray( sc::CompileFormulaContext& rCxt, bool bNoListening = false ); void CompileXML( ScProgress& rProgress ); // compile temporary string tokens - void CalcAfterLoad(); + void CalcAfterLoad( sc::CompileFormulaContext& rCxt ); bool MarkUsedExternalReferences(); void Interpret(); bool IsIterCell() const; @@ -293,7 +293,7 @@ public: bool IsRunning() const; void SetRunning( bool bVal ); void CompileDBFormula(); - void CompileDBFormula( bool bCreateFormulaString ); + void CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ); void CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ); void CompileColRowNameFormula(); ScFormulaCell* GetPrevious() const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 1c7cb126baca..330ca2c6e2d7 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -70,7 +70,7 @@ struct NoteEntry; class DocumentStreamAccess; class CellValues; class RowHeightContext; -struct CompileFormulaContext; +class CompileFormulaContext; } @@ -520,7 +520,7 @@ public: void SetDirtyVar(); void SetTableOpDirty( const ScRange& ); void CalcAll(); - void CalcAfterLoad(); + void CalcAfterLoad( sc::CompileFormulaContext& rCxt ); void CompileAll(); void CompileXML( ScProgress& rProgress ); @@ -1013,7 +1013,7 @@ private: bool GetNextMarkedCell( SCCOL& rCol, SCROW& rRow, const ScMarkData& rMark ) const; bool TestTabRefAbs(SCTAB nTable) const; void CompileDBFormula(); - void CompileDBFormula( bool bCreateFormulaString ); + void CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ); void CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ); void CompileColRowNameFormula(); void RebuildFormulaGroups(); diff --git a/sc/inc/tokenstringcontext.hxx b/sc/inc/tokenstringcontext.hxx index fcc7eae42acf..af97d999c37e 100644 --- a/sc/inc/tokenstringcontext.hxx +++ b/sc/inc/tokenstringcontext.hxx @@ -46,13 +46,23 @@ struct SC_DLLPUBLIC TokenStringContext TokenStringContext( const ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ); }; -struct CompileFormulaContext +class CompileFormulaContext { ScDocument* mpDoc; formula::FormulaGrammar::Grammar meGram; std::vector<OUString> maTabNames; + void updateTabNames(); + +public: CompileFormulaContext( ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ); + + formula::FormulaGrammar::Grammar getGrammar() const; + void setGrammar( formula::FormulaGrammar::Grammar eGram ); + + const std::vector<OUString>& getTabNames() const; + + ScDocument* getDoc(); }; } diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index f65c3c72063f..ba0e72db8619 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -2912,11 +2912,15 @@ public: bool isCompiled() const { return mbCompiled; } }; -struct CalcAfterLoadHandler +class CalcAfterLoadHandler { + sc::CompileFormulaContext& mrCxt; +public: + CalcAfterLoadHandler( sc::CompileFormulaContext& rCxt ) : mrCxt(rCxt) {} + void operator() (size_t /*nRow*/, ScFormulaCell* pCell) { - pCell->CalcAfterLoad(); + pCell->CalcAfterLoad(mrCxt); } }; @@ -3185,9 +3189,9 @@ bool ScColumn::CompileErrorCells(sal_uInt16 nErrCode) return aHdl.isCompiled(); } -void ScColumn::CalcAfterLoad() +void ScColumn::CalcAfterLoad( sc::CompileFormulaContext& rCxt ) { - CalcAfterLoadHandler aFunc; + CalcAfterLoadHandler aFunc(rCxt); sc::ProcessFormula(maCells, aFunc); } diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 4ab6d17edc2a..2d69ae4a50ef 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -3204,15 +3204,16 @@ struct CompileDBFormulaHandler class CompileDBFormula2Handler { + sc::CompileFormulaContext& mrCxt; bool mbCreateFormulaString; public: - CompileDBFormula2Handler(bool bCreateFormulaString) : - mbCreateFormulaString(bCreateFormulaString) {} + CompileDBFormula2Handler( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ) : + mrCxt(rCxt), mbCreateFormulaString(bCreateFormulaString) {} void operator() (size_t, ScFormulaCell* p) { - p->CompileDBFormula(mbCreateFormulaString); + p->CompileDBFormula(mrCxt, mbCreateFormulaString); } }; @@ -3248,9 +3249,9 @@ void ScColumn::CompileDBFormula() RegroupFormulaCells(); } -void ScColumn::CompileDBFormula( bool bCreateFormulaString ) +void ScColumn::CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ) { - CompileDBFormula2Handler aFunc(bCreateFormulaString); + CompileDBFormula2Handler aFunc(rCxt, bCreateFormulaString); sc::ProcessFormula(maCells, aFunc); RegroupFormulaCells(); } diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index c3d7a4341fa1..64c8718db485 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -549,11 +549,12 @@ void ScDocument::CompileDBFormula() void ScDocument::CompileDBFormula( bool bCreateFormulaString ) { + sc::CompileFormulaContext aCxt(this, eGrammar); TableContainer::iterator it = maTabs.begin(); for (;it != maTabs.end(); ++it) { if (*it) - (*it)->CompileDBFormula( bCreateFormulaString ); + (*it)->CompileDBFormula(aCxt, bCreateFormulaString); } } diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index b2126b232418..1ad862076ae2 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -96,6 +96,7 @@ #include "refupdatecontext.hxx" #include "formulagroup.hxx" #include <tokenarray.hxx> +#include <tokenstringcontext.hxx> #include "formula/vectortoken.hxx" @@ -3755,11 +3756,12 @@ void ScDocument::CalcAfterLoad() return; // dann wird erst beim Einfuegen in das richtige Doc berechnet bCalcingAfterLoad = true; + sc::CompileFormulaContext aCxt(this, eGrammar); { TableContainer::iterator it = maTabs.begin(); for (; it != maTabs.end(); ++it) if (*it) - (*it)->CalcAfterLoad(); + (*it)->CalcAfterLoad(aCxt); for (it = maTabs.begin(); it != maTabs.end(); ++it) if (*it) (*it)->SetDirtyAfterLoad(); diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 59a06644511c..939b6f815a04 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -1076,7 +1076,7 @@ void ScFormulaCell::CompileTokenArray( sc::CompileFormulaContext& rCxt, bool bNo // Not already compiled? if( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() ) { - assert(rCxt.meGram == eTempGrammar); + rCxt.setGrammar(eTempGrammar); Compile(rCxt, aResult.GetHybridFormula(), bNoListening); } else if( bCompile && !pDocument->IsClipOrUndo() && !pCode->GetCodeError() ) @@ -1180,13 +1180,14 @@ void ScFormulaCell::CompileXML( ScProgress& rProgress ) } -void ScFormulaCell::CalcAfterLoad() +void ScFormulaCell::CalcAfterLoad( sc::CompileFormulaContext& rCxt ) { bool bNewCompiled = false; // If a Calc 1.0-doc is read, we have a result, but no token array if( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() ) { - Compile( aResult.GetHybridFormula(), true, eTempGrammar); + rCxt.setGrammar(eTempGrammar); + Compile(rCxt, aResult.GetHybridFormula(), true); aResult.SetToken( NULL); bDirty = true; bNewCompiled = true; @@ -1194,8 +1195,7 @@ void ScFormulaCell::CalcAfterLoad() // The RPN array is not created when a Calc 3.0-Doc has been read as the Range Names exist until now. if( pCode->GetLen() && !pCode->GetCodeLen() && !pCode->GetCodeError() ) { - ScCompiler aComp(pDocument, aPos, *pCode); - aComp.SetGrammar(pDocument->GetGrammar()); + ScCompiler aComp(rCxt, aPos, *pCode); bSubTotal = aComp.CompileTokenArray(); nFormatType = aComp.GetNumFormatType(); bDirty = true; @@ -3357,7 +3357,7 @@ void ScFormulaCell::CompileDBFormula() } } -void ScFormulaCell::CompileDBFormula( bool bCreateFormulaString ) +void ScFormulaCell::CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ) { // Two phases must be called after each other // 1. Formula String with old generated names @@ -3385,8 +3385,7 @@ void ScFormulaCell::CompileDBFormula( bool bCreateFormulaString ) } if ( bRecompile ) { - OUString aFormula; - GetFormula( aFormula, formula::FormulaGrammar::GRAM_NATIVE); + OUString aFormula = GetFormula(rCxt); if ( GetMatrixFlag() != MM_NONE && !aFormula.isEmpty() ) { if ( aFormula[ aFormula.getLength()-1 ] == '}' ) @@ -3397,12 +3396,13 @@ void ScFormulaCell::CompileDBFormula( bool bCreateFormulaString ) EndListeningTo( pDocument ); pDocument->RemoveFromFormulaTree( this ); pCode->Clear(); - SetHybridFormula( aFormula, formula::FormulaGrammar::GRAM_NATIVE); + SetHybridFormula(aFormula, rCxt.getGrammar()); } } else if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() ) { - Compile( aResult.GetHybridFormula(), false, eTempGrammar ); + rCxt.setGrammar(eTempGrammar); + Compile(rCxt, aResult.GetHybridFormula(), false); aResult.SetToken( NULL); SetDirty(); } @@ -3443,12 +3443,12 @@ void ScFormulaCell::CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bC EndListeningTo( pDocument ); pDocument->RemoveFromFormulaTree( this ); pCode->Clear(); - SetHybridFormula(aFormula, rCxt.meGram); + SetHybridFormula(aFormula, rCxt.getGrammar()); } } else if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() ) { - assert(rCxt.meGram == eTempGrammar); + rCxt.setGrammar(eTempGrammar); Compile(rCxt, aResult.GetHybridFormula(), false); aResult.SetToken( NULL); SetDirty(); diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index dc35b163a917..eb11a5db33b8 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -1766,9 +1766,10 @@ bool ScTable::CompileErrorCells(sal_uInt16 nErrCode) return bCompiled; } -void ScTable::CalcAfterLoad() +void ScTable::CalcAfterLoad( sc::CompileFormulaContext& rCxt ) { - for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].CalcAfterLoad(); + for (SCCOL i = 0; i <= MAXCOL; ++i) + aCol[i].CalcAfterLoad(rCxt); } bool ScTable::IsEmptyData( SCCOL nCol ) const diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index 91b9187fce58..610103eeb2fa 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -2181,9 +2181,10 @@ void ScTable::CompileDBFormula() for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileDBFormula(); } -void ScTable::CompileDBFormula( bool bCreateFormulaString ) +void ScTable::CompileDBFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ) { - for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileDBFormula( bCreateFormulaString ); + for (SCCOL i = 0; i <= MAXCOL; ++i) + aCol[i].CompileDBFormula(rCxt, bCreateFormulaString); } void ScTable::CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bCreateFormulaString ) diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 1ffdab4a994e..8c6dee9d6b92 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -1516,7 +1516,7 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos, ScTokenArray& rArr ) : FormulaCompiler(rArr), - pDoc(rCxt.mpDoc), + pDoc(rCxt.getDoc()), aPos(rPos), mpFormatter(pDoc->GetFormatTable()), pCharClass(ScGlobal::pCharClass), @@ -1526,10 +1526,10 @@ ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos, meExtendedErrorDetection(EXTENDED_ERROR_DETECTION_NONE), mbCloseBrackets(true), mbRewind(false), - maTabNames(rCxt.maTabNames) + maTabNames(rCxt.getTabNames()) { nMaxTab = pDoc ? pDoc->GetTableCount() - 1 : 0; - SetGrammar(rCxt.meGram); + SetGrammar(rCxt.getGrammar()); } ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos,ScTokenArray& rArr) @@ -1559,7 +1559,7 @@ ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos,ScTokenArra } ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos ) : - pDoc(rCxt.mpDoc), + pDoc(rCxt.getDoc()), aPos(rPos), mpFormatter(pDoc ? pDoc->GetFormatTable() : NULL), pCharClass(ScGlobal::pCharClass), @@ -1569,10 +1569,10 @@ ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos ) meExtendedErrorDetection(EXTENDED_ERROR_DETECTION_NONE), mbCloseBrackets(true), mbRewind(false), - maTabNames(rCxt.maTabNames) + maTabNames(rCxt.getTabNames()) { nMaxTab = pDoc ? pDoc->GetTableCount() - 1 : 0; - SetGrammar(rCxt.meGram); + SetGrammar(rCxt.getGrammar()); } ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos) diff --git a/sc/source/core/tool/tokenstringcontext.cxx b/sc/source/core/tool/tokenstringcontext.cxx index 0273a216462f..96865fc026c8 100644 --- a/sc/source/core/tool/tokenstringcontext.cxx +++ b/sc/source/core/tool/tokenstringcontext.cxx @@ -111,15 +111,43 @@ CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc, formula::Formula if (!pDoc) return; + updateTabNames(); +} + +void CompileFormulaContext::updateTabNames() +{ // Fetch all sheet names. - maTabNames = pDoc->GetAllTableNames(); + maTabNames = mpDoc->GetAllTableNames(); { std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end(); for (; it != itEnd; ++it) - ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(eGram)); + ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(meGram)); } } +formula::FormulaGrammar::Grammar CompileFormulaContext::getGrammar() const +{ + return meGram; +} + +void CompileFormulaContext::setGrammar( formula::FormulaGrammar::Grammar eGram ) +{ + bool bUpdate = (meGram != eGram); + meGram = eGram; + if (bUpdate) + updateTabNames(); +} + +const std::vector<OUString>& CompileFormulaContext::getTabNames() const +{ + return maTabNames; +} + +ScDocument* CompileFormulaContext::getDoc() +{ + return mpDoc; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |