Kaydet (Commit) 34a6096d authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Use symbolic (not numeric) opcodes in the registry for the OpenCL use subset

Makes it easier to edit them manually directly in the registry files.
(Something end-users are of course not expected to do, but admins or hackers
may want to do.) Also guards against the possibility of the numeric values of
the opcodes being changed. I figured out how to do the mapping from symbolic
names to enum values and back without an ScDocument, turned out it was not
complicated after all.

Change-Id: I8bd97f256f7d777162c1b629bf82285544e86d70
üst ae541008
......@@ -1368,12 +1368,12 @@
<prop oor:name="OpenCLSubsetOpCodes" oor:type="xs:string" oor:nillable="false">
<!-- UIHints: Tools - Options Spreadsheet Formula -->
<info>
<desc>The list of operator and function opcodes for which to use OpenCL. If a
formula contains only these operators and functions, it
might be calculated using OpenCL.</desc>
<!-- numeric values correspond to RAND;SIN;COS;TAN;ATAN;EXP;LN;SQRT;NORMSINV;ROUND;POWER;SUMPRODUCT;MIN;MAX;SUM;PRODUCT;AVERAGE;COUNT;NORMDIST;SUMIFS -->
<desc>The list of operator and function opcodes (in
English) for which to use OpenCL. If OpenCLSubsetOnly is
true, and a formula contains only these operators and
functions, it might be calculated using OpenCL.</desc>
</info>
<value>66;82;83;84;88;102;103;104;149;204;209;213;222;223;224;225;226;227;236;403</value>
<value>RAND;SIN;COS;TAN;ATAN;EXP;LN;SQRT;NORMSINV;ROUND;POWER;SUMPRODUCT;MIN;MAX;SUM;PRODUCT;AVERAGE;COUNT;NORMDIST;SUMIFS</value>
</prop>
<prop oor:name="OpenCLAutoSelect" oor:type="xs:boolean" oor:nillable="false">
<!-- UIHints: Tools - Options Spreadsheet Formula -->
......
......@@ -110,46 +110,11 @@ std::ostream& operator<<(std::ostream& rStream, const ScCalcConfig& rConfig)
return rStream;
}
namespace {
formula::FormulaCompiler::OpCodeMapPtr setup()
{
SfxObjectShell* pObjShell = SfxObjectShell::Current();
ScDocShell* pScDocShell = PTR_CAST(ScDocShell, pObjShell);
if (pScDocShell)
{
ScDocument& rDoc(pScDocShell->GetDocument());
ScCompiler* pComp(new ScCompiler(&rDoc, ScAddress()));
return pComp->GetOpCodeMap(css::sheet::FormulaLanguage::NATIVE);
}
return nullptr;
}
} // anonymous namespace
OUString ScOpCodeSetToNumberString(const ScCalcConfig::OpCodeSet& rOpCodes)
{
OUStringBuffer result;
for (auto i = rOpCodes.cbegin(); i != rOpCodes.cend(); ++i)
{
if (i != rOpCodes.cbegin())
result.append(';');
result.append(static_cast<sal_Int32>(*i));
}
return result.toString();
}
OUString ScOpCodeSetToSymbolicString(const ScCalcConfig::OpCodeSet& rOpCodes)
{
OUStringBuffer result;
formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(setup());
if (!pOpCodeMap)
return ScOpCodeSetToNumberString(rOpCodes);
formula::FormulaCompiler aCompiler;
formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(aCompiler.GetOpCodeMap(css::sheet::FormulaLanguage::ENGLISH));
for (auto i = rOpCodes.cbegin(); i != rOpCodes.cend(); ++i)
{
......@@ -164,16 +129,15 @@ OUString ScOpCodeSetToSymbolicString(const ScCalcConfig::OpCodeSet& rOpCodes)
ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
{
ScCalcConfig::OpCodeSet result;
formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(setup());
formula::FormulaCompiler aCompiler;
formula::FormulaCompiler::OpCodeMapPtr pOpCodeMap(aCompiler.GetOpCodeMap(css::sheet::FormulaLanguage::ENGLISH));
OUString s(rOpCodes + ";");
const formula::OpCodeHashMap *pHashMap(nullptr);
if (pOpCodeMap)
pHashMap = pOpCodeMap->getHashMap();
const formula::OpCodeHashMap *pHashMap(pOpCodeMap->getHashMap());
sal_Int32 fromIndex(0);
sal_Int32 semicolon;
OUString s(rOpCodes + ";");
while ((semicolon = s.indexOf(';', fromIndex)) >= 0)
{
if (semicolon > fromIndex)
......@@ -182,7 +146,7 @@ ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
sal_Int32 n = element.toInt32();
if (n > 0 || (n == 0 && element == "0"))
result.insert(static_cast<OpCode>(n));
else if (pHashMap)
else
{
auto opcode(pHashMap->find(element));
if (opcode != pHashMap->end())
......@@ -190,10 +154,6 @@ ScCalcConfig::OpCodeSet ScStringToOpCodeSet(const OUString& rOpCodes)
else
SAL_WARN("sc.opencl", "Unrecognized OpCode " << element << " in OpCode set string");
}
else
{
SAL_WARN("sc.opencl", "No current doc, can't convert from OpCode name to value");
}
}
fromIndex = semicolon+1;
}
......
......@@ -496,7 +496,7 @@ void ScFormulaCfg::UpdateFromProperties( const Sequence<OUString>& aNames )
break;
case SCFORMULAOPT_OPENCL_SUBSET_OPS:
{
OUString sVal = ScOpCodeSetToNumberString(GetCalcConfig().maOpenCLSubsetOpCodes);
OUString sVal = ScOpCodeSetToSymbolicString(GetCalcConfig().maOpenCLSubsetOpCodes);
pValues[nProp] >>= sVal;
GetCalcConfig().maOpenCLSubsetOpCodes = ScStringToOpCodeSet(sVal);
}
......@@ -643,7 +643,7 @@ void ScFormulaCfg::Commit()
break;
case SCFORMULAOPT_OPENCL_SUBSET_OPS:
{
OUString sVal = ScOpCodeSetToNumberString(GetCalcConfig().maOpenCLSubsetOpCodes);
OUString sVal = ScOpCodeSetToSymbolicString(GetCalcConfig().maOpenCLSubsetOpCodes);
pValues[nProp] <<= sVal;
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment