/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
class ScJumpMatrix; class ScMatrix; struct ScComplexRefData; struct ScSingleRefData; enumclass FormulaError : sal_uInt16;
namespace formula
{
enum StackVar : sal_uInt8
{
svByte,
svDouble,
svString,
svStringName,
svSingleRef,
svDoubleRef,
svMatrix,
svIndex,
svJump,
svExternal, // Byte + String
svFAP, // FormulaAutoPilot only, ever exported
svJumpMatrix,
svRefList, // ocUnion result
svEmptyCell, // Result is an empty cell, e.g. in LOOKUP()
svMatrixCell, // Result is a matrix with bells and // whistles as needed for _the_ matrix // formula result.
svHybridCell, // A temporary condition of a formula // cell during import, having a double // and/or string result and a formula // string to be compiled.
// Only to be used for debugging output. No guarantee of stability of the // return value.
// Turn this into an operator<< when StackVar becomes a scoped enum
inline std::string StackVarEnumToString(StackVar const e)
{ switch (e)
{ case svByte: return"Byte"; case svDouble: return"Double"; case svString: return"String"; case svStringName: return"StringName"; case svSingleRef: return"SingleRef"; case svDoubleRef: return"DoubleRef"; case svMatrix: return"Matrix"; case svIndex: return"Index"; case svJump: return"Jump"; case svExternal: return"External"; case svFAP: return"FAP"; case svJumpMatrix: return"JumpMatrix"; case svRefList: return"RefList"; case svEmptyCell: return"EmptyCell"; case svMatrixCell: return"MatrixCell"; case svHybridCell: return"HybridCell"; case svExternalSingleRef: return"ExternalSingleRef"; case svExternalDoubleRef: return"ExternalDoubleRef"; case svExternalName: return"ExternalName"; case svSingleVectorRef: return"SingleVectorRef"; case svDoubleVectorRef: return"DoubleVectorRef"; case svError: return"Error"; case svMissing: return"Missing"; case svSep: return"Sep"; case svUnknown: return"Unknown";
}
std::ostringstream os;
os << static_cast<int>(e); return os.str();
}
enumclass RefCntPolicy : sal_uInt8
{
ThreadSafe, // refcounting via thread-safe oslInterlockedCount
UnsafeRef, // refcounting done with no locking/guarding against concurrent access
None // no ref counting done
};
class FORMULA_DLLPUBLIC FormulaToken
{
OpCode eOp; const StackVar eType; // type of data
RefCntPolicy eRefCntPolicy; // style of reference counting mutable oslInterlockedCount mnRefCnt; // reference count
FormulaToken& operator=( const FormulaToken& ) = delete; public:
FormulaToken( StackVar eTypeP,OpCode e = ocPush );
FormulaToken( const FormulaToken& r );
virtual ~FormulaToken();
voidDelete() { deletethis; } void DeleteIfZeroRef() { if (mnRefCnt == 0) deletethis; }
StackVar GetType() const { return eType; } bool IsFunction() const; // pure functions, no operators
bool IsExternalRef() const; bool IsRef() const;
sal_uInt8 GetParamCount() const;
void IncRef() const
{ switch (eRefCntPolicy)
{ case RefCntPolicy::ThreadSafe: default:
osl_atomic_increment(&mnRefCnt); break; case RefCntPolicy::UnsafeRef:
++mnRefCnt; break; case RefCntPolicy::None: break;
}
}
void DecRef() const
{ switch (eRefCntPolicy)
{ case RefCntPolicy::ThreadSafe: default: if (!osl_atomic_decrement(&mnRefCnt)) const_cast<FormulaToken*>(this)->Delete(); break; case RefCntPolicy::UnsafeRef: if (!--mnRefCnt) const_cast<FormulaToken*>(this)->Delete(); break; case RefCntPolicy::None: break;
}
}
/** Dummy methods to avoid switches and casts where possible, the real token classes have to override the appropriate method[s]. The only methods valid anytime if not overridden are:
- GetByte() since this represents the count of parameters to a function which of course is 0 on non-functions. FormulaByteToken and ScExternal do override it.
- GetInForceArray() since also this is only used for operators and functions and is ParamClass::Unknown for other tokens.
Any other non-overridden method pops up an assertion.
*/
/** This is dirty and only the compiler should use it! */ struct PrivateAccess { friendclass FormulaCompiler; private: PrivateAccess() { } }; void NewOpCode( OpCode e, const PrivateAccess& ) { eOp = e; }
};
// A special token for the FormulaAutoPilot only. Keeps a reference pointer of // the token of which it was created for comparison. class FORMULA_DLLPUBLIC FormulaFAPToken final : public FormulaByteToken
{ private:
FormulaTokenRef pOrigToken; public:
FormulaFAPToken( OpCode e, sal_uInt8 n, FormulaToken* p ) :
FormulaByteToken( e, n, svFAP, ParamClass::Unknown ),
pOrigToken( p ) {}
FormulaFAPToken( const FormulaFAPToken& r ) :
FormulaByteToken( r ), pOrigToken( r.pOrigToken ) {}
class FORMULA_DLLPUBLIC FormulaTypedDoubleToken final : public FormulaDoubleToken
{ private:
sal_Int16 mnType; /**< Can hold, for example, a value of SvNumFormatType, or by contract any other
classification. */ public:
FormulaTypedDoubleToken( double f, sal_Int16 nType ) :
FormulaDoubleToken( f ), mnType( nType ) {}
FormulaTypedDoubleToken( const FormulaTypedDoubleToken& r ) :
FormulaDoubleToken( r ), mnType( r.mnType ) {}
class FORMULA_DLLPUBLIC FormulaStringToken final : public FormulaToken
{
svl::SharedString maString; public:
FormulaStringToken( svl::SharedString r );
FormulaStringToken( const FormulaStringToken& r );
/** Identical to FormulaStringToken, but with explicit OpCode instead of implicit
ocPush, and an optional sal_uInt8 for ocBad tokens. */ class FORMULA_DLLPUBLIC FormulaStringOpToken final : public FormulaByteToken
{
svl::SharedString maString; public:
FormulaStringOpToken( OpCode e, svl::SharedString r );
FormulaStringOpToken( const FormulaStringOpToken& r );
class FORMULA_DLLPUBLIC FormulaExternalToken final : public FormulaByteToken
{ private:
OUString aExternal; public:
FormulaExternalToken( OpCode e, sal_uInt8 n, OUString r ) :
FormulaByteToken( e, n, svExternal, ParamClass::Unknown ),
aExternal(std::move( r )) {}
FormulaExternalToken( OpCode e, OUString r ) :
FormulaByteToken( e, 0, svExternal, ParamClass::Unknown ),
aExternal(std::move( r )) {}
FormulaExternalToken( const FormulaExternalToken& r ) :
FormulaByteToken( r ), aExternal( r.aExternal ) {}
class FORMULA_DLLPUBLIC FormulaMissingToken final : public FormulaToken
{ public:
FormulaMissingToken() :
FormulaToken( svMissing,ocMissing ) {}
FormulaMissingToken( const FormulaMissingToken& r ) :
FormulaToken( r ) {}
class FORMULA_DLLPUBLIC FormulaUnknownToken final : public FormulaToken
{ public:
FormulaUnknownToken( OpCode e ) :
FormulaToken( svUnknown, e ) {}
FormulaUnknownToken( const FormulaUnknownToken& r ) :
FormulaToken( r ) {}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.