[Libreoffice-commits] core.git: formula/source include/formula offapi/com sc/source

Eike Rathke erack at redhat.com
Wed Nov 13 08:16:37 PST 2013


 formula/source/core/api/FormulaCompiler.cxx   |   37 ++++++++++++++++++--------
 include/formula/FormulaCompiler.hxx           |   12 ++++----
 include/formula/grammar.hxx                   |    6 ++++
 offapi/com/sun/star/sheet/FormulaLanguage.idl |    7 +++-
 sc/source/filter/oox/formulabuffer.cxx        |   10 +++----
 sc/source/filter/orcus/interface.cxx          |    2 -
 6 files changed, 51 insertions(+), 23 deletions(-)

New commits:
commit debe0835cad25931a934eb3e1f205d508e6498cd
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Nov 13 16:55:48 2013 +0100

    introduced FormulaGrammar::GRAM_OOXML with FormulaLanguage::OOXML
    
    FormulaLanguage::XL_ENGLISH is not OOXML, unconditionally using
    SymbolsEnglishXL with RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML spoils
    the grammars of FormulaLanguage::XL_ENGLISH that are not OOXML.
    
    Change-Id: Id885d1c033cd15dc7b11c6490be3a98500027d37

diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 1d84757..6499aa4 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -144,25 +144,25 @@ void lclPushOpCodeMapEntries( ::std::vector< sheet::FormulaOpCodeMapEntry >& rVe
 class OpCodeList : public Resource        // temp object for resource
 {
 public:
+    enum SeparatorType
+    {
+        SEMICOLON_BASE,
+        COMMA_BASE
+    };
 
-    OpCodeList( sal_uInt16, FormulaCompiler::NonConstOpCodeMapPtr );
+    OpCodeList( sal_uInt16, FormulaCompiler::NonConstOpCodeMapPtr, SeparatorType = SEMICOLON_BASE );
 
 private:
     bool getOpCodeString( OUString& rStr, sal_uInt16 nOp );
     void putDefaultOpCode( FormulaCompiler::NonConstOpCodeMapPtr xMap, sal_uInt16 nOp );
 
 private:
-    enum SeparatorType
-    {
-        SEMICOLON_BASE,
-        COMMA_BASE
-    };
     SeparatorType meSepType;
 };
 
-OpCodeList::OpCodeList( sal_uInt16 nRID, FormulaCompiler::NonConstOpCodeMapPtr xMap ) :
+OpCodeList::OpCodeList( sal_uInt16 nRID, FormulaCompiler::NonConstOpCodeMapPtr xMap, SeparatorType eSepType ) :
     Resource( ResId( nRID, *ResourceManager::getResManager()))
-    , meSepType( SEMICOLON_BASE)
+    , meSepType( eSepType)
 {
     for (sal_uInt16 i = 0; i <= SC_OPCODE_LAST_OPCODE_ID; ++i)
     {
@@ -589,6 +589,11 @@ FormulaCompiler::OpCodeMapPtr FormulaCompiler::GetOpCodeMap( const sal_Int32 nLa
                 InitSymbolsEnglishXL();
             xMap = mxSymbolsEnglishXL;
             break;
+        case FormulaLanguage::OOXML:
+            if (!mxSymbolsOOXML)
+                InitSymbolsOOXML();
+            xMap = mxSymbolsOOXML;
+            break;
         default:
             ;   // nothing, NULL map returned
     }
@@ -703,7 +708,7 @@ void FormulaCompiler::InitSymbolsEnglishXL() const
     static OpCodeMapData aMap;
     osl::MutexGuard aGuard(&aMap.maMtx);
     if (!aMap.mxSymbolMap)
-        loadSymbols(RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML, FormulaGrammar::GRAM_ENGLISH, aMap.mxSymbolMap);
+        loadSymbols(RID_STRLIST_FUNCTION_NAMES_ENGLISH, FormulaGrammar::GRAM_ENGLISH, aMap.mxSymbolMap);
     mxSymbolsEnglishXL = aMap.mxSymbolMap;
 
     // TODO: For now, just replace the separators to the Excel English
@@ -714,6 +719,15 @@ void FormulaCompiler::InitSymbolsEnglishXL() const
     mxSymbolsEnglishXL->putOpCode( OUString(';'), ocArrayRowSep);
 }
 
+void FormulaCompiler::InitSymbolsOOXML() const
+{
+    static OpCodeMapData aMap;
+    osl::MutexGuard aGuard(&aMap.maMtx);
+    if (!aMap.mxSymbolMap)
+        loadSymbols(RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML, FormulaGrammar::GRAM_OOXML, aMap.mxSymbolMap);
+    mxSymbolsOOXML = aMap.mxSymbolMap;
+}
+
 
 void FormulaCompiler::loadSymbols( sal_uInt16 nSymbols, FormulaGrammar::Grammar eGrammar,
         NonConstOpCodeMapPtr& rxMap) const
@@ -723,7 +737,10 @@ void FormulaCompiler::loadSymbols( sal_uInt16 nSymbols, FormulaGrammar::Grammar
         // not Core
         rxMap.reset( new OpCodeMap( SC_OPCODE_LAST_OPCODE_ID + 1, eGrammar != FormulaGrammar::GRAM_ODFF, eGrammar ));
         OModuleClient aModuleClient;
-        OpCodeList aOpCodeList( nSymbols, rxMap );
+        OpCodeList aOpCodeList( nSymbols, rxMap,
+                ((eGrammar == FormulaGrammar::GRAM_OOXML) ?
+                 OpCodeList::SeparatorType::COMMA_BASE :
+                 OpCodeList::SeparatorType::SEMICOLON_BASE));
 
         fillFromAddInMap( rxMap, eGrammar);
         // Fill from collection for AddIns not already present.
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx
index e7ce920..5ce3c2d 100644
--- a/include/formula/FormulaCompiler.hxx
+++ b/include/formula/FormulaCompiler.hxx
@@ -333,6 +333,7 @@ private:
     void InitSymbolsPODF() const;      /// only SymbolsPODF, on demand
     void InitSymbolsODFF() const;      /// only SymbolsODFF, on demand
     void InitSymbolsEnglishXL() const; /// only SymbolsEnglishXL, on demand
+    void InitSymbolsOOXML() const;     /// only SymbolsOOXML, on demand
 
     void loadSymbols(sal_uInt16 _nSymbols,FormulaGrammar::Grammar _eGrammar,NonConstOpCodeMapPtr& _xMap) const;
 
@@ -382,11 +383,12 @@ private:
     };
 
 
-    mutable NonConstOpCodeMapPtr  mxSymbolsODFF;                          // ODFF symbols
-    mutable NonConstOpCodeMapPtr  mxSymbolsPODF;                          // ODF 1.1 symbols
-    mutable NonConstOpCodeMapPtr  mxSymbolsNative;                        // native symbols
-    mutable NonConstOpCodeMapPtr  mxSymbolsEnglish;                       // English symbols
-    mutable NonConstOpCodeMapPtr  mxSymbolsEnglishXL;                     // English Excel symbols (for VBA formula parsing)
+    mutable NonConstOpCodeMapPtr  mxSymbolsODFF;      // ODFF symbols
+    mutable NonConstOpCodeMapPtr  mxSymbolsPODF;      // ODF 1.1 symbols
+    mutable NonConstOpCodeMapPtr  mxSymbolsNative;    // native symbols
+    mutable NonConstOpCodeMapPtr  mxSymbolsEnglish;   // English symbols
+    mutable NonConstOpCodeMapPtr  mxSymbolsEnglishXL; // English Excel symbols (for VBA formula parsing)
+    mutable NonConstOpCodeMapPtr  mxSymbolsOOXML;     // Excel OOXML symbols
 };
 // =============================================================================
 } // formula
