summaryrefslogtreecommitdiff
path: root/formula/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'formula/source/core')
-rw-r--r--formula/source/core/api/FormulaCompiler.cxx185
-rw-r--r--formula/source/core/api/FormulaOpCodeMapperObj.cxx3
-rw-r--r--formula/source/core/api/services.cxx3
-rw-r--r--formula/source/core/api/token.cxx44
-rw-r--r--formula/source/core/inc/core_resource.hxx4
-rw-r--r--formula/source/core/resource/core_resource.cxx2
-rw-r--r--formula/source/core/resource/makefile.mk3
7 files changed, 159 insertions, 85 deletions
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 51e2ca99f1..76b9bba949 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -25,6 +26,7 @@
*
************************************************************************/
#include "precompiled_formula.hxx"
+#include <sal/macros.h>
#include "formula/FormulaCompiler.hxx"
#include "formula/errorcodes.hxx"
#include "formula/token.hxx"
@@ -345,7 +347,7 @@ uno::Sequence< sheet::FormulaOpCodeMapEntry > FormulaCompiler::OpCodeMap::create
{ FormulaMapGroupSpecialOffset::MACRO , ocMacro } ,
{ FormulaMapGroupSpecialOffset::COL_ROW_NAME , ocColRowName }
};
- const size_t nCount = sizeof(aMap)/sizeof(aMap[0]);
+ const size_t nCount = SAL_N_ELEMENTS(aMap);
// Preallocate vector elements.
if (aVec.size() < nCount)
{
@@ -385,7 +387,7 @@ uno::Sequence< sheet::FormulaOpCodeMapEntry > FormulaCompiler::OpCodeMap::create
SC_OPCODE_CLOSE,
SC_OPCODE_SEP,
};
- lclPushOpCodeMapEntries( aVec, mpTable, aOpCodes, sizeof(aOpCodes)/sizeof(aOpCodes[0]) );
+ lclPushOpCodeMapEntries( aVec, mpTable, aOpCodes, SAL_N_ELEMENTS(aOpCodes) );
}
if ((nGroups & FormulaMapGroup::ARRAY_SEPARATORS) != 0)
{
@@ -395,7 +397,7 @@ uno::Sequence< sheet::FormulaOpCodeMapEntry > FormulaCompiler::OpCodeMap::create
SC_OPCODE_ARRAY_ROW_SEP,
SC_OPCODE_ARRAY_COL_SEP
};
- lclPushOpCodeMapEntries( aVec, mpTable, aOpCodes, sizeof(aOpCodes)/sizeof(aOpCodes[0]) );
+ lclPushOpCodeMapEntries( aVec, mpTable, aOpCodes, SAL_N_ELEMENTS(aOpCodes) );
}
if ((nGroups & FormulaMapGroup::UNARY_OPERATORS) != 0)
{
@@ -451,7 +453,7 @@ uno::Sequence< sheet::FormulaOpCodeMapEntry > FormulaCompiler::OpCodeMap::create
SC_OPCODE_NOT,
SC_OPCODE_NEG
};
- lclPushOpCodeMapEntries( aVec, mpTable, aOpCodes, sizeof(aOpCodes)/sizeof(aOpCodes[0]) );
+ lclPushOpCodeMapEntries( aVec, mpTable, aOpCodes, SAL_N_ELEMENTS(aOpCodes) );
// functions with 2 or more parameters.
for (USHORT nOp = SC_OPCODE_START_2_PAR; nOp < SC_OPCODE_STOP_2_PAR && nOp < mnSymbols; ++nOp)
{
@@ -568,6 +570,11 @@ FormulaCompiler::OpCodeMapPtr FormulaCompiler::GetOpCodeMap( const sal_Int32 nLa
InitSymbolsNative();
xMap = mxSymbolsNative;
break;
+ case FormulaLanguage::XL_ENGLISH:
+ if (!mxSymbolsEnglishXL)
+ InitSymbolsEnglishXL();
+ xMap = mxSymbolsEnglishXL;
+ break;
default:
; // nothing, NULL map returned
}
@@ -637,24 +644,7 @@ const String& FormulaCompiler::GetNativeSymbol( OpCode eOp )
// -----------------------------------------------------------------------------
void FormulaCompiler::InitSymbolsNative() const
{
- if (mxSymbolsNative.get())
- return;
- //! Experimental!
- // Use English function names and separators instead of native in UI.
- static const sal_Char aEnvVarName[] = "OOO_CALC_USE_ENGLISH_FORMULAS";
- const char* pEnv = getenv( aEnvVarName);
- if (pEnv && (*pEnv == 'Y' || *pEnv == 'y' || *pEnv == '1') )
- {
- fprintf( stderr, "%s=%s => UI uses English function names and separators in formulas.\n",
- aEnvVarName, pEnv);
- InitSymbolsEnglish();
- mxSymbolsNative = mxSymbolsEnglish;
- return;
- }
- static NonConstOpCodeMapPtr s_sSymbol;
- if ( !s_sSymbol.get() )
- lcl_fillNativeSymbols(s_sSymbol);
- mxSymbolsNative = s_sSymbol;
+ lcl_fillNativeSymbols(mxSymbolsNative);
}
// -----------------------------------------------------------------------------
void FormulaCompiler::InitSymbolsEnglish() const
@@ -681,6 +671,22 @@ void FormulaCompiler::InitSymbolsODFF() const
mxSymbolsODFF = s_sSymbol;
}
// -----------------------------------------------------------------------------
+void FormulaCompiler::InitSymbolsEnglishXL() const
+{
+ static NonConstOpCodeMapPtr s_sSymbol;
+ if ( !s_sSymbol.get() )
+ loadSymbols(RID_STRLIST_FUNCTION_NAMES_ENGLISH,FormulaGrammar::GRAM_ENGLISH,s_sSymbol);
+ mxSymbolsEnglishXL = s_sSymbol;
+
+ // TODO: For now, just replace the separators to the Excel English
+ // variants. Later, if we want to properly map Excel functions with Calc
+ // functions, we'll need to do a little more work here.
+ mxSymbolsEnglishXL->putOpCode(sal_Unicode(','), ocSep);
+ mxSymbolsEnglishXL->putOpCode(sal_Unicode(','), ocArrayColSep);
+ mxSymbolsEnglishXL->putOpCode(sal_Unicode(';'), ocArrayRowSep);
+}
+
+// -----------------------------------------------------------------------------
void FormulaCompiler::loadSymbols(USHORT _nSymbols,FormulaGrammar::Grammar _eGrammar,NonConstOpCodeMapPtr& _xMap) const
{
if ( !_xMap.get() )
@@ -720,6 +726,30 @@ OpCode FormulaCompiler::GetEnglishOpCode( const String& rName ) const
return bFound ? (*iLook).second : OpCode(ocNone);
}
+bool FormulaCompiler::IsOpCodeVolatile( OpCode eOp )
+{
+ switch (eOp)
+ {
+ // no parameters:
+ case ocRandom:
+ case ocGetActDate:
+ case ocGetActTime:
+ // one parameter:
+ case ocFormula:
+ case ocInfo:
+ // more than one parameters:
+ // ocIndirect/ocIndirectXL otherwise would have to do
+ // StopListening and StartListening on a reference for every
+ // interpreted value.
+ case ocIndirect:
+ case ocIndirectXL:
+ // ocOffset results in indirect references.
+ case ocOffset:
+ return true;
+ }
+ return false;
+}
+
// Remove quotes, escaped quotes are unescaped.
BOOL FormulaCompiler::DeQuote( String& rStr )
{
@@ -775,6 +805,22 @@ FormulaCompiler::OpCodeMap::~OpCodeMap()
delete mpHashMap;
}
// -----------------------------------------------------------------------------
+void FormulaCompiler::OpCodeMap::copyFrom( const OpCodeMap& r )
+{
+ delete mpHashMap;
+ mpHashMap = new OpCodeHashMap(mnSymbols);
+
+ USHORT n = r.getSymbolCount();
+ for (USHORT i = 0; i < n; ++i)
+ {
+ OpCode eOp = OpCode(i);
+ const String& rSymbol = r.getSymbol(eOp);
+ putOpCode(rSymbol, eOp);
+ }
+
+ // TODO: maybe copy the external maps too?
+}
+// -----------------------------------------------------------------------------
sal_Int32 FormulaCompiler::OpCodeMap::getOpCodeUnknown()
{
static const sal_Int32 kOpCodeUnknown = -1;
@@ -844,7 +890,7 @@ BOOL FormulaCompiler::GetToken()
}
if( pToken->GetOpCode() == ocSubTotal )
glSubTotal = TRUE;
- else if ( pToken->GetOpCode() == ocExternalRef )
+ else if ( pToken->IsExternalRef() )
{
return HandleExternalReference(*pToken);
}
@@ -936,44 +982,32 @@ void FormulaCompiler::Factor()
{
if( nNumFmt == NUMBERFORMAT_UNDEFINED )
nNumFmt = lcl_GetRetFormat( eOp );
- // Functions that have to be always recalculated
- switch( eOp )
+
+ if ( IsOpCodeVolatile(eOp) )
+ pArr->SetRecalcModeAlways();
+ else
{
- // no parameters:
- case ocRandom:
- case ocGetActDate:
- case ocGetActTime:
- // one parameter:
- case ocFormula:
- case ocInfo:
- // more than one parameters:
- // ocIndirect/ocIndirectXL otherwise would have to do
- // StopListening and StartListening on a reference for every
- // interpreted value.
- case ocIndirect:
- case ocIndirectXL:
- // ocOffset results in indirect references.
- case ocOffset:
- pArr->SetRecalcModeAlways();
- break;
- // Functions recalculated on every document load.
- // Don't use SetRecalcModeOnLoad() which would override
- // ModeAlways.
- case ocConvert :
- pArr->AddRecalcMode( RECALCMODE_ONLOAD );
- break;
- // If the referred cell is moved the value changes.
- case ocColumn :
- case ocRow :
- // ocCell needs recalc on move for some possible type values.
- case ocCell :
- pArr->SetRecalcModeOnRefMove();
- break;
- case ocHyperLink :
- pArr->SetHyperLink(TRUE);
- break;
- default:
- ; // nothing
+ switch( eOp )
+ {
+ // Functions recalculated on every document load.
+ // Don't use SetRecalcModeOnLoad() which would override
+ // ModeAlways.
+ case ocConvert :
+ pArr->AddRecalcMode( RECALCMODE_ONLOAD );
+ break;
+ // If the referred cell is moved the value changes.
+ case ocColumn :
+ case ocRow :
+ // ocCell needs recalc on move for some possible type values.
+ case ocCell :
+ pArr->SetRecalcModeOnRefMove();
+ break;
+ case ocHyperLink :
+ pArr->SetHyperLink(TRUE);
+ break;
+ default:
+ ; // nothing
+ }
}
if (SC_OPCODE_START_NO_PAR <= eOp && eOp < SC_OPCODE_STOP_NO_PAR)
{
@@ -1138,7 +1172,7 @@ void FormulaCompiler::Factor()
bCorrected = TRUE;
}
}
- else if ( eOp == ocExternalRef )
+ else if ( pToken->IsExternalRef() )
{
PutCode(pToken);
eOp = NextToken();
@@ -1558,7 +1592,7 @@ FormulaToken* FormulaCompiler::CreateStringFromToken( rtl::OUStringBuffer& rBuff
}
if( bNext )
{
- if (eOp == ocExternalRef)
+ if (t->IsExternalRef())
{
CreateStringFromExternal(rBuffer, pTokenP);
}
@@ -1678,6 +1712,31 @@ void FormulaCompiler::AppendString( rtl::OUStringBuffer& rBuffer, const String &
rBuffer.append(sal_Unicode('"'));
}
}
+
+void FormulaCompiler::UpdateSeparatorsNative(
+ const rtl::OUString& rSep, const rtl::OUString& rArrayColSep, const rtl::OUString& rArrayRowSep )
+{
+ NonConstOpCodeMapPtr xSymbolsNative;
+ lcl_fillNativeSymbols(xSymbolsNative);
+ xSymbolsNative->putOpCode(rSep, ocSep);
+ xSymbolsNative->putOpCode(rArrayColSep, ocArrayColSep);
+ xSymbolsNative->putOpCode(rArrayRowSep, ocArrayRowSep);
+}
+
+void FormulaCompiler::ResetNativeSymbols()
+{
+ NonConstOpCodeMapPtr xSymbolsNative;
+ lcl_fillNativeSymbols(xSymbolsNative, true);
+ lcl_fillNativeSymbols(xSymbolsNative);
+}
+
+void FormulaCompiler::SetNativeSymbols( const OpCodeMapPtr& xMap )
+{
+ NonConstOpCodeMapPtr xSymbolsNative;
+ lcl_fillNativeSymbols(xSymbolsNative);
+ xSymbolsNative->copyFrom(*xMap);
+}
+
// -----------------------------------------------------------------------------
OpCode FormulaCompiler::NextToken()
{
@@ -1857,3 +1916,5 @@ void FormulaCompiler::PushTokenArray( FormulaTokenArray* pa, BOOL bTemp )
// =============================================================================
} // formula
// =============================================================================
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/formula/source/core/api/FormulaOpCodeMapperObj.cxx b/formula/source/core/api/FormulaOpCodeMapperObj.cxx
index c16be9acd1..28e9675e2d 100644
--- a/formula/source/core/api/FormulaOpCodeMapperObj.cxx
+++ b/formula/source/core/api/FormulaOpCodeMapperObj.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -124,3 +125,5 @@ uno::Reference< uno::XInterface > SAL_CALL FormulaOpCodeMapperObj::create(
// =============================================================================
} // formula
// =============================================================================
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/formula/source/core/api/services.cxx b/formula/source/core/api/services.cxx
index 39809ab9b6..3bcfbf7052 100644
--- a/formula/source/core/api/services.cxx
+++ b/formula/source/core/api/services.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -73,3 +74,5 @@ SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(
serviceManager, registryKey, entries);
}
} // extern "C"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index ccc740633c..8d9a5f8a6a 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,10 +29,6 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_formula.hxx"
-
-
-// INCLUDE ---------------------------------------------------------------
-
#if STLPORT_VERSION<321
#include <stddef.h>
#else
@@ -47,9 +44,6 @@
#include "formula/tokenarray.hxx"
#include "formula/FormulaCompiler.hxx"
#include <formula/compiler.hrc>
-//#include "rechead.hxx"
-//#include "parclass.hxx"
-//#include "jumpmatrix.hxx"
#define MAXJUMPCOUNT 32 /* maximum number of jumps (ocChose) */
namespace formula
@@ -145,6 +139,18 @@ BOOL FormulaToken::IsMatrixFunction() const
return formula::FormulaCompiler::IsMatrixFunction(GetOpCode());
}
+bool FormulaToken::IsExternalRef() const
+{
+ switch (eType)
+ {
+ case svExternalSingleRef:
+ case svExternalDoubleRef:
+ case svExternalName:
+ return true;
+ }
+ return false;
+}
+
BOOL FormulaToken::operator==( const FormulaToken& rToken ) const
{
// don't compare reference count!
@@ -550,6 +556,16 @@ FormulaToken* FormulaTokenArray::PeekPrevNoSpaces()
return NULL;
}
+bool FormulaTokenArray::HasExternalRef() const
+{
+ for ( USHORT j=0; j < nLen; j++ )
+ {
+ if (pCode[j]->IsExternalRef())
+ return true;
+ }
+ return false;
+}
+
BOOL FormulaTokenArray::HasOpCode( OpCode eOp ) const
{
for ( USHORT j=0; j < nLen; j++ )
@@ -877,19 +893,6 @@ BOOL FormulaTokenArray::HasMatrixDoubleRefOps()
// --- POF (plain old formula) rewrite of a token array ---------------------
-#if 0
-// static function can't be compiled if not used (warning)
-//#if OSL_DEBUG_LEVEL > 0
-static void DumpTokArr( FormulaTokenArray *pCode )
-{
- fprintf (stderr, "TokenArr: ");
- for ( FormulaToken *pCur = pCode->First(); pCur; pCur = pCode->Next() )
- fprintf( stderr, "t%d,o%d ",
- pCur->GetType(), pCur->GetOpCode() );
- fprintf (stderr, "\n");
-}
-#endif
-
inline bool MissingConvention::isRewriteNeeded( OpCode eOp ) const
{
switch (eOp)
@@ -1376,3 +1379,4 @@ BOOL FormulaUnknownToken::operator==( const FormulaToken& r ) const
} // formula
// -----------------------------------------------------------------------------
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/formula/source/core/inc/core_resource.hxx b/formula/source/core/inc/core_resource.hxx
index c38c158e0a..20a8f9b97c 100644
--- a/formula/source/core/inc/core_resource.hxx
+++ b/formula/source/core/inc/core_resource.hxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,9 +29,7 @@
#ifndef _FORMULA_CORE_RESOURCE_HXX_
#define _FORMULA_CORE_RESOURCE_HXX_
-#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
-#endif
#include <osl/mutex.hxx>
class ResMgr;
@@ -109,3 +108,4 @@ namespace formula
#endif // _FORMULA_CORE_RESOURCE_HXX_
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/formula/source/core/resource/core_resource.cxx b/formula/source/core/resource/core_resource.cxx
index 15ed492b5b..f3f6d31ab4 100644
--- a/formula/source/core/resource/core_resource.cxx
+++ b/formula/source/core/resource/core_resource.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -106,3 +107,4 @@ namespace formula
} // formula
//.........................................................................
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/formula/source/core/resource/makefile.mk b/formula/source/core/resource/makefile.mk
index 7aa3433476..96e2dfd5a8 100644
--- a/formula/source/core/resource/makefile.mk
+++ b/formula/source/core/resource/makefile.mk
@@ -41,7 +41,8 @@ SRS1NAME=core_strings
SRC1FILES= \
core_resource.src
-SLOFILES= $(SLO)$/core_resource.obj
+SLOFILES= $(EXCEPTIONSFILES)
+EXCEPTIONSFILES= $(SLO)$/core_resource.obj
# --- Targets ----------------------------------