LibreOffice Module basic (master) 1
parser.cxx
Go to the documentation of this file.
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#include <basic/sberrors.hxx>
21#include <basic/sbxmeth.hxx>
22#include <basic/sbmod.hxx>
23#include <basic/sbstar.hxx>
24#include <basic/sbx.hxx>
25#include <parser.hxx>
26#include <com/sun/star/script/ModuleType.hpp>
27#include <rtl/character.hxx>
28
29struct SbiParseStack { // "Stack" for statement-blocks
33 sal_uInt32 nChain; // JUMP-Chain
34};
35
36namespace {
37
38struct SbiStatement {
39 SbiToken eTok;
40 void( SbiParser::*Func )();
41 bool bMain; // true: OK outside the SUB
42 bool bSubr; // true: OK inside the SUB
43};
44
45}
46
47#define Y true
48#define N false
49
50const SbiStatement StmntTable [] = {
51{ ATTRIBUTE, &SbiParser::Attribute, Y, Y, }, // ATTRIBUTE
52{ CALL, &SbiParser::Call, N, Y, }, // CALL
53{ CLOSE, &SbiParser::Close, N, Y, }, // CLOSE
54{ CONST_, &SbiParser::Dim, Y, Y, }, // CONST
55{ DECLARE, &SbiParser::Declare, Y, N, }, // DECLARE
56{ DEFBOOL, &SbiParser::DefXXX, Y, N, }, // DEFBOOL
57{ DEFCUR, &SbiParser::DefXXX, Y, N, }, // DEFCUR
58{ DEFDATE, &SbiParser::DefXXX, Y, N, }, // DEFDATE
59{ DEFDBL, &SbiParser::DefXXX, Y, N, }, // DEFDBL
60{ DEFERR, &SbiParser::DefXXX, Y, N, }, // DEFERR
61{ DEFINT, &SbiParser::DefXXX, Y, N, }, // DEFINT
62{ DEFLNG, &SbiParser::DefXXX, Y, N, }, // DEFLNG
63{ DEFOBJ, &SbiParser::DefXXX, Y, N, }, // DEFOBJ
64{ DEFSNG, &SbiParser::DefXXX, Y, N, }, // DEFSNG
65{ DEFSTR, &SbiParser::DefXXX, Y, N, }, // DEFSTR
66{ DEFVAR, &SbiParser::DefXXX, Y, N, }, // DEFVAR
67{ DIM, &SbiParser::Dim, Y, Y, }, // DIM
68{ DO, &SbiParser::DoLoop, N, Y, }, // DO
69{ ELSE, &SbiParser::NoIf, N, Y, }, // ELSE
70{ ELSEIF, &SbiParser::NoIf, N, Y, }, // ELSEIF
71{ ENDIF, &SbiParser::NoIf, N, Y, }, // ENDIF
72{ END, &SbiParser::Stop, N, Y, }, // END
73{ ENUM, &SbiParser::Enum, Y, N, }, // TYPE
74{ ERASE, &SbiParser::Erase, N, Y, }, // ERASE
75{ ERROR_, &SbiParser::ErrorStmnt, N, Y, }, // ERROR
76{ EXIT, &SbiParser::Exit, N, Y, }, // EXIT
77{ FOR, &SbiParser::For, N, Y, }, // FOR
78{ FUNCTION, &SbiParser::SubFunc, Y, N, }, // FUNCTION
79{ GOSUB, &SbiParser::Goto, N, Y, }, // GOSUB
80{ GLOBAL, &SbiParser::Dim, Y, N, }, // GLOBAL
81{ GOTO, &SbiParser::Goto, N, Y, }, // GOTO
82{ IF, &SbiParser::If, N, Y, }, // IF
83{ IMPLEMENTS, &SbiParser::Implements, Y, N, }, // IMPLEMENTS
84{ INPUT, &SbiParser::Input, N, Y, }, // INPUT
85{ LET, &SbiParser::Assign, N, Y, }, // LET
86{ LINE, &SbiParser::Line, N, Y, }, // LINE, -> LINE INPUT (#i92642)
87{ LINEINPUT,&SbiParser::LineInput, N, Y, }, // LINE INPUT
88{ LOOP, &SbiParser::BadBlock, N, Y, }, // LOOP
89{ LSET, &SbiParser::LSet, N, Y, }, // LSET
90{ NAME, &SbiParser::Name, N, Y, }, // NAME
91{ NEXT, &SbiParser::BadBlock, N, Y, }, // NEXT
92{ ON, &SbiParser::On, N, Y, }, // ON
93{ OPEN, &SbiParser::Open, N, Y, }, // OPEN
94{ OPTION, &SbiParser::Option, Y, N, }, // OPTION
95{ PRINT, &SbiParser::Print, N, Y, }, // PRINT
96{ PRIVATE, &SbiParser::Dim, Y, N, }, // PRIVATE
97{ PROPERTY, &SbiParser::SubFunc, Y, N, }, // FUNCTION
98{ PUBLIC, &SbiParser::Dim, Y, N, }, // PUBLIC
99{ REDIM, &SbiParser::ReDim, N, Y, }, // DIM
100{ RESUME, &SbiParser::Resume, N, Y, }, // RESUME
101{ RETURN, &SbiParser::Return, N, Y, }, // RETURN
102{ RSET, &SbiParser::RSet, N, Y, }, // RSET
103{ SELECT, &SbiParser::Select, N, Y, }, // SELECT
104{ SET, &SbiParser::Set, N, Y, }, // SET
105{ STATIC, &SbiParser::Static, Y, Y, }, // STATIC
106{ STOP, &SbiParser::Stop, N, Y, }, // STOP
107{ SUB, &SbiParser::SubFunc, Y, N, }, // SUB
108{ TYPE, &SbiParser::Type, Y, N, }, // TYPE
109{ UNTIL, &SbiParser::BadBlock, N, Y, }, // UNTIL
110{ WHILE, &SbiParser::While, N, Y, }, // WHILE
111{ WEND, &SbiParser::BadBlock, N, Y, }, // WEND
112{ WITH, &SbiParser::With, N, Y, }, // WITH
113{ WRITE, &SbiParser::Write, N, Y, }, // WRITE
114
115{ NIL, nullptr, N, N }
116};
117
119 : SbiTokenizer( pm->GetSource32(), pb ),
120 pStack(nullptr),
121 pProc(nullptr),
122 pWithVar(nullptr),
123 eEndTok(NIL),
124 bGblDefs(false),
125 bNewGblDefs(false),
126 bSingleLineIf(false),
127 bCodeCompleting(false),
128 aGlobals( aGblStrings, SbGLOBAL, this ),
129 aPublics( aGblStrings, SbPUBLIC, this ),
130 aRtlSyms( aGblStrings, SbRTL, this ),
131 aGen( *pm, this ),
132 nBase(0),
133 bExplicit(false)
134{
135 bClassModule = ( pm->GetModuleType() == css::script::ModuleType::CLASS );
136 pPool = &aPublics;
137 for(SbxDataType & eDefType : eDefTypes)
138 eDefType = SbxVARIANT; // no explicit default type
139
142
143
145
146 rTypeArray = new SbxArray; // array for user defined types
147 rEnumArray = new SbxArray; // array for Enum types
149 if ( bVBASupportOn )
151
152}
153
155
156// part of the runtime-library?
158{
160 if (!pVar)
161 return nullptr;
162
163 if (SbxMethod* pMethod = dynamic_cast<SbxMethod*>(pVar))
164 {
165 SbiProcDef* pProc_ = aRtlSyms.AddProc( rSym );
166 if (pMethod->IsRuntimeFunction())
167 {
168 pProc_->SetType( pMethod->GetRuntimeFunctionReturnType() );
169 }
170 else
171 {
172 pProc_->SetType( pVar->GetType() );
173 }
174 return pProc_;
175 }
176
177
178 SbiSymDef* pDef = aRtlSyms.AddSym(rSym);
179 pDef->SetType(eType);
180 return pDef;
181}
182
183// close global chain
184
186{
187 if( bGblDefs && nGblChain )
188 {
191 nGblChain = 0;
192 }
193 return bGblDefs;
194}
195
197{
199 p->eExitTok = eTok;
200 p->nChain = 0;
201 p->pWithVar = pWithVar;
202 p->pNext = pStack;
203 pStack = p;
204 pWithVar = pVar;
205
206 // #29955 service the for-loop level
207 if( eTok == FOR )
209}
210
212{
213 if( !pStack )
214 return;
215
217
218 // #29955 service the for-loop level
219 if( p->eExitTok == FOR )
221
222 aGen.BackChain( p->nChain );
223 pStack = p->pNext;
224 pWithVar = p->pWithVar;
225 delete p;
226}
227
228// EXIT ...
229
231{
232 SbiToken eTok = Next();
233 for( SbiParseStack* p = pStack; p; p = p->pNext )
234 {
235 SbiToken eExitTok = p->eExitTok;
236 if( eTok == eExitTok ||
237 (eTok == PROPERTY && (eExitTok == GET || eExitTok == LET) ) ) // #i109051
238 {
239 p->nChain = aGen.Gen( SbiOpcode::JUMP_, p->nChain );
240 return;
241 }
242 }
243 if( pStack )
245 else
247}
248
250{
251 Peek();
252 if( eCurTok == SYMBOL )
253 {
254 Next(); return true;
255 }
257 return false;
258}
259
260
262{
263 if( Peek() == t )
264 {
265 Next(); return true;
266 }
267 else
268 {
270 return false;
271 }
272}
273
274
276{
277 SbiToken eTok = Peek();
278 if( IsEoln( eTok ) )
279 {
280 Next();
281 return false;
282 }
283 else if( eTok != COMMA )
284 {
286 return false;
287 }
288 Next();
289 return true;
290}
291
292
294{
295 if( !IsEoln( Next() ) )
296 {
298 while( !IsEoln( Next() ) ) {}
299 }
300}
301
302
304{
305 SbiToken xe = eEndTok;
306 eEndTok = eEnd;
307 while( !bAbort && Parse() ) {}
308 eEndTok = xe;
309 if( IsEof() )
310 {
312 bAbort = true;
313 }
314}
315
317{
318 bCodeCompleting = b;
319}
320
321
323{
324 if( bAbort ) return false;
325
326 EnableErrors();
327
328 bErrorIsSymbol = false;
329 Peek();
330 bErrorIsSymbol = true;
331
332 if( IsEof() )
333 {
334 // AB #33133: If no sub has been created before,
335 // the global chain must be closed here!
336 // AB #40689: Due to the new static-handling there
337 // can be another nGblChain, so ask for it before.
338 if( bNewGblDefs && nGblChain == 0 )
340 return false;
341 }
342
343
344 if( IsEoln( eCurTok ) )
345 {
346 Next(); return true;
347 }
348
349 if( !bSingleLineIf && MayBeLabel( true ) )
350 {
351 // is a label
352 if( !pProc )
354 else
356 Next(); Peek();
357
358 if( IsEoln( eCurTok ) )
359 {
360 Next(); return true;
361 }
362 }
363
364 // end of parsing?
365 if( eCurTok == eEndTok ||
366 ( bVBASupportOn && // #i109075
367 (eCurTok == ENDFUNC || eCurTok == ENDPROPERTY || eCurTok == ENDSUB) &&
368 (eEndTok == ENDFUNC || eEndTok == ENDPROPERTY || eEndTok == ENDSUB) ) )
369 {
370 Next();
371 if( eCurTok != NIL )
372 aGen.Statement();
373 return false;
374 }
375
376 // comment?
377 if( eCurTok == REM )
378 {
379 Next(); return true;
380 }
381
382 // In vba it's possible to do Error.foobar ( even if it results in
383 // a runtime error
384 if ( eCurTok == ERROR_ && IsVBASupportOn() ) // we probably need to define a subset of keywords where this madness applies e.g. if ( IsVBASupportOn() && SymbolCanBeRedined( eCurTok ) )
385 {
386 SbiTokenizer tokens( *this );
387 tokens.Next();
388 if ( tokens.Peek() == DOT )
389 {
390 eCurTok = SYMBOL;
391 ePush = eCurTok;
392 }
393 }
394 // if there's a symbol, it's either a variable (LET)
395 // or a SUB-procedure (CALL without brackets)
396 // DOT for assignments in the WITH-block: .A=5
397 if( eCurTok == SYMBOL || eCurTok == DOT )
398 {
399 if( !pProc )
401 else
402 {
403 // for correct line and column...
404 Next();
405 Push( eCurTok );
406 aGen.Statement();
407 Symbol(nullptr);
408 }
409 }
410 else
411 {
412 Next();
413
414 // statement parsers
415
416 const SbiStatement* p;
417 for( p = StmntTable; p->eTok != NIL; p++ )
418 if( p->eTok == eCurTok )
419 break;
420 if( p->eTok != NIL )
421 {
422 if( !pProc && !p->bMain )
424 else if( pProc && !p->bSubr )
426 else
427 {
428 // AB #41606/#40689: Due to the new static-handling there
429 // can be another nGblChain, so ask for it before.
430 if( bNewGblDefs && nGblChain == 0 &&
431 ( eCurTok == SUB || eCurTok == FUNCTION || eCurTok == PROPERTY ) )
432 {
434 bNewGblDefs = false;
435 }
436 // statement-opcode at the beginning of a sub, too, please
437 if( ( p->bSubr && (eCurTok != STATIC || Peek() == SUB || Peek() == FUNCTION ) ) ||
438 eCurTok == SUB || eCurTok == FUNCTION )
439 aGen.Statement();
440 (this->*( p->Func ) )();
441 ErrCode nSbxErr = SbxBase::GetError();
442 if( nSbxErr )
443 {
445 Error( nSbxErr );
446 }
447 }
448 }
449 else
451 }
452
453 // test for the statement's end -
454 // might also be an ELSE, as there must not necessary be a : before the ELSE!
455
456 if( !IsEos() )
457 {
458 Peek();
459 if( !IsEos() && eCurTok != ELSE )
460 {
461 // if the parsing has been aborted, jump over to the ":"
463 while( !IsEos() ) Next();
464 }
465 }
466 // The parser aborts at the end, the
467 // next token has not been fetched yet!
468 return true;
469}
470
471
473{
474 if( pWithVar )
475 return pWithVar;
476
478 while( p )
479 {
480 // LoopVar can at the moment only be for with
481 if( p->pWithVar )
482 return p->pWithVar;
483 p = p->pNext;
484 }
485 return nullptr;
486}
487
488
489// assignment or subroutine call
490
491void SbiParser::Symbol( const KeywordSymbolInfo* pKeywordSymbolInfo )
492{
494 SbiExpression aVar( this, SbSYMBOL, eMode, pKeywordSymbolInfo );
495
496 bool bEQ = ( Peek() == EQ );
497 if( !bEQ && bVBASupportOn && aVar.IsBracket() )
499
500 RecursiveMode eRecMode = ( bEQ ? PREVENT_CALL : FORCE_CALL );
501 bool bSpecialMidHandling = false;
502 SbiSymDef* pDef = aVar.GetRealVar();
503 if( bEQ && pDef && pDef->GetScope() == SbRTL )
504 {
505 OUString aRtlName = pDef->GetName();
506 if( aRtlName.equalsIgnoreAsciiCase("Mid") )
507 {
508 SbiExprNode* pExprNode = aVar.GetExprNode();
509 if( pExprNode && pExprNode->GetNodeType() == SbxVARVAL )
510 {
511 SbiExprList* pPar = pExprNode->GetParameters();
512 short nParCount = pPar ? pPar->GetSize() : 0;
513 if( nParCount == 2 || nParCount == 3 )
514 {
515 if( nParCount == 2 )
516 pPar->addExpression( std::make_unique<SbiExpression>( this, -1, SbxLONG ) );
517
518 TestToken( EQ );
519 pPar->addExpression( std::make_unique<SbiExpression>( this ) );
520
521 bSpecialMidHandling = true;
522 }
523 }
524 }
525 }
526 aVar.Gen( eRecMode );
527 if( bSpecialMidHandling )
528 return;
529
530 if( !bEQ )
531 {
533 }
534 else
535 {
536 // so it must be an assignment!
537 if( !aVar.IsLvalue() )
539 TestToken( EQ );
540 SbiExpression aExpr( this );
541 aExpr.Gen();
543 if( pDef )
544 {
545 if( pDef->GetConstDef() )
547 if( pDef->GetType() == SbxOBJECT )
548 {
549 eOp = SbiOpcode::SET_;
550 if( pDef->GetTypeId() )
551 {
553 return;
554 }
555 }
556 }
557 aGen.Gen( eOp );
558 }
559}
560
561
563{
564 SbiExpression aLvalue( this, SbLVALUE );
565 TestToken( EQ );
566 SbiExpression aExpr( this );
567 aLvalue.Gen();
568 aExpr.Gen();
569 sal_uInt16 nLen = 0;
570 SbiSymDef* pDef = aLvalue.GetRealVar();
571 {
572 if( pDef->GetConstDef() )
574 nLen = aLvalue.GetRealVar()->GetLen();
575 }
576 if( nLen )
577 aGen.Gen( SbiOpcode::PAD_, nLen );
579}
580
581// assignments of an object-variable
582
584{
585 SbiExpression aLvalue( this, SbLVALUE );
586 SbxDataType eType = aLvalue.GetType();
587 if( eType != SbxOBJECT && eType != SbxEMPTY && eType != SbxVARIANT )
589 TestToken( EQ );
590 SbiSymDef* pDef = aLvalue.GetRealVar();
591 if( pDef->GetConstDef() )
593
594 SbiToken eTok = Peek();
595 if( eTok == NEW )
596 {
597 Next();
598 auto pTypeDef = std::make_unique<SbiSymDef>( OUString() );
599 TypeDecl( *pTypeDef, true );
600
601 aLvalue.Gen();
602 aGen.Gen( SbiOpcode::CREATE_, pDef->GetId(), pTypeDef->GetTypeId() );
604 }
605 else
606 {
607 SbiExpression aExpr( this );
608 aLvalue.Gen();
609 aExpr.Gen();
610 // It's a good idea to distinguish between
611 // set something = another &
612 // something = another
613 // ( it's necessary for vba objects where set is object
614 // specific and also doesn't involve processing default params )
615 if( pDef->GetTypeId() )
616 {
617 if ( bVBASupportOn )
619 else
621 }
622 else
623 {
624 if ( bVBASupportOn )
626 else
628 }
629 }
630}
631
632// JSM 07.10.95
634{
635 SbiExpression aLvalue( this, SbLVALUE );
636 if( aLvalue.GetType() != SbxSTRING )
637 {
639 }
640 TestToken( EQ );
641 SbiSymDef* pDef = aLvalue.GetRealVar();
642 if( pDef && pDef->GetConstDef() )
643 {
645 }
646 SbiExpression aExpr( this );
647 aLvalue.Gen();
648 aExpr.Gen();
650}
651
652// JSM 07.10.95
654{
655 SbiExpression aLvalue( this, SbLVALUE );
656 if( aLvalue.GetType() != SbxSTRING )
657 {
659 }
660 TestToken( EQ );
661 SbiSymDef* pDef = aLvalue.GetRealVar();
662 if( pDef && pDef->GetConstDef() )
664 SbiExpression aExpr( this );
665 aLvalue.Gen();
666 aExpr.Gen();
668}
669
670// DEFINT, DEFLNG, DEFSNG, DEFDBL, DEFSTR and so on
671
673{
674 sal_Unicode ch1, ch2;
676
677 while( !bAbort )
678 {
679 if( Next() != SYMBOL ) break;
680 ch1 = rtl::toAsciiUpperCase(aSym[0]);
681 ch2 = 0;
682 if( Peek() == MINUS )
683 {
684 Next();
686 else
687 {
688 ch2 = rtl::toAsciiUpperCase(aSym[0]);
689 if( ch2 < ch1 )
690 {
692 ch2 = 0;
693 }
694 }
695 }
696 if (!ch2) ch2 = ch1;
697 ch1 -= 'A'; ch2 -= 'A';
698 for (; ch1 <= ch2; ch1++) eDefTypes[ ch1 ] = t;
699 if( !TestComma() ) break;
700 }
701}
702
703// STOP/SYSTEM
704
706{
708 Peek(); // #35694: only Peek(), so that EOL is recognized in Single-Line-If
709}
710
711// IMPLEMENTS
712
714{
715 if( !bClassModule )
716 {
718 return;
719 }
720
721 Peek();
722 if( eCurTok != SYMBOL )
723 {
725 return;
726 }
727
728 OUString aImplementedIface = aSym;
729 Next();
730 if( Peek() == DOT )
731 {
732 OUString aDotStr( '.' );
733 while( Peek() == DOT )
734 {
735 aImplementedIface += aDotStr;
736 Next();
737 SbiToken ePeekTok = Peek();
738 if( ePeekTok == SYMBOL || IsKwd( ePeekTok ) )
739 {
740 Next();
741 aImplementedIface += aSym;
742 }
743 else
744 {
745 Next();
747 break;
748 }
749 }
750 }
751 aIfaceVector.push_back( aImplementedIface );
752}
753
755{
756 if( !bCompatible )
757 AddConstants();
758 bCompatible = true;
759}
760
761// OPTION
762
764{
765 switch( Next() )
766 {
767 case BASIC_EXPLICIT:
768 bExplicit = true; break;
769 case BASE:
770 if( Next() == NUMBER && ( nVal == 0 || nVal == 1 ) )
771 {
772 nBase = static_cast<short>(nVal);
773 break;
774 }
776 break;
777 case PRIVATE:
778 {
779 OUString aString = SbiTokenizer::Symbol(Next());
780 if( !aString.equalsIgnoreAsciiCase("Module") )
781 {
782 Error( ERRCODE_BASIC_EXPECTED, "Module" );
783 }
784 break;
785 }
786 case COMPARE:
787 {
788 SbiToken eTok = Next();
789 if( eTok == BINARY )
790 {
791 }
792 else if( eTok == SYMBOL && GetSym().equalsIgnoreAsciiCase("text") )
793 {
794 }
795 else
796 {
797 Error( ERRCODE_BASIC_EXPECTED, "Text/Binary" );
798 }
799 break;
800 }
801 case COMPATIBLE:
803 break;
804
805 case CLASSMODULE:
806 bClassModule = true;
807 aGen.GetModule().SetModuleType( css::script::ModuleType::CLASS );
808 break;
809 case VBASUPPORT: // Option VBASupport used to override the module mode ( in fact this must reset the mode
810 if( Next() == NUMBER )
811 {
812 if ( nVal == 1 || nVal == 0 )
813 {
814 bVBASupportOn = ( nVal == 1 );
815 if ( bVBASupportOn )
816 {
818 }
819 // if the module setting is different
820 // reset it to what the Option tells us
822 {
824 }
825 break;
826 }
827 }
829 break;
830 default:
832 }
833}
834
835static void addStringConst( SbiSymPool& rPool, const OUString& pSym, const OUString& rStr )
836{
837 SbiConstDef* pConst = new SbiConstDef( pSym );
838 pConst->SetType( SbxSTRING );
839 pConst->Set( rStr );
840 rPool.Add( pConst );
841}
842
843static void addNumericConst(SbiSymPool& rPool, const OUString& pSym, double nVal)
844{
845 SbiConstDef* pConst = new SbiConstDef(pSym);
846 pConst->Set(nVal, SbxDOUBLE);
847 rPool.Add(pConst);
848}
849
851{
852 // tdf#153543 - shell constants
853 // See https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-constants
854 addNumericConst(aPublics, "vbHide", 0);
855 addNumericConst(aPublics, "vbNormalFocus", 1);
856 addNumericConst(aPublics, "vbMinimizedFocus", 2);
857 addNumericConst(aPublics, "vbMaximizedFocus", 3);
858 addNumericConst(aPublics, "vbNormalNoFocus", 4);
859 addNumericConst(aPublics, "vbMinimizedNoFocus", 6);
860
861 // tdf#131563 - add vba color constants
862 // See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/color-constants
863 addNumericConst(aPublics, "vbBlack", 0x0);
864 addNumericConst(aPublics, "vbRed", 0xFF);
865 addNumericConst(aPublics, "vbGreen", 0xFF00);
866 addNumericConst(aPublics, "vbYellow", 0xFFFF);
867 addNumericConst(aPublics, "vbBlue", 0xFF0000);
868 addNumericConst(aPublics, "vbMagenta", 0xFF00FF);
869 addNumericConst(aPublics, "vbCyan", 0xFFFF00);
870 addNumericConst(aPublics, "vbWhite", 0xFFFFFF);
871
872 // #113063 Create constant RTL symbols
873 addStringConst( aPublics, "vbCr", "\x0D" );
874 addStringConst( aPublics, "vbCrLf", "\x0D\x0A" );
875 addStringConst( aPublics, "vbFormFeed", "\x0C" );
876 addStringConst( aPublics, "vbLf", "\x0A" );
877#ifdef _WIN32
878 addStringConst( aPublics, "vbNewLine", "\x0D\x0A" );
879#else
880 addStringConst( aPublics, "vbNewLine", "\x0A" );
881#endif
882 addStringConst( aPublics, "vbNullString", "" );
883 addStringConst( aPublics, "vbTab", "\x09" );
884 addStringConst( aPublics, "vbVerticalTab", "\x0B" );
885
886 addStringConst( aPublics, "vbNullChar", OUString(u'\0') );
887}
888
889// ERROR n
890
892{
893 SbiExpression aPar( this );
894 aPar.Gen();
896}
897
898/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
sal_Int32 GetModuleType() const
Definition: sbmod.hxx:128
void SetModuleType(sal_Int32 nType)
Definition: sbmod.hxx:129
SAL_DLLPRIVATE void SetVBASupport(bool bSupport)
Definition: sbxmod.cxx:978
bool IsVBASupport() const
Definition: sbmod.hxx:126
void DecForLevel()
Definition: codegen.hxx:53
sal_uInt32 Gen(SbiOpcode)
Definition: codegen.cxx:88
void BackChain(sal_uInt32 off)
Definition: codegen.hxx:44
void IncForLevel()
Definition: codegen.hxx:52
SbModule & GetModule()
Definition: codegen.hxx:39
void Statement()
Definition: codegen.cxx:56
void Set(double, SbxDataType)
Definition: symtbl.cxx:516
short GetSize() const
Definition: expr.hxx:100
void addExpression(std::unique_ptr< SbiExpression > &&pExpr)
Definition: exprtree.cxx:904
SbiNodeType GetNodeType() const
Definition: expr.hxx:153
SbiExprList * GetParameters()
Definition: expr.hxx:159
void Gen(RecursiveMode eRecMode=UNDEFINED)
Definition: exprgen.cxx:260
SbiSymDef * GetRealVar()
Definition: expr.hxx:209
SbiExprNode * GetExprNode()
Definition: expr.hxx:210
bool IsBracket() const
Definition: expr.hxx:203
bool IsLvalue() const
Definition: expr.hxx:206
SbxDataType GetType() const
Definition: expr.hxx:211
SbiSymPool * pPool
Definition: parser.hxx:69
void Implements()
Definition: parser.cxx:713
void Declare()
Definition: dim.cxx:1038
void BadBlock()
Definition: loops.cxx:292
bool HasGlobalCode()
Definition: parser.cxx:185
void Attribute()
Definition: dim.cxx:1160
void On()
Definition: loops.cxx:471
void Set()
Definition: parser.cxx:583
void Exit()
Definition: parser.cxx:230
void LSet()
Definition: parser.cxx:633
void While()
Definition: loops.cxx:194
bool bNewGblDefs
Definition: parser.hxx:41
void Type()
Definition: dim.cxx:598
void Close()
Definition: io.cxx:288
bool TestComma()
Definition: parser.cxx:275
SbxArrayRef rTypeArray
Definition: parser.hxx:61
bool bExplicit
Definition: parser.hxx:71
void StmntBlock(SbiToken)
Definition: parser.cxx:303
bool Parse()
Definition: parser.cxx:322
void Resume()
Definition: loops.cxx:537
void Input()
Definition: io.cxx:146
bool TestToken(SbiToken)
Definition: parser.cxx:261
void TestEoln()
Definition: parser.cxx:293
SbiExprNode * GetWithVar()
Definition: parser.cxx:472
void Select()
Definition: loops.cxx:361
void ReDim()
Definition: dim.cxx:578
SbxDataType eDefTypes[N_DEF_TYPES]
Definition: parser.hxx:76
void Option()
Definition: parser.cxx:763
void Stop()
Definition: parser.cxx:705
void AddConstants()
Definition: parser.cxx:850
bool bClassModule
Definition: parser.hxx:72
sal_uInt32 nGblChain
Definition: parser.hxx:39
void LineInput()
Definition: io.cxx:130
SbiSymPool aPublics
Definition: parser.hxx:66
void SubFunc()
Definition: dim.cxx:1193
void OpenBlock(SbiToken, SbiExprNode *=nullptr)
Definition: parser.cxx:196
void If()
Definition: loops.cxx:28
SbiSymPool aRtlSyms
Definition: parser.hxx:67
std::vector< OUString > aIfaceVector
Definition: parser.hxx:73
SbxArrayRef rEnumArray
Definition: parser.hxx:62
void For()
Definition: loops.cxx:207
void Static()
Definition: dim.cxx:1310
short nBase
Definition: parser.hxx:70
void Goto()
Definition: loops.cxx:334
void TypeDecl(SbiSymDef &, bool bAsNewAlreadyParsed=false)
Definition: dim.cxx:79
void ErrorStmnt()
Definition: parser.cxx:891
void Erase()
Definition: dim.cxx:585
SbiSymDef * CheckRTLForSym(const OUString &rSym, SbxDataType eType)
Definition: parser.cxx:157
void Symbol(const KeywordSymbolInfo *pKeywordSymbolInfo)
Definition: parser.cxx:491
void Open()
Definition: io.cxx:170
SbiParser(StarBASIC *, SbModule *)
Definition: parser.cxx:118
~SbiParser()
Definition: parser.cxx:154
void Name()
Definition: io.cxx:264
void EnableCompatibility()
Definition: parser.cxx:754
bool bCodeCompleting
Definition: parser.hxx:43
void Return()
Definition: loops.cxx:348
void Write()
Definition: io.cxx:79
bool bSingleLineIf
Definition: parser.hxx:42
bool bGblDefs
Definition: parser.hxx:40
void Assign()
Definition: parser.cxx:562
SbiProcDef * pProc
Definition: parser.hxx:36
void Print()
Definition: io.cxx:48
bool TestSymbol()
Definition: parser.cxx:249
void RSet()
Definition: parser.cxx:653
void Call()
Definition: dim.cxx:1184
void DoLoop()
Definition: loops.cxx:154
void CloseBlock()
Definition: parser.cxx:211
SbiExprNode * pWithVar
Definition: parser.hxx:37
void Dim()
Definition: dim.cxx:197
void NoIf()
Definition: loops.cxx:145
void SetCodeCompleting(bool b)
Definition: parser.cxx:316
SbiParseStack * pStack
Definition: parser.hxx:35
SbiToken eEndTok
Definition: parser.hxx:38
void With()
Definition: loops.cxx:268
void DefXXX()
Definition: parser.cxx:672
SbiCodeGen aGen
Definition: parser.hxx:68
void Line()
Definition: io.cxx:107
SbiSymPool aGlobals
Definition: parser.hxx:65
void Enum()
Definition: dim.cxx:716
SbiSymPool & GetLabels()
Definition: symtbl.hxx:178
virtual void SetType(SbxDataType) override
Definition: symtbl.cxx:436
bool bAbort
Definition: scanner.hxx:59
bool bVBASupportOn
Definition: scanner.hxx:63
double nVal
Definition: scanner.hxx:48
bool IsVBASupportOn() const
Definition: scanner.hxx:77
void EnableErrors()
Definition: scanner.hxx:73
const OUString & GetSym() const
Definition: scanner.hxx:91
OUString aSym
Definition: scanner.hxx:45
bool bCompatible
Definition: scanner.hxx:62
StarBASIC * GetBasic()
Definition: scanner.hxx:83
SbiSymScope GetScope() const
Definition: symtbl.cxx:394
sal_uInt16 GetId() const
Definition: symtbl.hxx:120
virtual SbiConstDef * GetConstDef()
Definition: symtbl.cxx:315
sal_uInt16 GetTypeId() const
Definition: symtbl.hxx:121
short GetLen() const
Definition: symtbl.hxx:125
SbxDataType GetType() const
Definition: symtbl.hxx:115
const OUString & GetName()
Definition: symtbl.cxx:321
virtual void SetType(SbxDataType)
Definition: symtbl.cxx:331
SbiProcDef * AddProc(const OUString &)
Definition: symtbl.cxx:150
sal_uInt32 Define(const OUString &)
Definition: symtbl.cxx:239
void SetParent(SbiSymPool *p)
Definition: symtbl.hxx:63
void Add(SbiSymDef *)
Definition: symtbl.cxx:164
SbiSymDef * AddSym(const OUString &)
Definition: symtbl.cxx:139
SbiToken ePush
Definition: token.hxx:104
void Push(SbiToken)
Definition: token.cxx:227
bool IsEos() const
Definition: token.hxx:114
static bool IsKwd(SbiToken t)
Definition: token.hxx:129
bool IsEof() const
Definition: token.hxx:113
bool MayBeLabel(bool=false)
Definition: token.cxx:545
SbiToken Next()
Definition: token.cxx:309
bool bErrorIsSymbol
Definition: token.hxx:109
static bool IsEoln(SbiToken t)
Definition: token.hxx:127
void Error(ErrCode c)
Definition: token.hxx:123
SbiToken Peek()
Definition: token.cxx:248
SbiToken eCurTok
Definition: token.hxx:103
const OUString & Symbol(SbiToken)
Definition: token.cxx:266
Definition: sbx.hxx:95
static ErrCode const & GetError()
Definition: sbxbase.cxx:96
static void ResetError()
Definition: sbxbase.cxx:128
virtual SbxVariable * Find(const OUString &, SbxClassType)
Definition: sbxobj.cxx:182
virtual SbxDataType GetType() const override
Definition: sbxvar.cxx:321
SbxObject * GetRtl()
Definition: sbstar.hxx:103
float u
RecursiveMode
Definition: expr.hxx:82
@ FORCE_CALL
Definition: expr.hxx:84
@ PREVENT_CALL
Definition: expr.hxx:85
@ SbLVALUE
Definition: expr.hxx:55
@ SbSYMBOL
Definition: expr.hxx:56
@ SbxVARVAL
Definition: expr.hxx:74
SbiExprMode
Definition: expr.hxx:60
@ EXPRMODE_STANDARD
Definition: expr.hxx:61
@ EXPRMODE_STANDALONE
Definition: expr.hxx:62
DocumentType eType
Mode eMode
void * p
dictionary tokens
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
SbiOpcode
Definition: opcodes.hxx:25
const SbiStatement StmntTable[]
Definition: parser.cxx:50
#define N
Definition: parser.cxx:48
#define Y
Definition: parser.cxx:47
static void addStringConst(SbiSymPool &rPool, const OUString &pSym, const OUString &rStr)
Definition: parser.cxx:835
static void addNumericConst(SbiSymPool &rPool, const OUString &pSym, double nVal)
Definition: parser.cxx:843
#define ERRCODE_BASIC_EXPECTED
Definition: sberrors.hxx:125
#define ERRCODE_BASIC_NOT_IN_MAIN
Definition: sberrors.hxx:147
#define ERRCODE_BASIC_INVALID_OBJECT
Definition: sberrors.hxx:41
#define ERRCODE_BASIC_NOT_IN_SUBR
Definition: sberrors.hxx:146
#define ERRCODE_BASIC_UNEXPECTED
Definition: sberrors.hxx:124
#define ERRCODE_BASIC_LVALUE_EXPECTED
Definition: sberrors.hxx:129
#define ERRCODE_BASIC_SYMBOL_EXPECTED
Definition: sberrors.hxx:126
#define ERRCODE_BASIC_SYNTAX
Definition: sberrors.hxx:25
#define ERRCODE_BASIC_DUPLICATE_DEF
Definition: sberrors.hxx:59
#define ERRCODE_BASIC_BAD_BLOCK
Definition: sberrors.hxx:139
#define ERRCODE_BASIC_BAD_EXIT
Definition: sberrors.hxx:138
#define ERRCODE_BASIC_BAD_OPTION
Definition: sberrors.hxx:149
SbxDataType
Definition: sbxdef.hxx:37
@ SbxOBJECT
Definition: sbxdef.hxx:47
@ SbxLONG
Definition: sbxdef.hxx:41
@ SbxEMPTY
Definition: sbxdef.hxx:38
@ SbxVARIANT
Definition: sbxdef.hxx:51
@ SbxSTRING
Definition: sbxdef.hxx:46
@ SbxINTEGER
Definition: sbxdef.hxx:40
@ SbxDOUBLE
Definition: sbxdef.hxx:43
#define CONST_
Definition: stdobj.cxx:46
sal_uInt32 nChain
Definition: parser.cxx:33
SbiExprNode * pWithVar
Definition: parser.cxx:31
SbiParseStack * pNext
Definition: parser.cxx:30
SbiToken eExitTok
Definition: parser.cxx:32
@ SbPUBLIC
Definition: symtbl.hxx:32
@ SbRTL
Definition: symtbl.hxx:32
@ SbGLOBAL
Definition: symtbl.hxx:32
SbiToken
Definition: token.hxx:30
@ OPEN
Definition: token.hxx:58
@ PRIVATE
Definition: token.hxx:59
@ GET
Definition: token.hxx:54
@ NUMBER
Definition: token.hxx:78
@ SUB
Definition: token.hxx:61
@ DEFSNG
Definition: token.hxx:43
@ SELECT
Definition: token.hxx:61
@ REDIM
Definition: token.hxx:60
@ VBASUPPORT
Definition: token.hxx:98
@ IF
Definition: token.hxx:55
@ WEND
Definition: token.hxx:64
@ WHILE
Definition: token.hxx:64
@ ERASE
Definition: token.hxx:52
@ RESUME
Definition: token.hxx:60
@ DEFCUR
Definition: token.hxx:43
@ IMPLEMENTS
Definition: token.hxx:58
@ DEFDBL
Definition: token.hxx:43
@ DEFBOOL
Definition: token.hxx:44
@ ENDFUNC
Definition: token.hxx:65
@ RETURN
Definition: token.hxx:60
@ LINEINPUT
Definition: token.hxx:56
@ ENUM
Definition: token.hxx:62
@ ENDIF
Definition: token.hxx:65
@ DEFSTR
Definition: token.hxx:43
@ WRITE
Definition: token.hxx:64
@ LOOP
Definition: token.hxx:56
@ DEFLNG
Definition: token.hxx:43
@ STOP
Definition: token.hxx:61
@ NAME
Definition: token.hxx:57
@ NIL
Definition: token.hxx:31
@ CLOSE
Definition: token.hxx:39
@ DIM
Definition: token.hxx:40
@ REM
Definition: token.hxx:60
@ EXIT
Definition: token.hxx:52
@ ELSEIF
Definition: token.hxx:52
@ ENDPROPERTY
Definition: token.hxx:65
@ DEFINT
Definition: token.hxx:43
@ GOSUB
Definition: token.hxx:54
@ DOT
Definition: token.hxx:33
@ ELSE
Definition: token.hxx:52
@ DEFVAR
Definition: token.hxx:44
@ ENDSUB
Definition: token.hxx:65
@ PROPERTY
Definition: token.hxx:59
@ ON
Definition: token.hxx:58
@ EOLN
Definition: token.hxx:69
@ ATTRIBUTE
Definition: token.hxx:58
@ EQ
Definition: token.hxx:73
@ UNTIL
Definition: token.hxx:63
@ BASE
Definition: token.hxx:80
@ FOR
Definition: token.hxx:53
@ OPTION
Definition: token.hxx:58
@ DECLARE
Definition: token.hxx:40
@ FUNCTION
Definition: token.hxx:53
@ LINE
Definition: token.hxx:56
@ PRINT
Definition: token.hxx:59
@ RSET
Definition: token.hxx:60
@ NEXT
Definition: token.hxx:57
@ COMPATIBLE
Definition: token.hxx:81
@ SET
Definition: token.hxx:61
@ TYPE
Definition: token.hxx:62
@ ERROR_
Definition: token.hxx:49
@ CALL
Definition: token.hxx:39
@ DO
Definition: token.hxx:40
@ DEFDATE
Definition: token.hxx:43
@ DEFERR
Definition: token.hxx:44
@ END
Definition: token.hxx:52
@ LSET
Definition: token.hxx:56
@ BASIC_EXPLICIT
Definition: token.hxx:81
@ GOTO
Definition: token.hxx:54
@ DEFOBJ
Definition: token.hxx:43
@ INPUT
Definition: token.hxx:55
@ SYMBOL
Definition: token.hxx:78
@ STATIC
Definition: token.hxx:61
@ PUBLIC
Definition: token.hxx:59
@ NEW
Definition: token.hxx:57
@ BINARY
Definition: token.hxx:79
@ MINUS
Definition: token.hxx:72
@ COMMA
Definition: token.hxx:33
@ LET
Definition: token.hxx:56
@ WITH
Definition: token.hxx:64
@ GLOBAL
Definition: token.hxx:54
@ COMPARE
Definition: token.hxx:39
sal_uInt16 sal_Unicode