diff options
author | Arnaud Versini <Arnaud.Versini@libreoffice.org> | 2017-04-23 13:45:04 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-04-23 21:26:47 +0200 |
commit | 4a27349879ce40150c994ed49fdc8d0a6bd33d7c (patch) | |
tree | 21e864ec3f971b929a8054a0f04b4db3c7a4c0bd /basic/source/comp | |
parent | f3281c0954bd6111386b1ed75d3bdc180fc90d6f (diff) |
BASIC: Make TokenLabelInfo a singleton, never modified and simplify it.
Change-Id: Ie233aebc39f5b181087a64d3cf2053ef4ecbab91
Reviewed-on: https://gerrit.libreoffice.org/36829
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basic/source/comp')
-rw-r--r-- | basic/source/comp/token.cxx | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx index b4de0f0d024a..4dc5d395340f 100644 --- a/basic/source/comp/token.cxx +++ b/basic/source/comp/token.cxx @@ -18,6 +18,8 @@ */ +#include <array> + #include "basiccharclass.hxx" #include "token.hxx" @@ -182,31 +184,36 @@ static const TokenTable aTokTable_Basic [] = { { NIL, "" } }; +// #i109076 +class TokenLabelInfo +{ + std::array<bool,VBASUPPORT+1> m_pTokenCanBeLabelTab; + +public: + TokenLabelInfo(); + + bool canTokenBeLabel( SbiToken eTok ) + { return m_pTokenCanBeLabelTab[eTok]; } +}; + +class StaticTokenLabelInfo: public ::rtl::Static< TokenLabelInfo, StaticTokenLabelInfo >{}; // #i109076 TokenLabelInfo::TokenLabelInfo() { - m_pTokenCanBeLabelTab.reset( new bool[VBASUPPORT+1] ); - for( int i = 0 ; i <= VBASUPPORT ; ++i ) - { - m_pTokenCanBeLabelTab[i] = false; - } + m_pTokenCanBeLabelTab.fill(false); + // Token accepted as label by VBA - SbiToken eLabelToken[] = { ACCESS, ALIAS, APPEND, BASE, BINARY, CLASSMODULE, + static const SbiToken eLabelToken[] = { ACCESS, ALIAS, APPEND, BASE, BINARY, CLASSMODULE, COMPARE, COMPATIBLE, DEFERR, ERROR_, BASIC_EXPLICIT, LIB, LINE, LPRINT, NAME, TOBJECT, OUTPUT, PROPERTY, RANDOM, READ, STEP, STOP, TEXT, VBASUPPORT, NIL }; SbiToken eTok; - for( SbiToken* pTok = eLabelToken ; (eTok = *pTok) != NIL ; ++pTok ) + for( const SbiToken* pTok = eLabelToken ; (eTok = *pTok) != NIL ; ++pTok ) { m_pTokenCanBeLabelTab[eTok] = true; } } -TokenLabelInfo::~TokenLabelInfo() -{ -} - - // the constructor detects the length of the token table SbiTokenizer::SbiTokenizer( const OUString& rSrc, StarBASIC* pb ) @@ -542,7 +549,7 @@ special: bool SbiTokenizer::MayBeLabel( bool bNeedsColon ) { - if( eCurTok == SYMBOL || m_aTokenLabelInfo.canTokenBeLabel( eCurTok ) ) + if( eCurTok == SYMBOL || StaticTokenLabelInfo::get().canTokenBeLabel( eCurTok ) ) { return !bNeedsColon || DoesColonFollow(); } |