Files
libreoffice/basic/source/comp/token.cxx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

573 lines
14 KiB
C++
Raw Normal View History

/* -*- 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 .
*/
2000-09-18 15:18:56 +00:00
#include <array>
#include <basic/sberrors.hxx>
#include <sal/macros.h>
#include <o3tl/string_view.hxx>
#include <basiccharclass.hxx>
#include <token.hxx>
2000-09-18 15:18:56 +00:00
Extend loplugin:external to warn about classes ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
namespace {
2000-09-18 15:18:56 +00:00
struct TokenTable { SbiToken t; const char *s; };
Extend loplugin:external to warn about classes ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
}
const TokenTable aTokTable_Basic [] = {
2000-09-18 15:18:56 +00:00
{ CAT, "&" },
{ MUL, "*" },
{ PLUS, "+" },
{ MINUS, "-" },
{ DIV, "/" },
{ EOS, ":" },
{ ASSIGN, ":=" },
{ LT, "<" },
{ LE, "<=" },
{ NE, "<>" },
{ EQ, "=" },
{ GT, ">" },
{ GE, ">=" },
{ ACCESS, "Access" },
{ ALIAS, "Alias" },
{ AND, "And" },
{ ANY, "Any" },
{ APPEND, "Append" },
{ AS, "As" },
{ ATTRIBUTE,"Attribute" },
2000-09-18 15:18:56 +00:00
{ BASE, "Base" },
{ BINARY, "Binary" },
{ TBOOLEAN, "Boolean" },
{ BYREF, "ByRef", },
{ TBYTE, "Byte", },
2000-09-18 15:18:56 +00:00
{ BYVAL, "ByVal", },
{ CALL, "Call" },
{ CASE, "Case" },
{ CDECL_, "Cdecl" },
{ CLASSMODULE, "ClassModule" },
2000-09-18 15:18:56 +00:00
{ CLOSE, "Close" },
{ COMPARE, "Compare" },
{ COMPATIBLE,"Compatible" },
{ CONST_, "Const" },
2000-09-18 15:18:56 +00:00
{ TCURRENCY,"Currency" },
{ TDATE, "Date" },
{ DECLARE, "Declare" },
{ DEFBOOL, "DefBool" },
{ DEFCUR, "DefCur" },
{ DEFDATE, "DefDate" },
{ DEFDBL, "DefDbl" },
{ DEFERR, "DefErr" },
{ DEFINT, "DefInt" },
{ DEFLNG, "DefLng" },
{ DEFOBJ, "DefObj" },
{ DEFSNG, "DefSng" },
{ DEFSTR, "DefStr" },
{ DEFVAR, "DefVar" },
{ DIM, "Dim" },
{ DO, "Do" },
{ TDOUBLE, "Double" },
{ EACH, "Each" },
{ ELSE, "Else" },
{ ELSEIF, "ElseIf" },
{ END, "End" },
{ ENDENUM, "End Enum" },
2000-09-18 15:18:56 +00:00
{ ENDFUNC, "End Function" },
{ ENDIF, "End If" },
{ ENDPROPERTY, "End Property" },
2000-09-18 15:18:56 +00:00
{ ENDSELECT,"End Select" },
{ ENDSUB, "End Sub" },
{ ENDTYPE, "End Type" },
{ ENDIF, "EndIf" },
{ ENUM, "Enum" },
2000-09-18 15:18:56 +00:00
{ EQV, "Eqv" },
{ ERASE, "Erase" },
{ ERROR_, "Error" },
2000-09-18 15:18:56 +00:00
{ EXIT, "Exit" },
{ BASIC_EXPLICIT, "Explicit" },
2000-09-18 15:18:56 +00:00
{ FOR, "For" },
{ FUNCTION, "Function" },
{ GET, "Get" },
2000-09-18 15:18:56 +00:00
{ GLOBAL, "Global" },
{ GOSUB, "GoSub" },
{ GOTO, "GoTo" },
{ IF, "If" },
{ IMP, "Imp" },
{ IMPLEMENTS, "Implements" },
{ IN_, "In" },
{ INPUT, "Input" }, // also INPUT #
2000-09-18 15:18:56 +00:00
{ TINTEGER, "Integer" },
{ IS, "Is" },
{ LET, "Let" },
{ LIB, "Lib" },
{ LIKE, "Like" },
2000-09-18 15:18:56 +00:00
{ LINE, "Line" },
{ LINEINPUT,"Line Input" },
{ LOCAL, "Local" },
{ LOCK, "Lock" },
{ TLONG, "Long" },
{ LOOP, "Loop" },
{ LPRINT, "LPrint" },
{ LSET, "LSet" }, // JSM
{ MOD, "Mod" },
{ NAME, "Name" },
{ NEW, "New" },
{ NEXT, "Next" },
{ NOT, "Not" },
{ TOBJECT, "Object" },
{ ON, "On" },
{ OPEN, "Open" },
{ OPTION, "Option" },
{ OPTIONAL_, "Optional" },
2000-09-18 15:18:56 +00:00
{ OR, "Or" },
{ OUTPUT, "Output" },
{ PARAMARRAY, "ParamArray" },
2000-09-18 15:18:56 +00:00
{ PRESERVE, "Preserve" },
{ PRINT, "Print" },
{ PRIVATE, "Private" },
{ PROPERTY, "Property" },
{ PTRSAFE, "PtrSafe" },
2000-09-18 15:18:56 +00:00
{ PUBLIC, "Public" },
{ RANDOM, "Random" },
{ READ, "Read" },
{ REDIM, "ReDim" },
{ REM, "Rem" },
{ RESUME, "Resume" },
{ RETURN, "Return" },
{ RSET, "RSet" }, // JSM
{ SELECT, "Select" },
{ SET, "Set" },
{ SHARED, "Shared" },
{ TSINGLE, "Single" },
{ STATIC, "Static" },
{ STEP, "Step" },
{ STOP, "Stop" },
{ TSTRING, "String" },
{ SUB, "Sub" },
{ STOP, "System" },
{ TEXT, "Text" },
{ THEN, "Then" },
{ TO, "To", },
{ TYPE, "Type" },
{ TYPEOF, "TypeOf" },
2000-09-18 15:18:56 +00:00
{ UNTIL, "Until" },
{ TVARIANT, "Variant" },
{ VBASUPPORT, "VbaSupport" },
2000-09-18 15:18:56 +00:00
{ WEND, "Wend" },
{ WHILE, "While" },
{ WITH, "With" },
{ WITHEVENTS, "WithEvents" },
{ WRITE, "Write" }, // also WRITE #
2000-09-18 15:18:56 +00:00
{ XOR, "Xor" },
};
Extend loplugin:external to warn about classes ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
namespace {
// #i109076
class TokenLabelInfo
{
std::array<bool,VBASUPPORT+1> m_pTokenCanBeLabelTab;
public:
TokenLabelInfo();
bool canTokenBeLabel( SbiToken eTok )
{ return m_pTokenCanBeLabelTab[eTok]; }
};
Extend loplugin:external to warn about classes ...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend loplugin:external to warn about enums". Cases where free functions were moved into an unnamed namespace along with a class, to not break ADL, are in: filter/source/svg/svgexport.cxx sc/source/filter/excel/xelink.cxx sc/source/filter/excel/xilink.cxx svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx All other free functions mentioning moved classes appear to be harmless and not give rise to (silent, even) ADL breakage. (One remaining TODO in compilerplugins/clang/external.cxx is that derived classes are not covered by computeAffectedTypes, even though they could also be affected by ADL-breakage--- but don't seem to be in any acutal case across the code base.) For friend declarations using elaborate type specifiers, like class C1 {}; class C2 { friend class C1; }; * If C2 (but not C1) is moved into an unnamed namespace, the friend declaration must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither qualified nor a template-id and the declaration is a function or an elaborated-type-specifier, the lookup to determine whether the entity has been previously declared shall not consider any scopes outside the innermost enclosing namespace.") * If C1 (but not C2) is moved into an unnamed namespace, the friend declaration must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882> "elaborated-type-specifier friend not looked up in unnamed namespace". Apart from that, to keep changes simple and mostly mechanical (which should help avoid regressions), out-of-line definitions of class members have been left in the enclosing (named) namespace. But explicit specializations of class templates had to be moved into the unnamed namespace to appease <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of template from unnamed namespace using unqualified-id in enclosing namespace". Also, accompanying declarations (of e.g. typedefs or static variables) that could arguably be moved into the unnamed namespace too have been left alone. And in some cases, mention of affected types in blacklists in other loplugins needed to be adapted. And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is not moved into an unnamed namespace (because it is declared in sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler doesn’t give this warning for types defined in the main .C file, as those are unlikely to have multiple definitions." (<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The warned-about classes also don't have multiple definitions in the given test, so disable the warning when including the .cxx. Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4 Reviewed-on: https://gerrit.libreoffice.org/83239 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
}
// #i109076
TokenLabelInfo::TokenLabelInfo()
{
m_pTokenCanBeLabelTab.fill(false);
// Token accepted as label by VBA
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 };
for( SbiToken eTok : eLabelToken )
{
m_pTokenCanBeLabelTab[eTok] = true;
}
}
2000-09-18 15:18:56 +00:00
SbiTokenizer::SbiTokenizer( const OUString& rSrc, StarBASIC* pb )
: SbiScanner(rSrc, pb)
, eCurTok(NIL)
, ePush(NIL)
, nPLine(0)
, nPCol1(0)
, nPCol2(0)
, bEof(false)
, bEos(true)
, bAs(false)
, bErrorIsSymbol(true)
2000-09-18 15:18:56 +00:00
{
}
void SbiTokenizer::Push( SbiToken t )
{
if( ePush != NIL )
Error( ERRCODE_BASIC_INTERNAL_ERROR, u"PUSH"_ustr );
2000-09-18 15:18:56 +00:00
else ePush = t;
}
void SbiTokenizer::Error( ErrCode code, const OUString &aMsg )
2000-09-18 15:18:56 +00:00
{
aError = aMsg;
Error( code );
}
void SbiTokenizer::Error( ErrCode code, SbiToken tok )
2000-09-18 15:18:56 +00:00
{
aError = Symbol( tok );
Error( code );
}
// reading in the next token without absorbing it
2000-09-18 15:18:56 +00:00
SbiToken SbiTokenizer::Peek()
{
if( ePush == NIL )
{
sal_Int32 nOldLine = nLine;
sal_Int32 nOldCol1 = nCol1;
sal_Int32 nOldCol2 = nCol2;
2000-09-18 15:18:56 +00:00
ePush = Next();
nPLine = nLine; nLine = nOldLine;
nPCol1 = nCol1; nCol1 = nOldCol1;
nPCol2 = nCol2; nCol2 = nOldCol2;
}
eCurTok = ePush;
return eCurTok;
2000-09-18 15:18:56 +00:00
}
// For decompilation. Numbers and symbols return an empty string.
2000-09-18 15:18:56 +00:00
const OUString& SbiTokenizer::Symbol( SbiToken t )
2000-09-18 15:18:56 +00:00
{
// character token?
2000-09-18 15:18:56 +00:00
if( t < FIRSTKWD )
{
aSym = OUString(sal::static_int_cast<sal_Unicode>(t));
2000-09-18 15:18:56 +00:00
return aSym;
}
switch( t )
{
case NEG :
aSym = "-";
return aSym;
case EOS :
aSym = ":/CRLF";
return aSym;
case EOLN :
aSym = "CRLF";
return aSym;
default:
break;
2000-09-18 15:18:56 +00:00
}
for( auto& rTok : aTokTable_Basic )
2000-09-18 15:18:56 +00:00
{
if( rTok.t == t )
2000-09-18 15:18:56 +00:00
{
aSym = OStringToOUString(rTok.s, RTL_TEXTENCODING_ASCII_US);
2000-09-18 15:18:56 +00:00
return aSym;
}
}
const sal_Unicode *p = aSym.getStr();
if (*p <= ' ')
{
aSym = "???";
}
2000-09-18 15:18:56 +00:00
return aSym;
}
// Reading in the next token and put it down.
// Tokens that don't appear in the token table
// are directly returned as a character.
// Some words are treated in a special way.
2000-09-18 15:18:56 +00:00
SbiToken SbiTokenizer::Next()
{
if (bEof)
{
return EOLN;
}
// have read in one already?
2000-09-18 15:18:56 +00:00
if( ePush != NIL )
{
eCurTok = ePush;
ePush = NIL;
nLine = nPLine;
nCol1 = nPCol1;
nCol2 = nPCol2;
bEos = IsEoln( eCurTok );
return eCurTok;
}
const TokenTable *tp;
2000-09-18 15:18:56 +00:00
if( !NextSym() )
{
bEof = bEos = true;
eCurTok = EOLN;
return eCurTok;
2000-09-18 15:18:56 +00:00
}
if( aSym.startsWith("\n") )
2000-09-18 15:18:56 +00:00
{
bEos = true;
eCurTok = EOLN;
return eCurTok;
2000-09-18 15:18:56 +00:00
}
bEos = false;
2000-09-18 15:18:56 +00:00
if( bNumber )
{
eCurTok = NUMBER;
return eCurTok;
}
2000-09-18 15:18:56 +00:00
else if( ( eScanType == SbxDATE || eScanType == SbxSTRING ) && !bSymbol )
{
eCurTok = FIXSTRING;
return eCurTok;
}
else if( aSym.isEmpty() )
{
//something went wrong
bEof = bEos = true;
eCurTok = EOLN;
return eCurTok;
}
// Special cases of characters that are between "Z" and "a". ICompare()
// evaluates the position of these characters in different ways.
else if( aSym[0] == '^' )
{
eCurTok = EXPON;
return eCurTok;
}
else if( aSym[0] == '\\' )
{
eCurTok = IDIV;
return eCurTok;
}
2000-09-18 15:18:56 +00:00
else
{
if( eScanType != SbxVARIANT )
{
eCurTok = SYMBOL;
return eCurTok;
}
// valid token?
2000-09-18 15:18:56 +00:00
short lb = 0;
short ub = std::size(aTokTable_Basic)-1;
2000-09-18 15:18:56 +00:00
short delta;
do
{
delta = (ub - lb) >> 1;
tp = &aTokTable_Basic[ lb + delta ];
sal_Int32 res = aSym.compareToIgnoreAsciiCaseAscii( tp->s );
if( res == 0 )
{
goto special;
}
if( res < 0 )
2000-09-18 15:18:56 +00:00
{
if ((ub - lb) == 2)
{
ub = lb;
}
else
{
ub = ub - delta;
}
2000-09-18 15:18:56 +00:00
}
else
{
if ((ub -lb) == 2)
{
lb = ub;
}
else
{
lb = lb + delta;
}
2000-09-18 15:18:56 +00:00
}
}
while( delta );
// Symbol? if not >= token
sal_Unicode ch = aSym[0];
if( !BasicCharClass::isAlpha( ch, bCompatible ) && !bSymbol )
{
eCurTok = static_cast<SbiToken>(ch & 0x00FF);
return eCurTok;
}
eCurTok = SYMBOL;
return eCurTok;
2000-09-18 15:18:56 +00:00
}
special:
// #i92642
bool bStartOfLine = (eCurTok == NIL || eCurTok == REM || eCurTok == EOLN ||
eCurTok == THEN || eCurTok == ELSE); // single line If
if( !bStartOfLine && (tp->t == NAME || tp->t == LINE) )
{
eCurTok = SYMBOL;
return eCurTok;
}
else if( tp->t == TEXT )
{
eCurTok = SYMBOL;
return eCurTok;
}
// maybe we can expand this for other statements that have parameters
// that are keywords ( and those keywords are only used within such
// statements )
// what's happening here is that if we come across 'append' ( and we are
// not in the middle of parsing a special statement ( like 'Open')
// we just treat keyword 'append' as a normal 'SYMBOL'.
// Also we accept Dim APPEND
else if ( ( !bInStatement || eCurTok == DIM ) && tp->t == APPEND )
{
eCurTok = SYMBOL;
return eCurTok;
}
// #i92642: Special LINE token handling -> SbiParser::Line()
2000-09-18 15:18:56 +00:00
// END IF, CASE, SUB, DEF, FUNCTION, TYPE, CLASS, WITH
if( tp->t == END )
{
// from 15.3.96, special treatment for END, at Peek() the current
// time is lost, so memorize everything and restore after
sal_Int32 nOldLine = nLine;
sal_Int32 nOldCol = nCol;
sal_Int32 nOldCol1 = nCol1;
sal_Int32 nOldCol2 = nCol2;
OUString aOldSym = aSym;
SaveLine(); // save pLine in the scanner
2000-09-18 15:18:56 +00:00
eCurTok = Peek();
switch( eCurTok )
{
case IF: Next(); eCurTok = ENDIF; break;
case SELECT: Next(); eCurTok = ENDSELECT; break;
case SUB: Next(); eCurTok = ENDSUB; break;
case FUNCTION: Next(); eCurTok = ENDFUNC; break;
case PROPERTY: Next(); eCurTok = ENDPROPERTY; break;
case TYPE: Next(); eCurTok = ENDTYPE; break;
case ENUM: Next(); eCurTok = ENDENUM; break;
case WITH: Next(); eCurTok = ENDWITH; break;
default : eCurTok = END; break;
2000-09-18 15:18:56 +00:00
}
nCol1 = nOldCol1;
if( eCurTok == END )
{
// reset everything so that token is read completely newly after END
2000-09-18 15:18:56 +00:00
ePush = NIL;
nLine = nOldLine;
nCol = nOldCol;
nCol2 = nOldCol2;
aSym = aOldSym;
RestoreLine();
2000-09-18 15:18:56 +00:00
}
return eCurTok;
}
// are data types keywords?
// there is ERROR(), DATA(), STRING() etc.
2000-09-18 15:18:56 +00:00
eCurTok = tp->t;
// AS: data types are keywords
2000-09-18 15:18:56 +00:00
if( tp->t == AS )
{
bAs = true;
}
2000-09-18 15:18:56 +00:00
else
{
if( bAs )
{
bAs = false;
}
else if( eCurTok >= DATATYPE1 && eCurTok <= DATATYPE2 && (bErrorIsSymbol || eCurTok != ERROR_) )
{
2000-09-18 15:18:56 +00:00
eCurTok = SYMBOL;
}
2000-09-18 15:18:56 +00:00
}
// CLASSMODULE, PROPERTY, GET, ENUM token only visible in compatible mode
SbiToken eTok = tp->t;
if( bCompatible )
{
// #129904 Suppress system
if( eTok == STOP && aSym.equalsIgnoreAsciiCase("system") )
{
eCurTok = SYMBOL;
}
if( eTok == GET && bStartOfLine )
{
eCurTok = SYMBOL;
}
}
else
{
if( eTok == CLASSMODULE ||
eTok == IMPLEMENTS ||
eTok == PARAMARRAY ||
eTok == ENUM ||
eTok == PROPERTY ||
eTok == GET ||
eTok == TYPEOF )
{
eCurTok = SYMBOL;
}
}
2000-09-18 15:18:56 +00:00
bEos = IsEoln( eCurTok );
return eCurTok;
}
bool SbiTokenizer::MayBeLabel( bool bNeedsColon )
2000-09-18 15:18:56 +00:00
{
static TokenLabelInfo gaStaticTokenLabelInfo;
if( eCurTok == SYMBOL || gaStaticTokenLabelInfo.canTokenBeLabel( eCurTok ) )
{
return !bNeedsColon || DoesColonFollow();
}
2000-09-18 15:18:56 +00:00
else
{
return ( eCurTok == NUMBER
2000-09-18 15:18:56 +00:00
&& eScanType == SbxINTEGER
&& nVal >= 0 );
}
2000-09-18 15:18:56 +00:00
}
OUString SbiTokenizer::GetKeywordCase( std::u16string_view sKeyword )
{
for( auto& rTok : aTokTable_Basic )
{
if( o3tl::equalsIgnoreAsciiCase(sKeyword, rTok.s) )
return OStringToOUString(rTok.s, RTL_TEXTENCODING_ASCII_US);
}
return OUString();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */