From 4a27349879ce40150c994ed49fdc8d0a6bd33d7c Mon Sep 17 00:00:00 2001 From: Arnaud Versini Date: Sun, 23 Apr 2017 13:45:04 +0200 Subject: BASIC: Make TokenLabelInfo a singleton, never modified and simplify it. Change-Id: Ie233aebc39f5b181087a64d3cf2053ef4ecbab91 Reviewed-on: https://gerrit.libreoffice.org/36829 Tested-by: Jenkins Reviewed-by: Noel Grandin --- basic/source/comp/token.cxx | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'basic/source/comp') 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 + #include "basiccharclass.hxx" #include "token.hxx" @@ -182,31 +184,36 @@ static const TokenTable aTokTable_Basic [] = { { NIL, "" } }; +// #i109076 +class TokenLabelInfo +{ + std::array 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(); } -- cgit