sc/inc/compiler.hxx | 2 sc/inc/formulacell.hxx | 5 + sc/source/core/data/formulacell.cxx | 103 ++++++++++++++++++++++++++++++++++-- sc/source/core/tool/compiler.cxx | 18 ++++++ 4 files changed, 123 insertions(+), 5 deletions(-)
New commits: commit 9c15f4e48485706fb48ffee0d26f2f6f0f5ca957 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Tue Feb 4 11:26:33 2014 -0500 More places to cover pre-compiled sheet names. Change-Id: I9dead89e990297abee185a8a64b0d2f4a86f5c70 diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index 4632641..c9b4c20 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -366,6 +366,8 @@ public: ScCompiler( ScDocument* pDocument, const ScAddress&); + ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos, ScTokenArray& rArr ); + ScCompiler( ScDocument* pDocument, const ScAddress&,ScTokenArray& rArr); virtual ~ScCompiler(); diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index d96ac8e..0c572c5 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -206,6 +206,8 @@ public: void GetFormula( OUStringBuffer& rBuffer, const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT ) const; + OUString GetFormula( sc::CompileFormulaContext& rCxt ) const; + void SetDirty( bool bDirtyFlag=true ); void SetDirtyVar(); // If setting entire document dirty after load, no broadcasts but still append to FormulaTree. @@ -225,7 +227,8 @@ public: void Compile( sc::CompileFormulaContext& rCxt, const OUString& rFormula, bool bNoListening = false ); - void CompileTokenArray( bool bNoListening = false ); + void CompileTokenArray( bool bNoListening = false ); + void CompileTokenArray( sc::CompileFormulaContext& rCxt, bool bNoListening = false ); void CompileXML( ScProgress& rProgress ); // compile temporary string tokens void CalcAfterLoad(); bool MarkUsedExternalReferences(); diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index aee1517..59a0664 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -50,6 +50,7 @@ #include "types.hxx" #include "scopetools.hxx" #include "refupdatecontext.hxx" +#include <tokenstringcontext.hxx> #include <boost/scoped_ptr.hpp> @@ -881,6 +882,62 @@ void ScFormulaCell::GetFormula( OUString& rFormula, const FormulaGrammar::Gramma rFormula = rBuffer.makeStringAndClear(); } +OUString ScFormulaCell::GetFormula( sc::CompileFormulaContext& rCxt ) const +{ + OUStringBuffer aBuf; + if (pCode->GetCodeError() && !pCode->GetLen()) + { + aBuf = OUStringBuffer( ScGlobal::GetErrorString( pCode->GetCodeError())); + return aBuf.makeStringAndClear(); + } + else if( cMatrixFlag == MM_REFERENCE ) + { + // Reference to another cell that contains a matrix formula. + pCode->Reset(); + ScToken* p = static_cast<ScToken*>(pCode->GetNextReferenceRPN()); + if( p ) + { + /* FIXME: original GetFormula() code obtained + * pCell only if (!this->IsInChangeTrack()), + * GetEnglishFormula() omitted that test. + * Can we live without in all cases? */ + ScFormulaCell* pCell = NULL; + ScSingleRefData& rRef = p->GetSingleRef(); + ScAddress aAbs = rRef.toAbs(aPos); + if (ValidAddress(aAbs)) + pCell = pDocument->GetFormulaCell(aAbs); + + if (pCell) + { + return pCell->GetFormula(rCxt); + } + else + { + ScCompiler aComp(rCxt, aPos, *pCode); + aComp.CreateStringFromTokenArray(aBuf); + } + } + else + { + OSL_FAIL("ScFormulaCell::GetFormula: not a matrix"); + } + } + else + { + ScCompiler aComp(rCxt, aPos, *pCode); + aComp.CreateStringFromTokenArray(aBuf); + } + + aBuf.insert( 0, '='); + if( cMatrixFlag ) + { + aBuf.insert( 0, '{'); + aBuf.append( '}'); + } + + return aBuf.makeStringAndClear(); +} + void ScFormulaCell::GetResultDimensions( SCSIZE& rCols, SCSIZE& rRows ) { MaybeInterpret(); @@ -965,7 +1022,7 @@ void ScFormulaCell::Compile( pCode->AddBad( rFormula ); } bCompile = true; - CompileTokenArray( bNoListening ); + CompileTokenArray(rCxt, bNoListening); } else bChanged = true; @@ -1014,6 +1071,45 @@ void ScFormulaCell::CompileTokenArray( bool bNoListening ) } } +void ScFormulaCell::CompileTokenArray( sc::CompileFormulaContext& rCxt, bool bNoListening ) +{ + // Not already compiled? + if( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() ) + { + assert(rCxt.meGram == eTempGrammar); + Compile(rCxt, aResult.GetHybridFormula(), bNoListening); + } + else if( bCompile && !pDocument->IsClipOrUndo() && !pCode->GetCodeError() ) + { + // RPN length may get changed + bool bWasInFormulaTree = pDocument->IsInFormulaTree( this ); + if ( bWasInFormulaTree ) + pDocument->RemoveFromFormulaTree( this ); + + // Loading from within filter? No listening yet! + if( pDocument->IsInsertingFromOtherDoc() ) + bNoListening = true; + + if( !bNoListening && pCode->GetCodeLen() ) + EndListeningTo( pDocument ); + ScCompiler aComp(rCxt, aPos, *pCode); + bSubTotal = aComp.CompileTokenArray(); + if( !pCode->GetCodeError() ) + { + nFormatType = aComp.GetNumFormatType(); + bChanged = true; + aResult.SetToken( NULL); + bCompile = false; + if ( !bNoListening ) + StartListeningTo( pDocument ); + } + if ( bWasInFormulaTree ) + pDocument->PutInFormulaTree( this ); + + if (bSubTotal) + pDocument->AddSubTotalCell(this); + } +} void ScFormulaCell::CompileXML( ScProgress& rProgress ) { @@ -3336,8 +3432,7 @@ void ScFormulaCell::CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bC } 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 ] == '}' ) @@ -3348,7 +3443,7 @@ void ScFormulaCell::CompileNameFormula( sc::CompileFormulaContext& rCxt, bool bC EndListeningTo( pDocument ); pDocument->RemoveFromFormulaTree( this ); pCode->Clear(); - SetHybridFormula( aFormula, formula::FormulaGrammar::GRAM_NATIVE); + SetHybridFormula(aFormula, rCxt.meGram); } } else if ( !pCode->GetLen() && !aResult.GetHybridFormula().isEmpty() ) diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index ce0f427..1ffdab4 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -1514,6 +1514,24 @@ struct ConventionXL_R1C1 : public ScCompiler::Convention, public ConventionXL } }; +ScCompiler::ScCompiler( sc::CompileFormulaContext& rCxt, const ScAddress& rPos, ScTokenArray& rArr ) : + FormulaCompiler(rArr), + pDoc(rCxt.mpDoc), + aPos(rPos), + mpFormatter(pDoc->GetFormatTable()), + pCharClass(ScGlobal::pCharClass), + mnPredetectedReference(0), + mnRangeOpPosInSymbol(-1), + pConv(GetRefConvention(FormulaGrammar::CONV_OOO)), + meExtendedErrorDetection(EXTENDED_ERROR_DETECTION_NONE), + mbCloseBrackets(true), + mbRewind(false), + maTabNames(rCxt.maTabNames) +{ + nMaxTab = pDoc ? pDoc->GetTableCount() - 1 : 0; + SetGrammar(rCxt.meGram); +} + ScCompiler::ScCompiler( ScDocument* pDocument, const ScAddress& rPos,ScTokenArray& rArr) : FormulaCompiler(rArr), pDoc( pDocument ), _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits