diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-03-02 12:03:20 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-03-23 09:09:06 +0100 |
commit | 719b1bb6ada9be751d770624599fa71a8ac1aa0e (patch) | |
tree | 0757253ed3f8361fb82cd6b1b29bdef4a9aa7da3 | |
parent | 101a1dbb59a0d2ff2f7d13dc8e889f406403a9a6 (diff) |
function that modifies data should not be called IsXXX()
IsXXX() is for const functions that check something. Using it
for functions that modify data is confusing. Some of them even are
in fact const, and the problem got "fixed" by making data mutable
*sigh*.
Change-Id: Ic385c96d6c32c818a8a6baa77ab025aab2c45a03
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130890
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | sc/inc/compiler.hxx | 38 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 114 |
2 files changed, 76 insertions, 76 deletions
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index f2c17fe612c8..c2bdb29b478d 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -285,7 +285,7 @@ private: sal_Unicode cSymbol[MAXSTRLEN+1]; // current Symbol + 0 OUString aFormula; // formula source code sal_Int32 nSrcPos; // tokenizer position (source code) - mutable ScRawToken maRawToken; + ScRawToken maRawToken; std::queue<OpCode> maPendingOpCodes; // additional opcodes generated from a single symbol @@ -347,21 +347,21 @@ private: std::vector<Whitespace> NextSymbol(bool bInArray); - bool IsValue( const OUString& ); - bool IsOpCode( const OUString&, bool bInArray ); - bool IsOpCode2( const OUString& ); - bool IsString(); - bool IsReference( const OUString& rSymbol, const OUString* pErrRef = nullptr ); - bool IsSingleReference( const OUString& rSymbol, const OUString* pErrRef = nullptr ); - bool IsDoubleReference( const OUString& rSymbol, const OUString* pErrRef = nullptr ); - bool IsPredetectedReference( const OUString& rSymbol ); - bool IsPredetectedErrRefReference( const OUString& rName, const OUString* pErrRef ); - bool IsMacro( const OUString& ); - bool IsNamedRange( const OUString& ); - bool IsExternalNamedRange( const OUString& rSymbol, bool& rbInvalidExternalNameRange ); - bool IsDBRange( const OUString& ); - bool IsColRowName( const OUString& ); - bool IsBoolean( const OUString& ); + bool ParseValue( const OUString& ); + bool ParseOpCode( const OUString&, bool bInArray ); + bool ParseOpCode2( const OUString& ); + bool ParseString(); + bool ParseReference( const OUString& rSymbol, const OUString* pErrRef = nullptr ); + bool ParseSingleReference( const OUString& rSymbol, const OUString* pErrRef = nullptr ); + bool ParseDoubleReference( const OUString& rSymbol, const OUString* pErrRef = nullptr ); + bool ParsePredetectedReference( const OUString& rSymbol ); + bool ParsePredetectedErrRefReference( const OUString& rName, const OUString* pErrRef ); + bool ParseMacro( const OUString& ); + bool ParseNamedRange( const OUString& ); + bool ParseExternalNamedRange( const OUString& rSymbol, bool& rbInvalidExternalNameRange ); + bool ParseDBRange( const OUString& ); + bool ParseColRowName( const OUString& ); + bool ParseBoolean( const OUString& ); void AutoCorrectParsedSymbol(); const ScRangeData* GetRangeData( SCTAB& rSheet, const OUString& rUpperName ) const; @@ -417,9 +417,9 @@ public: // Check if it is a valid english function name static bool IsEnglishSymbol( const OUString& rName ); - bool IsErrorConstant( const OUString& ) const; - bool IsTableRefItem( const OUString& ) const; - bool IsTableRefColumn( const OUString& ) const; + bool ParseErrorConstant( const OUString& ); + bool ParseTableRefItem( const OUString& ); + bool ParseTableRefColumn( const OUString& ); /** Calls GetToken() if PeekNextNoSpaces() is of given OpCode. */ bool GetTokenIfOpCode( OpCode eOp ); diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index be03f91b2f98..ba47ab92f222 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -2875,7 +2875,7 @@ Label_MaskStateMachine: // Convert symbol to token -bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray ) +bool ScCompiler::ParseOpCode( const OUString& rName, bool bInArray ) { OpCodeHashMap::const_iterator iLook( mxSymbols->getHashMap().find( rName)); bool bFound = (iLook != mxSymbols->getHashMap().end()); @@ -3062,7 +3062,7 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool bInArray ) return bFound; } -bool ScCompiler::IsOpCode2( const OUString& rName ) +bool ScCompiler::ParseOpCode2( const OUString& rName ) { bool bFound = false; sal_uInt16 i; @@ -3084,7 +3084,7 @@ static bool lcl_ParenthesisFollows( const sal_Unicode* p ) return *p == '('; } -bool ScCompiler::IsValue( const OUString& rSym ) +bool ScCompiler::ParseValue( const OUString& rSym ) { const sal_Int32 nFormulaLanguage = FormulaGrammar::extractFormulaLanguage( GetGrammar()); if (nFormulaLanguage == css::sheet::FormulaLanguage::ODFF || nFormulaLanguage == css::sheet::FormulaLanguage::OOXML) @@ -3172,7 +3172,7 @@ bool ScCompiler::IsValue( const OUString& rSym ) return true; } -bool ScCompiler::IsString() +bool ScCompiler::ParseString() { if ( cSymbol[0] != '"' ) return false; @@ -3187,20 +3187,20 @@ bool ScCompiler::IsString() return true; } -bool ScCompiler::IsPredetectedErrRefReference( const OUString& rName, const OUString* pErrRef ) +bool ScCompiler::ParsePredetectedErrRefReference( const OUString& rName, const OUString* pErrRef ) { switch (mnPredetectedReference) { case 1: - return IsSingleReference( rName, pErrRef); + return ParseSingleReference( rName, pErrRef); case 2: - return IsDoubleReference( rName, pErrRef); + return ParseDoubleReference( rName, pErrRef); default: return false; } } -bool ScCompiler::IsPredetectedReference( const OUString& rName ) +bool ScCompiler::ParsePredetectedReference( const OUString& rName ) { // Speedup documents with lots of broken references, e.g. sheet deleted. // It could also be a broken invalidated reference that contains #REF! @@ -3222,9 +3222,9 @@ bool ScCompiler::IsPredetectedReference( const OUString& rName ) // Per ODFF the correct string for a reference error is just #REF!, // so pass it on. if (rName.getLength() == 5) - return IsErrorConstant( rName); + return ParseErrorConstant( rName); // #REF!.AB42 or #REF!42 or #REF!#REF! - return IsPredetectedErrRefReference( rName, &aErrRef); + return ParsePredetectedErrRefReference( rName, &aErrRef); } sal_Unicode c = rName[nPos-1]; // before #REF! if ('$' == c) @@ -3232,7 +3232,7 @@ bool ScCompiler::IsPredetectedReference( const OUString& rName ) if (nPos == 1) { // $#REF!.AB42 or $#REF!42 or $#REF!#REF! - return IsPredetectedErrRefReference( rName, &aErrRef); + return ParsePredetectedErrRefReference( rName, &aErrRef); } c = rName[nPos-2]; // before $#REF! } @@ -3243,7 +3243,7 @@ bool ScCompiler::IsPredetectedReference( const OUString& rName ) if ('$' == c2 || '#' == c2 || ('0' <= c2 && c2 <= '9')) { // sheet.#REF!42 or sheet.#REF!#REF! - return IsPredetectedErrRefReference( rName, &aErrRef); + return ParsePredetectedErrRefReference( rName, &aErrRef); } break; case ':': @@ -3252,7 +3252,7 @@ bool ScCompiler::IsPredetectedReference( const OUString& rName ) ('0' <= c2 && c2 <= '9'))) { // :#REF!.AB42 or :#REF!42 or :#REF!#REF! - return IsPredetectedErrRefReference( rName, &aErrRef); + return ParsePredetectedErrRefReference( rName, &aErrRef); } break; default: @@ -3260,21 +3260,21 @@ bool ScCompiler::IsPredetectedReference( const OUString& rName ) ((mnPredetectedReference > 1 && ':' == c2) || 0 == c2)) { // AB#REF!: or AB#REF! - return IsPredetectedErrRefReference( rName, &aErrRef); + return ParsePredetectedErrRefReference( rName, &aErrRef); } } } switch (mnPredetectedReference) { case 1: - return IsSingleReference( rName); + return ParseSingleReference( rName); case 2: - return IsDoubleReference( rName); + return ParseDoubleReference( rName); } return false; } -bool ScCompiler::IsDoubleReference( const OUString& rName, const OUString* pErrRef ) +bool ScCompiler::ParseDoubleReference( const OUString& rName, const OUString* pErrRef ) { ScRange aRange( aPos, aPos ); const ScAddress::Details aDetails( pConv->meConv, aPos ); @@ -3314,7 +3314,7 @@ bool ScCompiler::IsDoubleReference( const OUString& rName, const OUString* pErrR return ( nFlags & ScRefFlags::VALID ) != ScRefFlags::ZERO; } -bool ScCompiler::IsSingleReference( const OUString& rName, const OUString* pErrRef ) +bool ScCompiler::ParseSingleReference( const OUString& rName, const OUString* pErrRef ) { mnCurrentSheetEndPos = 0; mnCurrentSheetTab = -1; @@ -3379,11 +3379,11 @@ bool ScCompiler::IsSingleReference( const OUString& rName, const OUString* pErrR return ( nFlags & ScRefFlags::VALID ) != ScRefFlags::ZERO; } -bool ScCompiler::IsReference( const OUString& rName, const OUString* pErrRef ) +bool ScCompiler::ParseReference( const OUString& rName, const OUString* pErrRef ) { - // Has to be called before IsValue + // Has to be called before ParseValue - // A later IsNamedRange() relies on these, being set in IsSingleReference() + // A later ParseNamedRange() relies on these, being set in ParseSingleReference() // if so, reset in all cases. mnCurrentSheetEndPos = 0; mnCurrentSheetTab = -1; @@ -3443,7 +3443,7 @@ bool ScCompiler::IsReference( const OUString& rName, const OUString* pErrRef ) } while(false); } - if (IsSingleReference( rName, pErrRef)) + if (ParseSingleReference( rName, pErrRef)) return true; // Though the range operator is handled explicitly, when encountering @@ -3451,7 +3451,7 @@ bool ScCompiler::IsReference( const OUString& rName, const OUString* pErrRef ) // doesn't pass as single cell reference. if (mnRangeOpPosInSymbol > 0) // ":foo" would be nonsense { - if (IsDoubleReference( rName, pErrRef)) + if (ParseDoubleReference( rName, pErrRef)) return true; // Now try with a symbol up to the range operator, rewind source // position. @@ -3481,7 +3481,7 @@ bool ScCompiler::IsReference( const OUString& rName, const OUString* pErrRef ) [[fallthrough]]; case FormulaGrammar::CONV_XL_R1C1: // C2 or C[1] are valid entire column references. - if (IsDoubleReference( rName, pErrRef)) + if (ParseDoubleReference( rName, pErrRef)) return true; break; default: @@ -3491,7 +3491,7 @@ bool ScCompiler::IsReference( const OUString& rName, const OUString* pErrRef ) return false; } -bool ScCompiler::IsMacro( const OUString& rName ) +bool ScCompiler::ParseMacro( const OUString& rName ) { #if !HAVE_FEATURE_SCRIPTING (void) rName; @@ -3508,7 +3508,7 @@ bool ScCompiler::IsMacro( const OUString& rName ) vcl::SolarMutexTryAndBuyGuard g; if (!g.isAcquired()) { - SAL_WARN( "sc.core", "ScCompiler::IsMacro - SolarMutex would deadlock, not obtaining Basic"); + SAL_WARN( "sc.core", "ScCompiler::ParseMacro - SolarMutex would deadlock, not obtaining Basic"); return false; // bad luck } @@ -3575,9 +3575,9 @@ const ScRangeData* ScCompiler::GetRangeData( SCTAB& rSheet, const OUString& rUpp return pData; } -bool ScCompiler::IsNamedRange( const OUString& rUpperName ) +bool ScCompiler::ParseNamedRange( const OUString& rUpperName ) { - // IsNamedRange is called only from NextNewToken, with an upper-case string + // ParseNamedRange is called only from NextNewToken, with an upper-case string SCTAB nSheet = -1; const ScRangeData* pData = GetRangeData( nSheet, rUpperName); @@ -3606,7 +3606,7 @@ bool ScCompiler::IsNamedRange( const OUString& rUpperName ) return false; } -bool ScCompiler::IsExternalNamedRange( const OUString& rSymbol, bool& rbInvalidExternalNameRange ) +bool ScCompiler::ParseExternalNamedRange( const OUString& rSymbol, bool& rbInvalidExternalNameRange ) { /* FIXME: This code currently (2008-12-02T15:41+0100 in CWS mooxlsc) * correctly parses external named references in OOo, as required per RFE @@ -3644,7 +3644,7 @@ bool ScCompiler::IsExternalNamedRange( const OUString& rSymbol, bool& rbInvalidE return true; } -bool ScCompiler::IsDBRange( const OUString& rName ) +bool ScCompiler::ParseDBRange( const OUString& rName ) { ScDBCollection::NamedDBs& rDBs = rDoc.GetDBCollection()->getNamedDBs(); const ScDBData* p = rDBs.findByUpperName(rName); @@ -3656,7 +3656,7 @@ bool ScCompiler::IsDBRange( const OUString& rName ) return true; } -bool ScCompiler::IsColRowName( const OUString& rName ) +bool ScCompiler::ParseColRowName( const OUString& rName ) { bool bInList = false; bool bFound = false; @@ -3911,7 +3911,7 @@ bool ScCompiler::IsColRowName( const OUString& rName ) return false; } -bool ScCompiler::IsBoolean( const OUString& rName ) +bool ScCompiler::ParseBoolean( const OUString& rName ) { OpCodeHashMap::const_iterator iLook( mxSymbols->getHashMap().find( rName ) ); if( iLook != mxSymbols->getHashMap().end() && @@ -3925,7 +3925,7 @@ bool ScCompiler::IsBoolean( const OUString& rName ) return false; } -bool ScCompiler::IsErrorConstant( const OUString& rName ) const +bool ScCompiler::ParseErrorConstant( const OUString& rName ) { FormulaError nError = GetErrorConstant( rName); if (nError != FormulaError::NONE) @@ -3937,7 +3937,7 @@ bool ScCompiler::IsErrorConstant( const OUString& rName ) const return false; } -bool ScCompiler::IsTableRefItem( const OUString& rName ) const +bool ScCompiler::ParseTableRefItem( const OUString& rName ) { bool bItem = false; OpCodeHashMap::const_iterator iLook( mxSymbols->getHashMap().find( rName)); @@ -4009,7 +4009,7 @@ OUString unescapeTableRefColumnSpecifier( const OUString& rStr ) } } -bool ScCompiler::IsTableRefColumn( const OUString& rName ) const +bool ScCompiler::ParseTableRefColumn( const OUString& rName ) { // Only called when there actually is a current TableRef, hence // accessing maTableRefs.back() is safe. @@ -4363,7 +4363,7 @@ bool ScCompiler::NextNewToken( bool bInArray ) { OUString aStr( cSymbol); bool bInvalidExternalNameRange; - if (!IsPredetectedReference( aStr) && !IsExternalNamedRange( aStr, bInvalidExternalNameRange )) + if (!ParsePredetectedReference( aStr) && !ParseExternalNamedRange( aStr, bInvalidExternalNameRange )) { svl::SharedString aSS = rDoc.GetSharedStringPool().intern(aStr); maRawToken.SetString(aSS.getData(), aSS.getDataIgnoreCase()); @@ -4387,7 +4387,7 @@ bool ScCompiler::NextNewToken( bool bInArray ) return false; } - if( IsString() ) + if( ParseString() ) return true; bool bMayBeFuncName; @@ -4418,7 +4418,7 @@ bool ScCompiler::NextNewToken( bool bInArray ) if (bAsciiNonAlnum && cSymbol[1] == 0 && (eLastOp != ocTableRefOpen || cSymbol[0] == '[' || cSymbol[0] == ']')) { // Shortcut for operators and separators that need no further checks or upper. - if (IsOpCode( OUString( cSymbol), bInArray )) + if (ParseOpCode( OUString( cSymbol), bInArray )) return true; } @@ -4431,8 +4431,8 @@ bool ScCompiler::NextNewToken( bool bInArray ) bMayBeFuncName = ( *p == '(' ); } - // Italian ARCTAN.2 resulted in #REF! => IsOpcode() before - // IsReference(). + // Italian ARCTAN.2 resulted in #REF! => ParseOpcode() before + // ParseReference(). OUString aUpper; @@ -4445,7 +4445,7 @@ Label_Rewind: // Check for TableRef column specifier first, it may be anything. if (cSymbol[0] != '#' && !maTableRefs.empty() && maTableRefs.back().mnLevel) { - if (IsTableRefColumn( aOrg )) + if (ParseTableRefColumn( aOrg )) return true; // Do not attempt to resolve as any other name. aUpper = aOrg; // for ocBad @@ -4464,12 +4464,12 @@ Label_Rewind: // Check for TableRef item specifiers first. if (!maTableRefs.empty() && maTableRefs.back().mnLevel == 2) { - if (IsTableRefItem( aUpper )) + if (ParseTableRefItem( aUpper )) return true; } // This can be either an error constant ... - if (IsErrorConstant( aUpper)) + if (ParseErrorConstant( aUpper)) return true; // ... or some invalidated reference starting with #REF! @@ -4477,7 +4477,7 @@ Label_Rewind: break; // do; create ocBad token or set error. } - if (IsOpCode( aUpper, bInArray )) + if (ParseOpCode( aUpper, bInArray )) return true; } @@ -4485,14 +4485,14 @@ Label_Rewind: { if (aUpper.isEmpty()) bAsciiUpper = ToUpperAsciiOrI18nIsAscii( aUpper, aOrg); - if (IsOpCode( aUpper, bInArray )) + if (ParseOpCode( aUpper, bInArray )) return true; } // Column 'DM' ("Deutsche Mark", German currency) couldn't be - // referred => IsReference() before IsValue(). + // referred => ParseReference() before ParseValue(). // Preserve case of file names in external references. - if (IsReference( aOrg )) + if (ParseReference( aOrg )) { if (mbRewind) // Range operator, but no direct reference. continue; // do; up to range operator. @@ -4510,12 +4510,12 @@ Label_Rewind: if (aUpper.isEmpty()) bAsciiUpper = ToUpperAsciiOrI18nIsAscii( aUpper, aOrg); - // IsBoolean() before IsValue() to catch inline bools without the kludge + // ParseBoolean() before ParseValue() to catch inline bools without the kludge // for inline arrays. - if (bAllowBooleans && IsBoolean( aUpper )) + if (bAllowBooleans && ParseBoolean( aUpper )) return true; - if (IsValue( aUpper )) + if (ParseValue( aUpper )) return true; // User defined names and such do need i18n upper also in ODF. @@ -4528,7 +4528,7 @@ Label_Rewind: aUpper = ScGlobal::getCharClass().uppercase( aOrg ); } - if (IsNamedRange( aUpper )) + if (ParseNamedRange( aUpper )) return true; // Compiling a named expression during collecting them in import shall @@ -4541,7 +4541,7 @@ Label_Rewind: // Preserve case of file names in external references. bool bInvalidExternalNameRange; - if (IsExternalNamedRange( aOrg, bInvalidExternalNameRange )) + if (ParseExternalNamedRange( aOrg, bInvalidExternalNameRange )) return true; // Preserve case of file names in external references even when range // is not valid and previous check failed tdf#89330 @@ -4553,15 +4553,15 @@ Label_Rewind: maRawToken.NewOpCode( ocBad ); return true; } - if (IsDBRange( aUpper )) + if (ParseDBRange( aUpper )) return true; // If followed by '(' (with or without space inbetween) it can not be a // column/row label. Prevent arbitrary content detection. - if (!bMayBeFuncName && IsColRowName( aUpper )) + if (!bMayBeFuncName && ParseColRowName( aUpper )) return true; - if (bMayBeFuncName && IsMacro( aUpper )) + if (bMayBeFuncName && ParseMacro( aUpper )) return true; - if (bMayBeFuncName && IsOpCode2( aUpper )) + if (bMayBeFuncName && ParseOpCode2( aUpper )) return true; } while (mbRewind); @@ -4570,7 +4570,7 @@ Label_Rewind: // #REF! (but is not equal to), which we also wrote to ODFF between 2013 // and 2016 until 5.1.4 OUString aErrRef( mxSymbols->getSymbol( ocErrRef)); - if (aUpper.indexOf( aErrRef) >= 0 && IsReference( aUpper, &aErrRef)) + if (aUpper.indexOf( aErrRef) >= 0 && ParseReference( aUpper, &aErrRef)) { if (mbRewind) goto Label_Rewind; |