diff --git a/include/formula/grammar.hxx b/include/formula/grammar.hxx
index 34a0aa6..e3f29de 100644
--- a/include/formula/grammar.hxx
+++ b/include/formula/grammar.hxx
@@ -134,6 +134,11 @@ public:
                                 ((CONV_XL_OOX        +
                                   kConventionOffset) << kConventionShift)            |
                                 kEnglishBit,
+        /// Excel OOXML with Excel OOXML reference style.
+        GRAM_OOXML           = ::com::sun::star::sheet::FormulaLanguage::OOXML  |
+                                ((CONV_XL_OOX        +
+                                  kConventionOffset) << kConventionShift)       |
+                                kEnglishBit,
         /// Central definition of the default grammar to be used.
         GRAM_DEFAULT        = GRAM_NATIVE_UI,
 
@@ -187,6 +192,7 @@ public:
             case GRAM_ENGLISH_XL_A1  :
             case GRAM_ENGLISH_XL_R1C1:
             case GRAM_ENGLISH_XL_OOX :
+            case GRAM_OOXML          :
                 return true;
             default:
                 return extractFormulaLanguage( eGrammar) == GRAM_EXTERNAL;
diff --git a/offapi/com/sun/star/sheet/FormulaLanguage.idl b/offapi/com/sun/star/sheet/FormulaLanguage.idl
index edd79c0..70d3578 100644
--- a/offapi/com/sun/star/sheet/FormulaLanguage.idl
+++ b/offapi/com/sun/star/sheet/FormulaLanguage.idl
@@ -51,10 +51,13 @@ constants FormulaLanguage
     const long NATIVE   = 3;
 
     /** Function names and operators as used in the English version of
-        Excel.  This formula language is also used in VBA formulas and
-        OOXML import/export.
+        Excel.  This formula language is also used in VBA formulas.
      */
     const long XL_ENGLISH = 4;
