1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_basic.hxx" 30*cdf0e10cSrcweir #include <basic/sbx.hxx> 31*cdf0e10cSrcweir #include "sbcomp.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/script/ModuleType.hpp> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir struct SbiParseStack { // "Stack" fuer Statement-Blocks 35*cdf0e10cSrcweir SbiParseStack* pNext; // Chain 36*cdf0e10cSrcweir SbiExprNode* pWithVar; // Variable fuer WITH 37*cdf0e10cSrcweir SbiToken eExitTok; // Exit-Token 38*cdf0e10cSrcweir sal_uInt32 nChain; // JUMP-Chain 39*cdf0e10cSrcweir }; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir struct SbiStatement { 42*cdf0e10cSrcweir SbiToken eTok; 43*cdf0e10cSrcweir void( SbiParser::*Func )(); // Verarbeitungsroutine 44*cdf0e10cSrcweir sal_Bool bMain; // sal_True: ausserhalb SUBs OK 45*cdf0e10cSrcweir sal_Bool bSubr; // sal_True: in SUBs OK 46*cdf0e10cSrcweir }; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #define Y sal_True 49*cdf0e10cSrcweir #define N sal_False 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir static SbiStatement StmntTable [] = { 52*cdf0e10cSrcweir { CALL, &SbiParser::Call, N, Y, }, // CALL 53*cdf0e10cSrcweir { CLOSE, &SbiParser::Close, N, Y, }, // CLOSE 54*cdf0e10cSrcweir { _CONST_, &SbiParser::Dim, Y, Y, }, // CONST 55*cdf0e10cSrcweir { DECLARE, &SbiParser::Declare, Y, N, }, // DECLARE 56*cdf0e10cSrcweir { DEFBOOL, &SbiParser::DefXXX, Y, N, }, // DEFBOOL 57*cdf0e10cSrcweir { DEFCUR, &SbiParser::DefXXX, Y, N, }, // DEFCUR 58*cdf0e10cSrcweir { DEFDATE, &SbiParser::DefXXX, Y, N, }, // DEFDATE 59*cdf0e10cSrcweir { DEFDBL, &SbiParser::DefXXX, Y, N, }, // DEFDBL 60*cdf0e10cSrcweir { DEFERR, &SbiParser::DefXXX, Y, N, }, // DEFERR 61*cdf0e10cSrcweir { DEFINT, &SbiParser::DefXXX, Y, N, }, // DEFINT 62*cdf0e10cSrcweir { DEFLNG, &SbiParser::DefXXX, Y, N, }, // DEFLNG 63*cdf0e10cSrcweir { DEFOBJ, &SbiParser::DefXXX, Y, N, }, // DEFOBJ 64*cdf0e10cSrcweir { DEFSNG, &SbiParser::DefXXX, Y, N, }, // DEFSNG 65*cdf0e10cSrcweir { DEFSTR, &SbiParser::DefXXX, Y, N, }, // DEFSTR 66*cdf0e10cSrcweir { DEFVAR, &SbiParser::DefXXX, Y, N, }, // DEFVAR 67*cdf0e10cSrcweir { DIM, &SbiParser::Dim, Y, Y, }, // DIM 68*cdf0e10cSrcweir { DO, &SbiParser::DoLoop, N, Y, }, // DO 69*cdf0e10cSrcweir { ELSE, &SbiParser::NoIf, N, Y, }, // ELSE 70*cdf0e10cSrcweir { ELSEIF, &SbiParser::NoIf, N, Y, }, // ELSEIF 71*cdf0e10cSrcweir { ENDIF, &SbiParser::NoIf, N, Y, }, // ENDIF 72*cdf0e10cSrcweir { END, &SbiParser::Stop, N, Y, }, // END 73*cdf0e10cSrcweir { ENUM, &SbiParser::Enum, Y, N, }, // TYPE 74*cdf0e10cSrcweir { ERASE, &SbiParser::Erase, N, Y, }, // ERASE 75*cdf0e10cSrcweir { _ERROR_, &SbiParser::ErrorStmnt, N, Y, }, // ERROR 76*cdf0e10cSrcweir { EXIT, &SbiParser::Exit, N, Y, }, // EXIT 77*cdf0e10cSrcweir { FOR, &SbiParser::For, N, Y, }, // FOR 78*cdf0e10cSrcweir { FUNCTION, &SbiParser::SubFunc, Y, N, }, // FUNCTION 79*cdf0e10cSrcweir { GOSUB, &SbiParser::Goto, N, Y, }, // GOSUB 80*cdf0e10cSrcweir { GLOBAL, &SbiParser::Dim, Y, N, }, // GLOBAL 81*cdf0e10cSrcweir { GOTO, &SbiParser::Goto, N, Y, }, // GOTO 82*cdf0e10cSrcweir { IF, &SbiParser::If, N, Y, }, // IF 83*cdf0e10cSrcweir { IMPLEMENTS, &SbiParser::Implements, Y, N, }, // IMPLEMENTS 84*cdf0e10cSrcweir { INPUT, &SbiParser::Input, N, Y, }, // INPUT 85*cdf0e10cSrcweir { LET, &SbiParser::Assign, N, Y, }, // LET 86*cdf0e10cSrcweir { LINE, &SbiParser::Line, N, Y, }, // LINE, -> LINE INPUT (#i92642) 87*cdf0e10cSrcweir { LINEINPUT,&SbiParser::LineInput, N, Y, }, // LINE INPUT 88*cdf0e10cSrcweir { LOOP, &SbiParser::BadBlock, N, Y, }, // LOOP 89*cdf0e10cSrcweir { LSET, &SbiParser::LSet, N, Y, }, // LSET 90*cdf0e10cSrcweir { NAME, &SbiParser::Name, N, Y, }, // NAME 91*cdf0e10cSrcweir { NEXT, &SbiParser::BadBlock, N, Y, }, // NEXT 92*cdf0e10cSrcweir { ON, &SbiParser::On, N, Y, }, // ON 93*cdf0e10cSrcweir { OPEN, &SbiParser::Open, N, Y, }, // OPEN 94*cdf0e10cSrcweir { OPTION, &SbiParser::Option, Y, N, }, // OPTION 95*cdf0e10cSrcweir { PRINT, &SbiParser::Print, N, Y, }, // PRINT 96*cdf0e10cSrcweir { PRIVATE, &SbiParser::Dim, Y, N, }, // PRIVATE 97*cdf0e10cSrcweir { PROPERTY, &SbiParser::SubFunc, Y, N, }, // FUNCTION 98*cdf0e10cSrcweir { PUBLIC, &SbiParser::Dim, Y, N, }, // PUBLIC 99*cdf0e10cSrcweir { REDIM, &SbiParser::ReDim, N, Y, }, // DIM 100*cdf0e10cSrcweir { RESUME, &SbiParser::Resume, N, Y, }, // RESUME 101*cdf0e10cSrcweir { RETURN, &SbiParser::Return, N, Y, }, // RETURN 102*cdf0e10cSrcweir { RSET, &SbiParser::RSet, N, Y, }, // RSET 103*cdf0e10cSrcweir { SELECT, &SbiParser::Select, N, Y, }, // SELECT 104*cdf0e10cSrcweir { SET, &SbiParser::Set, N, Y, }, // SET 105*cdf0e10cSrcweir { STATIC, &SbiParser::Static, Y, Y, }, // STATIC 106*cdf0e10cSrcweir { STOP, &SbiParser::Stop, N, Y, }, // STOP 107*cdf0e10cSrcweir { SUB, &SbiParser::SubFunc, Y, N, }, // SUB 108*cdf0e10cSrcweir { TYPE, &SbiParser::Type, Y, N, }, // TYPE 109*cdf0e10cSrcweir { UNTIL, &SbiParser::BadBlock, N, Y, }, // UNTIL 110*cdf0e10cSrcweir { WHILE, &SbiParser::While, N, Y, }, // WHILE 111*cdf0e10cSrcweir { WEND, &SbiParser::BadBlock, N, Y, }, // WEND 112*cdf0e10cSrcweir { WITH, &SbiParser::With, N, Y, }, // WITH 113*cdf0e10cSrcweir { WRITE, &SbiParser::Write, N, Y, }, // WRITE 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir { NIL, NULL, N, N } 116*cdf0e10cSrcweir }; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir #ifdef _MSC_VER 120*cdf0e10cSrcweir // 'this' : used in base member initializer list 121*cdf0e10cSrcweir #pragma warning( disable: 4355 ) 122*cdf0e10cSrcweir #endif 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir SbiParser::SbiParser( StarBASIC* pb, SbModule* pm ) 125*cdf0e10cSrcweir : SbiTokenizer( pm->GetSource32(), pb ), 126*cdf0e10cSrcweir aGblStrings( this ), 127*cdf0e10cSrcweir aLclStrings( this ), 128*cdf0e10cSrcweir aGlobals( aGblStrings, SbGLOBAL ), 129*cdf0e10cSrcweir aPublics( aGblStrings, SbPUBLIC ), 130*cdf0e10cSrcweir aRtlSyms( aGblStrings, SbRTL ), 131*cdf0e10cSrcweir aGen( *pm, this, 1024 ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir pBasic = pb; 134*cdf0e10cSrcweir eCurExpr = SbSYMBOL; 135*cdf0e10cSrcweir eEndTok = NIL; 136*cdf0e10cSrcweir pProc = NULL; 137*cdf0e10cSrcweir pStack = NULL; 138*cdf0e10cSrcweir pWithVar = NULL; 139*cdf0e10cSrcweir nBase = 0; 140*cdf0e10cSrcweir bText = 141*cdf0e10cSrcweir bGblDefs = 142*cdf0e10cSrcweir bNewGblDefs = 143*cdf0e10cSrcweir bSingleLineIf = 144*cdf0e10cSrcweir bExplicit = sal_False; 145*cdf0e10cSrcweir bClassModule = ( pm->GetModuleType() == com::sun::star::script::ModuleType::CLASS ); 146*cdf0e10cSrcweir OSL_TRACE("Parser - %s, bClassModule %d", rtl::OUStringToOString( pm->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), bClassModule ); 147*cdf0e10cSrcweir pPool = &aPublics; 148*cdf0e10cSrcweir for( short i = 0; i < 26; i++ ) 149*cdf0e10cSrcweir eDefTypes[ i ] = SbxVARIANT; // Kein expliziter Defaulttyp 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir aPublics.SetParent( &aGlobals ); 152*cdf0e10cSrcweir aGlobals.SetParent( &aRtlSyms ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // Die globale Chainkette faengt bei Adresse 0 an: 155*cdf0e10cSrcweir nGblChain = aGen.Gen( _JUMP, 0 ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir rTypeArray = new SbxArray; // Array fuer Benutzerdefinierte Typen 158*cdf0e10cSrcweir rEnumArray = new SbxArray; // Array for Enum types 159*cdf0e10cSrcweir bVBASupportOn = pm->IsVBACompat(); 160*cdf0e10cSrcweir if ( bVBASupportOn ) 161*cdf0e10cSrcweir EnableCompatibility(); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // Ist Teil der Runtime-Library? 167*cdf0e10cSrcweir SbiSymDef* SbiParser::CheckRTLForSym( const String& rSym, SbxDataType eType ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir SbxVariable* pVar = GetBasic()->GetRtl()->Find( rSym, SbxCLASS_DONTCARE ); 170*cdf0e10cSrcweir SbiSymDef* pDef = NULL; 171*cdf0e10cSrcweir if( pVar ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir if( pVar->IsA( TYPE(SbxMethod) ) ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir SbiProcDef* pProc_ = aRtlSyms.AddProc( rSym ); 176*cdf0e10cSrcweir pProc_->SetType( pVar->GetType() ); 177*cdf0e10cSrcweir pDef = pProc_; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir else 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir pDef = aRtlSyms.AddSym( rSym ); 182*cdf0e10cSrcweir pDef->SetType( eType ); 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir return pDef; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir // Globale Chainkette schliessen 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir sal_Bool SbiParser::HasGlobalCode() 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir if( bGblDefs && nGblChain ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir aGen.BackChain( nGblChain ); 195*cdf0e10cSrcweir aGen.Gen( _LEAVE ); 196*cdf0e10cSrcweir // aGen.Gen( _STOP ); 197*cdf0e10cSrcweir nGblChain = 0; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir return bGblDefs; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir void SbiParser::OpenBlock( SbiToken eTok, SbiExprNode* pVar ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir SbiParseStack* p = new SbiParseStack; 205*cdf0e10cSrcweir p->eExitTok = eTok; 206*cdf0e10cSrcweir p->nChain = 0; 207*cdf0e10cSrcweir p->pWithVar = pWithVar; 208*cdf0e10cSrcweir p->pNext = pStack; 209*cdf0e10cSrcweir pStack = p; 210*cdf0e10cSrcweir pWithVar = pVar; 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir // #29955 for-Schleifen-Ebene pflegen 213*cdf0e10cSrcweir if( eTok == FOR ) 214*cdf0e10cSrcweir aGen.IncForLevel(); 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir void SbiParser::CloseBlock() 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir if( pStack ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir SbiParseStack* p = pStack; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // #29955 for-Schleifen-Ebene pflegen 224*cdf0e10cSrcweir if( p->eExitTok == FOR ) 225*cdf0e10cSrcweir aGen.DecForLevel(); 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir aGen.BackChain( p->nChain ); 228*cdf0e10cSrcweir pStack = p->pNext; 229*cdf0e10cSrcweir pWithVar = p->pWithVar; 230*cdf0e10cSrcweir delete p; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir // EXIT ... 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir void SbiParser::Exit() 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir SbiToken eTok = Next(); 239*cdf0e10cSrcweir for( SbiParseStack* p = pStack; p; p = p->pNext ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir SbiToken eExitTok = p->eExitTok; 242*cdf0e10cSrcweir if( eTok == eExitTok || 243*cdf0e10cSrcweir (eTok == PROPERTY && (eExitTok == GET || eExitTok == LET) ) ) // #i109051 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir p->nChain = aGen.Gen( _JUMP, p->nChain ); 246*cdf0e10cSrcweir return; 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir if( pStack ) 250*cdf0e10cSrcweir Error( SbERR_EXPECTED, pStack->eExitTok ); 251*cdf0e10cSrcweir else 252*cdf0e10cSrcweir Error( SbERR_BAD_EXIT ); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir sal_Bool SbiParser::TestSymbol( sal_Bool bKwdOk ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir Peek(); 258*cdf0e10cSrcweir if( eCurTok == SYMBOL || ( bKwdOk && IsKwd( eCurTok ) ) ) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir Next(); return sal_True; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir Error( SbERR_SYMBOL_EXPECTED ); 263*cdf0e10cSrcweir return sal_False; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir // Testen auf ein bestimmtes Token 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir sal_Bool SbiParser::TestToken( SbiToken t ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir if( Peek() == t ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir Next(); return sal_True; 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir else 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir Error( SbERR_EXPECTED, t ); 277*cdf0e10cSrcweir return sal_False; 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir // Testen auf Komma oder EOLN 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir sal_Bool SbiParser::TestComma() 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir SbiToken eTok = Peek(); 286*cdf0e10cSrcweir if( IsEoln( eTok ) ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir Next(); 289*cdf0e10cSrcweir return sal_False; 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir else if( eTok != COMMA ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir Error( SbERR_EXPECTED, COMMA ); 294*cdf0e10cSrcweir return sal_False; 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir Next(); 297*cdf0e10cSrcweir return sal_True; 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir // Testen, ob EOLN vorliegt 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir void SbiParser::TestEoln() 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir if( !IsEoln( Next() ) ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir Error( SbERR_EXPECTED, EOLN ); 307*cdf0e10cSrcweir while( !IsEoln( Next() ) ) {} 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // Parsing eines Statement-Blocks 312*cdf0e10cSrcweir // Das Parsing laeuft bis zum Ende-Token. 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir void SbiParser::StmntBlock( SbiToken eEnd ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir SbiToken xe = eEndTok; 317*cdf0e10cSrcweir eEndTok = eEnd; 318*cdf0e10cSrcweir while( !bAbort && Parse() ) {} 319*cdf0e10cSrcweir eEndTok = xe; 320*cdf0e10cSrcweir if( IsEof() ) 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir Error( SbERR_BAD_BLOCK, eEnd ); 323*cdf0e10cSrcweir bAbort = sal_True; 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir // Die Hauptroutine. Durch wiederholten Aufrufs dieser Routine wird 328*cdf0e10cSrcweir // die Quelle geparst. Returnwert sal_False bei Ende/Fehlern. 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir sal_Bool SbiParser::Parse() 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir if( bAbort ) return sal_False; 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir EnableErrors(); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir bErrorIsSymbol = false; 337*cdf0e10cSrcweir Peek(); 338*cdf0e10cSrcweir bErrorIsSymbol = true; 339*cdf0e10cSrcweir // Dateiende? 340*cdf0e10cSrcweir if( IsEof() ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir // AB #33133: Falls keine Sub angelegt wurde, muss hier 343*cdf0e10cSrcweir // der globale Chain abgeschlossen werden! 344*cdf0e10cSrcweir // AB #40689: Durch die neue static-Behandlung kann noch 345*cdf0e10cSrcweir // ein nGblChain vorhanden sein, daher vorher abfragen 346*cdf0e10cSrcweir if( bNewGblDefs && nGblChain == 0 ) 347*cdf0e10cSrcweir nGblChain = aGen.Gen( _JUMP, 0 ); 348*cdf0e10cSrcweir return sal_False; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir // Leerstatement? 352*cdf0e10cSrcweir if( IsEoln( eCurTok ) ) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir Next(); return sal_True; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir if( !bSingleLineIf && MayBeLabel( sal_True ) ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir // Ist ein Label 360*cdf0e10cSrcweir if( !pProc ) 361*cdf0e10cSrcweir Error( SbERR_NOT_IN_MAIN, aSym ); 362*cdf0e10cSrcweir else 363*cdf0e10cSrcweir pProc->GetLabels().Define( aSym ); 364*cdf0e10cSrcweir Next(); Peek(); 365*cdf0e10cSrcweir // Leerstatement? 366*cdf0e10cSrcweir if( IsEoln( eCurTok ) ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir Next(); return sal_True; 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir // Ende des Parsings? 373*cdf0e10cSrcweir if( eCurTok == eEndTok || 374*cdf0e10cSrcweir ( bVBASupportOn && // #i109075 375*cdf0e10cSrcweir (eCurTok == ENDFUNC || eCurTok == ENDPROPERTY || eCurTok == ENDSUB) && 376*cdf0e10cSrcweir (eEndTok == ENDFUNC || eEndTok == ENDPROPERTY || eEndTok == ENDSUB) ) ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir Next(); 379*cdf0e10cSrcweir if( eCurTok != NIL ) 380*cdf0e10cSrcweir aGen.Statement(); 381*cdf0e10cSrcweir return sal_False; 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir // Kommentar? 385*cdf0e10cSrcweir if( eCurTok == REM ) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir Next(); return sal_True; 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir // Kommt ein Symbol, ist es entweder eine Variable( LET ) 391*cdf0e10cSrcweir // oder eine SUB-Prozedur( CALL ohne Klammern ) 392*cdf0e10cSrcweir // DOT fuer Zuweisungen im WITH-Block: .A=5 393*cdf0e10cSrcweir if( eCurTok == SYMBOL || eCurTok == DOT ) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir if( !pProc ) 396*cdf0e10cSrcweir Error( SbERR_EXPECTED, SUB ); 397*cdf0e10cSrcweir else 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir // Damit Zeile & Spalte stimmen... 400*cdf0e10cSrcweir Next(); 401*cdf0e10cSrcweir Push( eCurTok ); 402*cdf0e10cSrcweir aGen.Statement(); 403*cdf0e10cSrcweir Symbol(); 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir else 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir Next(); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir // Hier folgen nun die Statement-Parser. 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir SbiStatement* p; 413*cdf0e10cSrcweir for( p = StmntTable; p->eTok != NIL; p++ ) 414*cdf0e10cSrcweir if( p->eTok == eCurTok ) 415*cdf0e10cSrcweir break; 416*cdf0e10cSrcweir if( p->eTok != NIL ) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir if( !pProc && !p->bMain ) 419*cdf0e10cSrcweir Error( SbERR_NOT_IN_MAIN, eCurTok ); 420*cdf0e10cSrcweir else if( pProc && !p->bSubr ) 421*cdf0e10cSrcweir Error( SbERR_NOT_IN_SUBR, eCurTok ); 422*cdf0e10cSrcweir else 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir // globalen Chain pflegen 425*cdf0e10cSrcweir // AB #41606/#40689: Durch die neue static-Behandlung kann noch 426*cdf0e10cSrcweir // ein nGblChain vorhanden sein, daher vorher abfragen 427*cdf0e10cSrcweir if( bNewGblDefs && nGblChain == 0 && 428*cdf0e10cSrcweir ( eCurTok == SUB || eCurTok == FUNCTION || eCurTok == PROPERTY ) ) 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir nGblChain = aGen.Gen( _JUMP, 0 ); 431*cdf0e10cSrcweir bNewGblDefs = sal_False; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir // Statement-Opcode bitte auch am Anfang einer Sub 434*cdf0e10cSrcweir if( ( p->bSubr && (eCurTok != STATIC || Peek() == SUB || Peek() == FUNCTION ) ) || 435*cdf0e10cSrcweir eCurTok == SUB || eCurTok == FUNCTION ) 436*cdf0e10cSrcweir aGen.Statement(); 437*cdf0e10cSrcweir (this->*( p->Func ) )(); 438*cdf0e10cSrcweir SbxError nSbxErr = SbxBase::GetError(); 439*cdf0e10cSrcweir if( nSbxErr ) 440*cdf0e10cSrcweir SbxBase::ResetError(), Error( (SbError)nSbxErr ); 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir else 444*cdf0e10cSrcweir Error( SbERR_UNEXPECTED, eCurTok ); 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir // Test auf Ende des Statements: 448*cdf0e10cSrcweir // Kann auch ein ELSE sein, da vor dem ELSE kein : stehen muss! 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir if( !IsEos() ) 451*cdf0e10cSrcweir { 452*cdf0e10cSrcweir Peek(); 453*cdf0e10cSrcweir if( !IsEos() && eCurTok != ELSE ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir // falls das Parsing abgebrochen wurde, bis zum ":" vorgehen: 456*cdf0e10cSrcweir Error( SbERR_UNEXPECTED, eCurTok ); 457*cdf0e10cSrcweir while( !IsEos() ) Next(); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir // Der Parser bricht am Ende ab, das naechste Token ist noch nicht 461*cdf0e10cSrcweir // geholt! 462*cdf0e10cSrcweir return sal_True; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir // Innerste With-Variable liefern 466*cdf0e10cSrcweir SbiExprNode* SbiParser::GetWithVar() 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir if( pWithVar ) 469*cdf0e10cSrcweir return pWithVar; 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir // Sonst im Stack suchen 472*cdf0e10cSrcweir SbiParseStack* p = pStack; 473*cdf0e10cSrcweir while( p ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir // LoopVar kann zur Zeit nur fuer with sein 476*cdf0e10cSrcweir if( p->pWithVar ) 477*cdf0e10cSrcweir return p->pWithVar; 478*cdf0e10cSrcweir p = p->pNext; 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir return NULL; 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir // Zuweisung oder Subroutine Call 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir void SbiParser::Symbol( const KeywordSymbolInfo* pKeywordSymbolInfo ) 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir SbiExprMode eMode = bVBASupportOn ? EXPRMODE_STANDALONE : EXPRMODE_STANDARD; 489*cdf0e10cSrcweir SbiExpression aVar( this, SbSYMBOL, eMode, pKeywordSymbolInfo ); 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir bool bEQ = ( Peek() == EQ ); 492*cdf0e10cSrcweir if( !bEQ && bVBASupportOn && aVar.IsBracket() ) 493*cdf0e10cSrcweir Error( SbERR_EXPECTED, "=" ); 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir RecursiveMode eRecMode = ( bEQ ? PREVENT_CALL : FORCE_CALL ); 496*cdf0e10cSrcweir bool bSpecialMidHandling = false; 497*cdf0e10cSrcweir SbiSymDef* pDef = aVar.GetRealVar(); 498*cdf0e10cSrcweir if( bEQ && pDef && pDef->GetScope() == SbRTL ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir String aRtlName = pDef->GetName(); 501*cdf0e10cSrcweir if( aRtlName.EqualsIgnoreCaseAscii("Mid") ) 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir SbiExprNode* pExprNode = aVar.GetExprNode(); 504*cdf0e10cSrcweir // SbiNodeType eNodeType; 505*cdf0e10cSrcweir if( pExprNode && pExprNode->GetNodeType() == SbxVARVAL ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir SbiExprList* pPar = pExprNode->GetParameters(); 508*cdf0e10cSrcweir short nParCount = pPar ? pPar->GetSize() : 0; 509*cdf0e10cSrcweir if( nParCount == 2 || nParCount == 3 ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir if( nParCount == 2 ) 512*cdf0e10cSrcweir pPar->addExpression( new SbiExpression( this, -1, SbxLONG ) ); 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir TestToken( EQ ); 515*cdf0e10cSrcweir pPar->addExpression( new SbiExpression( this ) ); 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir bSpecialMidHandling = true; 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir } 522*cdf0e10cSrcweir aVar.Gen( eRecMode ); 523*cdf0e10cSrcweir if( !bSpecialMidHandling ) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir if( !bEQ ) 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir aGen.Gen( _GET ); 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir else 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir // Dann muss es eine Zuweisung sein. Was anderes gibts nicht! 532*cdf0e10cSrcweir if( !aVar.IsLvalue() ) 533*cdf0e10cSrcweir Error( SbERR_LVALUE_EXPECTED ); 534*cdf0e10cSrcweir TestToken( EQ ); 535*cdf0e10cSrcweir SbiExpression aExpr( this ); 536*cdf0e10cSrcweir aExpr.Gen(); 537*cdf0e10cSrcweir SbiOpcode eOp = _PUT; 538*cdf0e10cSrcweir // SbiSymDef* pDef = aVar.GetRealVar(); 539*cdf0e10cSrcweir if( pDef ) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir if( pDef->GetConstDef() ) 542*cdf0e10cSrcweir Error( SbERR_DUPLICATE_DEF, pDef->GetName() ); 543*cdf0e10cSrcweir if( pDef->GetType() == SbxOBJECT ) 544*cdf0e10cSrcweir { 545*cdf0e10cSrcweir eOp = _SET; 546*cdf0e10cSrcweir if( pDef->GetTypeId() ) 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir aGen.Gen( _SETCLASS, pDef->GetTypeId() ); 549*cdf0e10cSrcweir return; 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir aGen.Gen( eOp ); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir // Zuweisungen 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir void SbiParser::Assign() 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir SbiExpression aLvalue( this, SbLVALUE ); 563*cdf0e10cSrcweir TestToken( EQ ); 564*cdf0e10cSrcweir SbiExpression aExpr( this ); 565*cdf0e10cSrcweir aLvalue.Gen(); 566*cdf0e10cSrcweir aExpr.Gen(); 567*cdf0e10cSrcweir sal_uInt16 nLen = 0; 568*cdf0e10cSrcweir SbiSymDef* pDef = aLvalue.GetRealVar(); 569*cdf0e10cSrcweir { 570*cdf0e10cSrcweir if( pDef->GetConstDef() ) 571*cdf0e10cSrcweir Error( SbERR_DUPLICATE_DEF, pDef->GetName() ); 572*cdf0e10cSrcweir nLen = aLvalue.GetRealVar()->GetLen(); 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir if( nLen ) 575*cdf0e10cSrcweir aGen.Gen( _PAD, nLen ); 576*cdf0e10cSrcweir aGen.Gen( _PUT ); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir // Zuweisungen einer Objektvariablen 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir void SbiParser::Set() 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir SbiExpression aLvalue( this, SbLVALUE ); 584*cdf0e10cSrcweir SbxDataType eType = aLvalue.GetType(); 585*cdf0e10cSrcweir if( eType != SbxOBJECT && eType != SbxEMPTY && eType != SbxVARIANT ) 586*cdf0e10cSrcweir Error( SbERR_INVALID_OBJECT ); 587*cdf0e10cSrcweir TestToken( EQ ); 588*cdf0e10cSrcweir SbiSymDef* pDef = aLvalue.GetRealVar(); 589*cdf0e10cSrcweir if( pDef && pDef->GetConstDef() ) 590*cdf0e10cSrcweir Error( SbERR_DUPLICATE_DEF, pDef->GetName() ); 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir SbiToken eTok = Peek(); 593*cdf0e10cSrcweir if( eTok == NEW ) 594*cdf0e10cSrcweir { 595*cdf0e10cSrcweir Next(); 596*cdf0e10cSrcweir String aStr; 597*cdf0e10cSrcweir SbiSymDef* pTypeDef = new SbiSymDef( aStr ); 598*cdf0e10cSrcweir TypeDecl( *pTypeDef, sal_True ); 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir aLvalue.Gen(); 601*cdf0e10cSrcweir // aGen.Gen( _CLASS, pDef->GetTypeId() | 0x8000 ); 602*cdf0e10cSrcweir aGen.Gen( _CREATE, pDef->GetId(), pTypeDef->GetTypeId() ); 603*cdf0e10cSrcweir aGen.Gen( _SETCLASS, pDef->GetTypeId() ); 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir else 606*cdf0e10cSrcweir { 607*cdf0e10cSrcweir SbiExpression aExpr( this ); 608*cdf0e10cSrcweir aLvalue.Gen(); 609*cdf0e10cSrcweir aExpr.Gen(); 610*cdf0e10cSrcweir // Its a good idea to distinguish between 611*cdf0e10cSrcweir // set someting = another & 612*cdf0e10cSrcweir // someting = another 613*cdf0e10cSrcweir // ( its necessary for vba objects where set is object 614*cdf0e10cSrcweir // specific and also doesn't involve processing default params ) 615*cdf0e10cSrcweir if( pDef->GetTypeId() ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir if ( bVBASupportOn ) 618*cdf0e10cSrcweir aGen.Gen( _VBASETCLASS, pDef->GetTypeId() ); 619*cdf0e10cSrcweir else 620*cdf0e10cSrcweir aGen.Gen( _SETCLASS, pDef->GetTypeId() ); 621*cdf0e10cSrcweir } 622*cdf0e10cSrcweir else 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir if ( bVBASupportOn ) 625*cdf0e10cSrcweir aGen.Gen( _VBASET ); 626*cdf0e10cSrcweir else 627*cdf0e10cSrcweir aGen.Gen( _SET ); 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir // aGen.Gen( _SET ); 631*cdf0e10cSrcweir } 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir // JSM 07.10.95 634*cdf0e10cSrcweir void SbiParser::LSet() 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir SbiExpression aLvalue( this, SbLVALUE ); 637*cdf0e10cSrcweir if( aLvalue.GetType() != SbxSTRING ) 638*cdf0e10cSrcweir Error( SbERR_INVALID_OBJECT ); 639*cdf0e10cSrcweir TestToken( EQ ); 640*cdf0e10cSrcweir SbiSymDef* pDef = aLvalue.GetRealVar(); 641*cdf0e10cSrcweir if( pDef && pDef->GetConstDef() ) 642*cdf0e10cSrcweir Error( SbERR_DUPLICATE_DEF, pDef->GetName() ); 643*cdf0e10cSrcweir SbiExpression aExpr( this ); 644*cdf0e10cSrcweir aLvalue.Gen(); 645*cdf0e10cSrcweir aExpr.Gen(); 646*cdf0e10cSrcweir aGen.Gen( _LSET ); 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir // JSM 07.10.95 650*cdf0e10cSrcweir void SbiParser::RSet() 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir SbiExpression aLvalue( this, SbLVALUE ); 653*cdf0e10cSrcweir if( aLvalue.GetType() != SbxSTRING ) 654*cdf0e10cSrcweir Error( SbERR_INVALID_OBJECT ); 655*cdf0e10cSrcweir TestToken( EQ ); 656*cdf0e10cSrcweir SbiSymDef* pDef = aLvalue.GetRealVar(); 657*cdf0e10cSrcweir if( pDef && pDef->GetConstDef() ) 658*cdf0e10cSrcweir Error( SbERR_DUPLICATE_DEF, pDef->GetName() ); 659*cdf0e10cSrcweir SbiExpression aExpr( this ); 660*cdf0e10cSrcweir aLvalue.Gen(); 661*cdf0e10cSrcweir aExpr.Gen(); 662*cdf0e10cSrcweir aGen.Gen( _RSET ); 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir // DEFINT, DEFLNG, DEFSNG, DEFDBL, DEFSTR und so weiter 666*cdf0e10cSrcweir 667*cdf0e10cSrcweir void SbiParser::DefXXX() 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir sal_Unicode ch1, ch2; 670*cdf0e10cSrcweir SbxDataType t = SbxDataType( eCurTok - DEFINT + SbxINTEGER ); 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir while( !bAbort ) 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir if( Next() != SYMBOL ) break; 675*cdf0e10cSrcweir ch1 = aSym.ToUpperAscii().GetBuffer()[0]; 676*cdf0e10cSrcweir ch2 = 0; 677*cdf0e10cSrcweir if( Peek() == MINUS ) 678*cdf0e10cSrcweir { 679*cdf0e10cSrcweir Next(); 680*cdf0e10cSrcweir if( Next() != SYMBOL ) Error( SbERR_SYMBOL_EXPECTED ); 681*cdf0e10cSrcweir else 682*cdf0e10cSrcweir { 683*cdf0e10cSrcweir ch2 = aSym.ToUpperAscii().GetBuffer()[0]; 684*cdf0e10cSrcweir //ch2 = aSym.Upper(); 685*cdf0e10cSrcweir if( ch2 < ch1 ) Error( SbERR_SYNTAX ), ch2 = 0; 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir } 688*cdf0e10cSrcweir if (!ch2) ch2 = ch1; 689*cdf0e10cSrcweir ch1 -= 'A'; ch2 -= 'A'; 690*cdf0e10cSrcweir for (; ch1 <= ch2; ch1++) eDefTypes[ ch1 ] = t; 691*cdf0e10cSrcweir if( !TestComma() ) break; 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir // STOP/SYSTEM 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir void SbiParser::Stop() 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir aGen.Gen( _STOP ); 700*cdf0e10cSrcweir Peek(); // #35694: Nur Peek(), damit EOL in Single-Line-If erkannt wird 701*cdf0e10cSrcweir } 702*cdf0e10cSrcweir 703*cdf0e10cSrcweir // IMPLEMENTS 704*cdf0e10cSrcweir 705*cdf0e10cSrcweir void SbiParser::Implements() 706*cdf0e10cSrcweir { 707*cdf0e10cSrcweir if( !bClassModule ) 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir Error( SbERR_UNEXPECTED, IMPLEMENTS ); 710*cdf0e10cSrcweir return; 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir Peek(); 714*cdf0e10cSrcweir if( eCurTok != SYMBOL ) 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir Error( SbERR_SYMBOL_EXPECTED ); 717*cdf0e10cSrcweir return; 718*cdf0e10cSrcweir } 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir String aImplementedIface = aSym; 721*cdf0e10cSrcweir Next(); 722*cdf0e10cSrcweir if( Peek() == DOT ) 723*cdf0e10cSrcweir { 724*cdf0e10cSrcweir String aDotStr( '.' ); 725*cdf0e10cSrcweir while( Peek() == DOT ) 726*cdf0e10cSrcweir { 727*cdf0e10cSrcweir aImplementedIface += aDotStr; 728*cdf0e10cSrcweir Next(); 729*cdf0e10cSrcweir SbiToken ePeekTok = Peek(); 730*cdf0e10cSrcweir if( ePeekTok == SYMBOL || IsKwd( ePeekTok ) ) 731*cdf0e10cSrcweir { 732*cdf0e10cSrcweir Next(); 733*cdf0e10cSrcweir aImplementedIface += aSym; 734*cdf0e10cSrcweir } 735*cdf0e10cSrcweir else 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir Next(); 738*cdf0e10cSrcweir Error( SbERR_SYMBOL_EXPECTED ); 739*cdf0e10cSrcweir break; 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir } 742*cdf0e10cSrcweir } 743*cdf0e10cSrcweir aIfaceVector.push_back( aImplementedIface ); 744*cdf0e10cSrcweir } 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir void SbiParser::EnableCompatibility() 747*cdf0e10cSrcweir { 748*cdf0e10cSrcweir if( !bCompatible ) 749*cdf0e10cSrcweir AddConstants(); 750*cdf0e10cSrcweir bCompatible = sal_True; 751*cdf0e10cSrcweir } 752*cdf0e10cSrcweir 753*cdf0e10cSrcweir // OPTION 754*cdf0e10cSrcweir 755*cdf0e10cSrcweir void SbiParser::Option() 756*cdf0e10cSrcweir { 757*cdf0e10cSrcweir switch( Next() ) 758*cdf0e10cSrcweir { 759*cdf0e10cSrcweir case EXPLICIT: 760*cdf0e10cSrcweir bExplicit = sal_True; break; 761*cdf0e10cSrcweir case BASE: 762*cdf0e10cSrcweir if( Next() == NUMBER ) 763*cdf0e10cSrcweir { 764*cdf0e10cSrcweir if( nVal == 0 || nVal == 1 ) 765*cdf0e10cSrcweir { 766*cdf0e10cSrcweir nBase = (short) nVal; 767*cdf0e10cSrcweir break; 768*cdf0e10cSrcweir } 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir Error( SbERR_EXPECTED, "0/1" ); 771*cdf0e10cSrcweir break; 772*cdf0e10cSrcweir case PRIVATE: 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir String aString = SbiTokenizer::Symbol(Next()); 775*cdf0e10cSrcweir if( !aString.EqualsIgnoreCaseAscii("Module") ) 776*cdf0e10cSrcweir Error( SbERR_EXPECTED, "Module" ); 777*cdf0e10cSrcweir break; 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir case COMPARE: 780*cdf0e10cSrcweir { 781*cdf0e10cSrcweir SbiToken eTok = Next(); 782*cdf0e10cSrcweir if( eTok == BINARY ) 783*cdf0e10cSrcweir bText = sal_False; 784*cdf0e10cSrcweir else if( eTok == SYMBOL && GetSym().EqualsIgnoreCaseAscii("text") ) 785*cdf0e10cSrcweir bText = sal_True; 786*cdf0e10cSrcweir else 787*cdf0e10cSrcweir Error( SbERR_EXPECTED, "Text/Binary" ); 788*cdf0e10cSrcweir break; 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir case COMPATIBLE: 791*cdf0e10cSrcweir EnableCompatibility(); 792*cdf0e10cSrcweir break; 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir case CLASSMODULE: 795*cdf0e10cSrcweir bClassModule = sal_True; 796*cdf0e10cSrcweir aGen.GetModule().SetModuleType( com::sun::star::script::ModuleType::CLASS ); 797*cdf0e10cSrcweir break; 798*cdf0e10cSrcweir case VBASUPPORT: 799*cdf0e10cSrcweir if( Next() == NUMBER ) 800*cdf0e10cSrcweir { 801*cdf0e10cSrcweir if ( nVal == 1 || nVal == 0 ) 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir bVBASupportOn = ( nVal == 1 ); 804*cdf0e10cSrcweir if ( bVBASupportOn ) 805*cdf0e10cSrcweir EnableCompatibility(); 806*cdf0e10cSrcweir // if the module setting is different 807*cdf0e10cSrcweir // reset it to what the Option tells us 808*cdf0e10cSrcweir if ( bVBASupportOn != aGen.GetModule().IsVBACompat() ) 809*cdf0e10cSrcweir aGen.GetModule().SetVBACompat( bVBASupportOn ); 810*cdf0e10cSrcweir break; 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir Error( SbERR_EXPECTED, "0/1" ); 814*cdf0e10cSrcweir break; 815*cdf0e10cSrcweir default: 816*cdf0e10cSrcweir Error( SbERR_BAD_OPTION, eCurTok ); 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir } 819*cdf0e10cSrcweir 820*cdf0e10cSrcweir void addStringConst( SbiSymPool& rPool, const char* pSym, const String& rStr ) 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir SbiConstDef* pConst = new SbiConstDef( String::CreateFromAscii( pSym ) ); 823*cdf0e10cSrcweir pConst->SetType( SbxSTRING ); 824*cdf0e10cSrcweir pConst->Set( rStr ); 825*cdf0e10cSrcweir rPool.Add( pConst ); 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir inline void addStringConst( SbiSymPool& rPool, const char* pSym, const char* pStr ) 829*cdf0e10cSrcweir { 830*cdf0e10cSrcweir addStringConst( rPool, pSym, String::CreateFromAscii( pStr ) ); 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir void SbiParser::AddConstants( void ) 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir // #113063 Create constant RTL symbols 836*cdf0e10cSrcweir addStringConst( aPublics, "vbCr", "\x0D" ); 837*cdf0e10cSrcweir addStringConst( aPublics, "vbCrLf", "\x0D\x0A" ); 838*cdf0e10cSrcweir addStringConst( aPublics, "vbFormFeed", "\x0C" ); 839*cdf0e10cSrcweir addStringConst( aPublics, "vbLf", "\x0A" ); 840*cdf0e10cSrcweir #if defined(UNX) 841*cdf0e10cSrcweir addStringConst( aPublics, "vbNewLine", "\x0A" ); 842*cdf0e10cSrcweir #else 843*cdf0e10cSrcweir addStringConst( aPublics, "vbNewLine", "\x0D\x0A" ); 844*cdf0e10cSrcweir #endif 845*cdf0e10cSrcweir addStringConst( aPublics, "vbNullString", "" ); 846*cdf0e10cSrcweir addStringConst( aPublics, "vbTab", "\x09" ); 847*cdf0e10cSrcweir addStringConst( aPublics, "vbVerticalTab", "\x0B" ); 848*cdf0e10cSrcweir 849*cdf0e10cSrcweir // Force length 1 and make char 0 afterwards 850*cdf0e10cSrcweir String aNullCharStr( String::CreateFromAscii( " " ) ); 851*cdf0e10cSrcweir aNullCharStr.SetChar( 0, 0 ); 852*cdf0e10cSrcweir addStringConst( aPublics, "vbNullChar", aNullCharStr ); 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir // ERROR n 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir void SbiParser::ErrorStmnt() 858*cdf0e10cSrcweir { 859*cdf0e10cSrcweir SbiExpression aPar( this ); 860*cdf0e10cSrcweir aPar.Gen(); 861*cdf0e10cSrcweir aGen.Gen( _ERROR ); 862*cdf0e10cSrcweir } 863*cdf0e10cSrcweir 864