LCOV - code coverage report
Current view: top level - basic/source/inc - token.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 12 15 80.0 %
Date: 2014-11-03 Functions: 7 9 77.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_BASIC_SOURCE_INC_TOKEN_HXX
      21             : #define INCLUDED_BASIC_SOURCE_INC_TOKEN_HXX
      22             : 
      23             : #include "scanner.hxx"
      24             : #include <basic/sbdef.hxx>
      25             : 
      26             : #if defined( SHARED )
      27             : #define SbiTokenSHAREDTMPUNDEF
      28             : #undef SHARED
      29             : #endif
      30             : 
      31             : #if defined( EXPLICIT )
      32             : #undef EXPLICIT
      33             : #endif
      34             : 
      35             : // The tokenizer is stand-alone, i. e. he can be used from everywhere.
      36             : // A BASIC-instance is necessary for error messages. Without BASIC the
      37             : // errors are only counted. The BASIC is also necessary when an advanced
      38             : // SBX-variable shall be used for recognition of data types etc.
      39             : 
      40             : 
      41             : enum SbiToken {
      42             :     NIL = 0,
      43             :     // tokens between 0x20 and 0x3F are literals:
      44             :     LPAREN = '(', RPAREN = ')', COMMA = ',', DOT = '.', EXCLAM = '!',
      45             :     HASH = '#', SEMICOLON = ';',
      46             : 
      47             :     // commands:
      48             :     FIRSTKWD = 0x40,
      49             :     AS = FIRSTKWD, ALIAS, ASSIGN,
      50             :     CALL, CASE, CLOSE, COMPARE, _CONST_,
      51             :     DECLARE, DIM, DO,
      52             : 
      53             :     // in the order of the data type enums!
      54             :     DEFINT, DEFLNG, DEFSNG, DEFDBL, DEFCUR, DEFDATE, DEFSTR, DEFOBJ,
      55             :     DEFERR, DEFBOOL, DEFVAR,
      56             :     // in the order of the data type enums!
      57             :     DATATYPE1,
      58             :     TINTEGER = DATATYPE1,
      59             :     TLONG, TSINGLE, TDOUBLE, TCURRENCY, TDATE, TSTRING, TOBJECT,
      60             :     _ERROR_, TBOOLEAN, TVARIANT, TBYTE,
      61             :     DATATYPE2 = TBYTE,
      62             : 
      63             :     EACH, ELSE, ELSEIF, END, ERASE, EXIT,
      64             :     FOR, FUNCTION,
      65             :     GET, GLOBAL, GOSUB, GOTO,
      66             :     IF, _IN_, INPUT,
      67             :     LET, LINE, LINEINPUT, LOCAL, LOOP, LPRINT, LSET,
      68             :     NAME, NEW, NEXT,
      69             :     ON, OPEN, OPTION, ATTRIBUTE, IMPLEMENTS,
      70             :     PRINT, PRIVATE, PROPERTY, PUBLIC,
      71             :     REDIM, REM, RESUME, RETURN, RSET,
      72             :     SELECT, SET, SHARED, STATIC, STEP, STOP, SUB,
      73             :     TEXT, THEN, TO, TYPE, ENUM,
      74             :     UNTIL,
      75             :     WEND, WHILE, WITH, WRITE,
      76             :     ENDENUM, ENDIF, ENDFUNC, ENDPROPERTY, ENDSUB, ENDTYPE, ENDSELECT, ENDWITH,
      77             :     // end of all keywords
      78             :     LASTKWD = ENDWITH,
      79             :     // statement end
      80             :     EOS, EOLN,
      81             :     // operators:
      82             :     EXPON, NEG, MUL,
      83             :     DIV, IDIV, MOD, PLUS, MINUS,
      84             :     EQ, NE, LT, GT, LE, GE,
      85             :     NOT, AND, OR, XOR, EQV,
      86             :     IMP, CAT, LIKE, IS, TYPEOF,
      87             :     // miscellaneous:
      88             :     FIRSTEXTRA,
      89             :     NUMBER=FIRSTEXTRA, FIXSTRING, SYMBOL, _CDECL_, BYVAL, BYREF,
      90             :     OUTPUT, RANDOM, APPEND, BINARY, ACCESS,
      91             :     LOCK, READ, PRESERVE, BASE, ANY, LIB, _OPTIONAL_,
      92             :     BASIC_EXPLICIT, COMPATIBLE, CLASSMODULE, PARAMARRAY, WITHEVENTS,
      93             : 
      94             :     // from here there are JavaScript-tokens (same enum so that same type)
      95             :     FIRSTJAVA,
      96             :     JS_BREAK=FIRSTJAVA, JS_CONTINUE, JS_FOR, JS_FUNCTION, JS_IF, JS_NEW,
      97             :     JS_RETURN, JS_THIS, JS_VAR, JS_WHILE, JS_WITH,
      98             : 
      99             :     // JavaScript-operators
     100             :     // _ASS_ = Assignment
     101             :     JS_COMMA, JS_ASSIGNMENT, JS_ASS_PLUS, JS_ASS_MINUS, JS_ASS_MUL,
     102             :     JS_ASS_DIV, JS_ASS_MOD, JS_ASS_LSHIFT, JS_ASS_RSHIFT, JS_ASS_RSHIFT_Z,
     103             :     JS_ASS_AND, JS_ASS_XOR, JS_ASS_OR,
     104             :     JS_COND_QUEST, JS_COND_SEL, JS_LOG_OR, JS_LOG_AND, JS_BIT_OR,
     105             :     JS_BIT_XOR, JS_BIT_AND, JS_EQ, JS_NE, JS_LT, JS_LE,
     106             :     JS_GT, JS_GE, JS_LSHIFT, JS_RSHIFT, JS_RSHIFT_Z,
     107             :     JS_PLUS, JS_MINUS, JS_MUL, JS_DIV, JS_MOD, JS_LOG_NOT, JS_BIT_NOT,
     108             :     JS_INC, JS_DEC, JS_LPAREN, JS_RPAREN, JS_LINDEX, JS_RINDEX
     109             :     , VBASUPPORT
     110             : };
     111             : 
     112             : #ifdef SbiTokenSHAREDTMPUNDEF
     113             : #define SHARED
     114             : #undef SbiTokenSHAREDTMPUNDEF
     115             : #endif
     116             : 
     117             : // #i109076
     118             : class TokenLabelInfo
     119             : {
     120             :     bool* m_pTokenCanBeLabelTab;
     121             : 
     122             : public:
     123             :     TokenLabelInfo( void );
     124        4442 :     TokenLabelInfo( const TokenLabelInfo& rInfo )
     125        4442 :         : m_pTokenCanBeLabelTab( NULL )
     126        4442 :             { (void)rInfo; }
     127             :     ~TokenLabelInfo();
     128             : 
     129        6220 :     bool canTokenBeLabel( SbiToken eTok )
     130        6220 :         { return m_pTokenCanBeLabelTab[eTok]; }
     131             : };
     132             : 
     133        4442 : class SbiTokenizer : public SbiScanner {
     134             :     TokenLabelInfo  m_aTokenLabelInfo;
     135             : 
     136             : protected:
     137             :     SbiToken eCurTok;
     138             :     SbiToken ePush;
     139             :     sal_uInt16  nPLine, nPCol1, nPCol2; // pushback location
     140             :     bool bEof;
     141             :     bool bEos;
     142             :     bool bKeywords;                 // true, if keywords are parsed
     143             :     bool bAs;                       // last keyword was AS
     144             :     bool bErrorIsSymbol;            // Handle Error token as Symbol, not keyword
     145             : public:
     146             :     SbiTokenizer( const OUString&, StarBASIC* = NULL );
     147             :    ~SbiTokenizer();
     148             : 
     149      142606 :     inline bool IsEof()             { return bEof; }
     150       13482 :     inline bool IsEos()             { return bEos; }
     151             : 
     152             :     void  Push( SbiToken );
     153             :     const OUString& Symbol( SbiToken );   // reconversion
     154             : 
     155             :     SbiToken Peek();                    // read the next token
     156             :     SbiToken Next();                    // read a token
     157             :     bool MayBeLabel( bool= false );
     158             : 
     159           0 :     void Error( SbError c ) { GenError( c ); }
     160             :     void Error( SbError, SbiToken );
     161             :     void Error( SbError, const char* );
     162             :     void Error( SbError, const OUString &);
     163             : 
     164      204702 :     static bool IsEoln( SbiToken t )
     165      204702 :         { return t == EOS || t == EOLN || t == REM; }
     166       19260 :     static bool IsKwd( SbiToken t )
     167       19260 :         { return t >= FIRSTKWD && t <= LASTKWD; }
     168           0 :     static bool IsExtra( SbiToken t )
     169           0 :         { return t >= FIRSTEXTRA; }
     170             :     static OUString GetKeywordCase( const OUString& sKeyword );
     171             : };
     172             : 
     173             : 
     174             : #endif
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10