+
+    /** Function names and operators as used in OOXML.
+     */
+    const long OOXML = 5;
 };
 
 
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index 6f0c991..b9ae6b1 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -76,7 +76,7 @@ public:
 
         Item& rCached = *it->second;
         ScCompiler aComp(&mrDoc, rPos, *rCached.mpCell->GetCode());
-        aComp.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
+        aComp.SetGrammar(formula::FormulaGrammar::GRAM_OOXML);
         OUStringBuffer aBuf;
         aComp.CreateStringFromTokenArray(aBuf);
         OUString aPredicted = aBuf.makeStringAndClear();
@@ -132,7 +132,7 @@ void applySharedFormulas(
             ScUnoConversion::FillScAddress(aPos, rAddr);
             ScCompiler aComp(&rDoc.getDoc(), aPos);
             aComp.SetNumberFormatter(&rFormatter);
-            aComp.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
+            aComp.SetGrammar(formula::FormulaGrammar::GRAM_OOXML);
             ScTokenArray* pArray = aComp.CompileString(rTokenStr);
             if (pArray)
             {
@@ -220,7 +220,7 @@ void applyCellFormulas(
 
         ScCompiler aCompiler(&rDoc.getDoc(), aPos);
         aCompiler.SetNumberFormatter(&rFormatter);
-        aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
+        aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_OOXML);
         ScTokenArray* pCode = aCompiler.CompileString(it->maTokenStr);
         if (!pCode)
             continue;
@@ -246,10 +246,10 @@ void applyArrayFormulas(
 
         ScCompiler aComp(&rDoc.getDoc(), aPos);
         aComp.SetNumberFormatter(&rFormatter);
-        aComp.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
+        aComp.SetGrammar(formula::FormulaGrammar::GRAM_OOXML);
         boost::scoped_ptr<ScTokenArray> pArray(aComp.CompileString(it->maTokenAndAddress.maTokenStr));
         if (pArray)
-            rDoc.setMatrixCells(aRange, *pArray, formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
+            rDoc.setMatrixCells(aRange, *pArray, formula::FormulaGrammar::GRAM_OOXML);
     }
 }
 
diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx
index df8c992..86964ea 100644
--- a/sc/source/filter/orcus/interface.cxx
+++ b/sc/source/filter/orcus/interface.cxx
@@ -257,7 +257,7 @@ formula::FormulaGrammar::Grammar getCalcGrammarFromOrcus( os::formula_grammar_t
             break;
         case orcus::spreadsheet::xlsx_2007:
         case orcus::spreadsheet::xlsx_2010:
-            eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX;
+            eGrammar = formula::FormulaGrammar::GRAM_OOXML;
             break;
         case orcus::spreadsheet::gnumeric:
             eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_A1;


More information about the Libreoffice-commits mailing list