[Libreoffice-commits] core.git: 3 commits - formula/source include/formula
Eike Rathke
erack at redhat.com
Mon Sep 16 16:04:46 PDT 2013
formula/source/core/api/FormulaCompiler.cxx | 77 ++++++++++++++++++++-----
formula/source/core/resource/core_resource.src | 10 ++-
include/formula/FormulaCompiler.hxx | 17 +++++
3 files changed, 86 insertions(+), 18 deletions(-)
New commits:
commit 3ec486639befae454eebfd5b8f5dbc88aa357404
Author: Eike Rathke <erack at redhat.com>
Date: Tue Sep 17 01:01:58 2013 +0200
introduced putCopyOpCode() to handle copyFrom()
... and added bOverrideKnownBad handling
Change-Id: I1b669771ec1aa0cdfa1c1bef0bcfccfad96fe727
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index c624eee..6389313 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -820,17 +820,68 @@ FormulaCompiler::OpCodeMap::~OpCodeMap()
delete mpHashMap;
}
-void FormulaCompiler::OpCodeMap::copyFrom( const OpCodeMap& r )
+void FormulaCompiler::OpCodeMap::putCopyOpCode( const String& rSymbol, OpCode eOp )
+{
+ SAL_WARN_IF( mpTable[eOp].Len() && !rSymbol.Len(), "formula.core",
+ "OpCodeMap::putCopyOpCode: NOT replacing OpCode " << eOp << " '" << mpTable[eOp] << "' with empty name!");
+ if (mpTable[eOp].Len() && !rSymbol.Len())
+ mpHashMap->insert( OpCodeHashMap::value_type( mpTable[eOp], eOp));
+ else
+ {
+ mpTable[eOp] = rSymbol;
+ mpHashMap->insert( OpCodeHashMap::value_type( rSymbol, eOp));
+ }
+}
+
+void FormulaCompiler::OpCodeMap::copyFrom( const OpCodeMap& r, bool bOverrideKnownBad )
{
delete mpHashMap;
mpHashMap = new OpCodeHashMap( mnSymbols);
sal_uInt16 n = r.getSymbolCount();
- for (sal_uInt16 i = 0; i < n; ++i)
+ SAL_WARN_IF( n != mnSymbols, "formula.core",
+ "OpCodeMap::copyFrom: unequal size, this: " << mnSymbols << " that: " << n);
+ if (n > mnSymbols)
+ n = mnSymbols;
+
+ // OpCode 0 (ocPush) should never be in a map.
+ SAL_WARN_IF( mpTable[0].Len() || r.mpTable[0].Len(), "formula.core",
+ "OpCodeMap::copyFrom: OpCode 0 assigned, this: '"
+ << mpTable[0] << "' that: '" << r.mpTable[0] << "'");
+
+ // For bOverrideKnownBad when copying from the English core map (ODF 1.1
+ // and API) to the native map (UI "use English function names") replace the
+ // known bad legacy function names with correct ones.
+ if (bOverrideKnownBad && r.mbCore &&
+ FormulaGrammar::extractFormulaLanguage( meGrammar) == sheet::FormulaLanguage::NATIVE &&
+ FormulaGrammar::extractFormulaLanguage( r.meGrammar) == sheet::FormulaLanguage::ENGLISH)
{
- OpCode eOp = OpCode(i);
- const String& rSymbol = r.getSymbol( eOp);
- putOpCode( rSymbol, eOp);
+ for (sal_uInt16 i = 1; i < n; ++i)
+ {
+ String aSymbol;
+ OpCode eOp = OpCode(i);
+ switch (eOp)
+ {
+ case ocZGZ:
+ aSymbol = OUString("RRI");
+ break;
+ case ocTableOp:
+ aSymbol = OUString("MULTIPLE.OPERATIONS");
+ break;
+ default:
+ aSymbol = r.mpTable[i];
+ }
+ putCopyOpCode( aSymbol, eOp);
+ }
+ }
+ else
+ {
+ for (sal_uInt16 i = 1; i < n; ++i)
+ {
+ OpCode eOp = OpCode(i);
+ const String& rSymbol = r.mpTable[i];
+ putCopyOpCode( rSymbol, eOp);
+ }
}
// TODO: maybe copy the external maps too?
@@ -1847,7 +1898,7 @@ void FormulaCompiler::SetNativeSymbols( const OpCodeMapPtr& xMap )
{
NonConstOpCodeMapPtr xSymbolsNative;
lcl_fillNativeSymbols( xSymbolsNative);
- xSymbolsNative->copyFrom(*xMap);
+ xSymbolsNative->copyFrom( *xMap, true);
}
diff --git a/include/formula/FormulaCompiler.hxx b/include/formula/FormulaCompiler.hxx
index 6e271ca..28bf5f92 100644
--- a/include/formula/FormulaCompiler.hxx
+++ b/include/formula/FormulaCompiler.hxx
@@ -114,7 +114,14 @@ public:
}
virtual ~OpCodeMap();
- void copyFrom( const OpCodeMap& r );
+ /** Copy mappings from r into this map, effectively replacing this map.
+
+ @param bOverrideKnownBad
+ If TRUE, override known legacy bad function names with
+ correct ones if the conditions can be derived from the
+ current maps.
+ */
+ void copyFrom( const OpCodeMap& r, bool bOverrideKnownBad );
/// Get the symbol String -> OpCode hash map for finds.
inline const OpCodeHashMap* getHashMap() const { return mpHashMap; }
@@ -180,6 +187,14 @@ public:
/** The value used in createSequenceOfAvailableMappings() and thus in
XFormulaOpCodeMapper::getMappings() for an unknown symbol. */
static sal_Int32 getOpCodeUnknown();
+
+ private:
+
+ /** Conditionally put a mapping in copyFrom() context.
+
+ Does NOT check eOp range!
+ */
+ void putCopyOpCode( const String& rSymbol, OpCode eOp );
};
public:
commit 24726fe2de005fe9532487907f8867259f61260c
Author: Eike Rathke <erack at redhat.com>
Date: Mon Sep 16 22:38:40 2013 +0200
FILTERXML and WEBSERVICE were missing
... from RID_STRLIST_FUNCTION_NAMES_ENGLISH
Change-Id: Ie8ef677ffb415d2a4dc29f703b80723e20e2a21a
diff --git a/formula/source/core/resource/core_resource.src b/formula/source/core/resource/core_resource.src
index e6d3474..6b1b1a8 100644
--- a/formula/source/core/resource/core_resource.src
+++ b/formula/source/core/resource/core_resource.src
@@ -20,7 +20,7 @@
#include "core_resource.hrc"
#include "formula/compiler.hrc"
-// DO NOT CHANGE!
+// DO NOT CHANGE NAMES! Only add functions.
// These English names are used internally to store/load ODFF as of ODF v1.2
Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF
{
@@ -362,11 +362,12 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF
String SC_OPCODE_ERROR_NAME { Text = "#NAME?" ; };
String SC_OPCODE_ERROR_NUM { Text = "#NUM!" ; };
String SC_OPCODE_ERROR_NA { Text = "#N/A" ; };
+ /* END defined ERROR.TYPE() values. */
String SC_OPCODE_FILTERXML { Text = "COM.MICROSOFT.FILTERXML";};
String SC_OPCODE_WEBSERVICE { Text = "COM.MICROSOFT.WEBSERVICE"; };
- /* END defined ERROR.TYPE() values. */
};
-// DO NOT CHANGE!
+
+// DO NOT CHANGE NAMES! Only add functions.
// These English names are used internally to store/load ODF v1.0/v1.1 and for
// API XFunctionAccess.
Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH
@@ -710,7 +711,10 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH
String SC_OPCODE_ERROR_NUM { Text = "#NUM!" ; };
String SC_OPCODE_ERROR_NA { Text = "#N/A" ; };
/* END defined ERROR.TYPE() values. */
+ String SC_OPCODE_FILTERXML { Text = "FILTERXML";};
+ String SC_OPCODE_WEBSERVICE { Text = "WEBSERVICE"; };
};
+
Resource RID_STRLIST_FUNCTION_NAMES
{
String SC_OPCODE_IF
commit 4fc4a3f2e5f82ed473fc6e9c22aa3fdf9178c6ff
Author: Eike Rathke <erack at redhat.com>
Date: Mon Sep 16 22:19:39 2013 +0200
better SAL_WARN_IF diagnostics
Change-Id: I74fe8e145dda41466f21f20369681d6f1e5274df
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 4917eec..c624eee 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -497,14 +497,12 @@ void FormulaCompiler::OpCodeMap::putOpCode( const String & rStr, const OpCode eO
DBG_ASSERT( 0 < eOp && sal_uInt16(eOp) < mnSymbols, "OpCodeMap::putOpCode: OpCode out of range");
if (0 < eOp && sal_uInt16(eOp) < mnSymbols)
{
- DBG_ASSERT( (mpTable[eOp].Len() == 0) || (mpTable[eOp] == rStr) ||
- (eOp == ocCurrency) || (eOp == ocSep) || (eOp == ocArrayColSep) ||
- (eOp == ocArrayRowSep),
- OStringBuffer(
- RTL_CONSTASCII_STRINGPARAM("OpCodeMap::putOpCode: reusing OpCode ")).
- append( sal_Int32( eOp)).append( RTL_CONSTASCII_STRINGPARAM(" (")).
- append( OUStringToOString( rStr, RTL_TEXTENCODING_ASCII_US)).
- append(')').getStr());
+ SAL_WARN_IF( !((mpTable[eOp].Len() == 0) || (mpTable[eOp] == rStr) ||
+ (eOp == ocCurrency) || (eOp == ocSep) || (eOp == ocArrayColSep) ||
+ (eOp == ocArrayRowSep)), "formula.core",
+ "OpCodeMap::putOpCode: reusing OpCode " << eOp
+ << ", replacing '" << mpTable[eOp] << "' with '" << rStr << "' in "
+ << (mbEnglish ? "" : "non-") << "English map 0x" << ::std::hex << meGrammar);
mpTable[eOp] = rStr;
mpHashMap->insert( OpCodeHashMap::value_type( rStr, eOp));
}
More information about the Libreoffice-commits
mailing list