diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-11-03 09:07:25 -0500 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-11-03 20:24:28 -0500 |
commit | d92814f462432b52b1ef4d0dc335d22af881397b (patch) | |
tree | b5d9c03dae16bc2b19ad36f2f3894f723b1b8231 /basic/source/comp | |
parent | 4316e643ef345b0f673b4a03a80a4b7cb3185588 (diff) |
basic: preliminary cosmetic clean-up
parsing 1000s of line of code is hard enough without having to fight
with weird indentation and irregular formatting.
So as the review progress, in order to follow the code, cosmetic changes
were made...
In order to minimize the task of the reviewers and allow them to
concentrate on what matter, an effort is made to collect these
cosmetic changes into this separate commit.
Change-Id: I3c9b04a0150d0d0a048c2e976fe24de4f2b6b98a
Diffstat (limited to 'basic/source/comp')
-rw-r--r-- | basic/source/comp/codegen.cxx | 42 | ||||
-rw-r--r-- | basic/source/comp/dim.cxx | 118 | ||||
-rw-r--r-- | basic/source/comp/exprgen.cxx | 42 | ||||
-rw-r--r-- | basic/source/comp/exprtree.cxx | 221 | ||||
-rw-r--r-- | basic/source/comp/loops.cxx | 20 | ||||
-rw-r--r-- | basic/source/comp/parser.cxx | 16 | ||||
-rw-r--r-- | basic/source/comp/sbcomp.cxx | 86 | ||||
-rw-r--r-- | basic/source/comp/symtbl.cxx | 35 | ||||
-rw-r--r-- | basic/source/comp/token.cxx | 120 |
9 files changed, 524 insertions, 176 deletions
diff --git a/basic/source/comp/codegen.cxx b/basic/source/comp/codegen.cxx index 6642cb13f6f1..3f389eb04188 100644 --- a/basic/source/comp/codegen.cxx +++ b/basic/source/comp/codegen.cxx @@ -149,17 +149,21 @@ void SbiCodeGen::Save() { GetSbData()->pClassFac->RemoveClassModule( &rMod ); // Only a ClassModule can revert to Normal - if ( rMod.mnType == com::sun::star::script::ModuleType::CLASS ) + if ( rMod.mnType == com::sun::star::script::ModuleType::CLASS ) + { rMod.mnType = com::sun::star::script::ModuleType::NORMAL; + } rMod.bIsProxyModule = false; } // GlobalCode-Flag if( pParser->HasGlobalCode() ) + { p->SetFlag( SBIMG_INITCODE ); + } // Die Entrypoints: for( SbiSymDef* pDef = pParser->aPublics.First(); pDef; - pDef = pParser->aPublics.Next() ) + pDef = pParser->aPublics.Next() ) { SbiProcDef* pProc = pDef->GetProcDef(); if( pProc && pProc->IsDefined() ) @@ -198,8 +202,9 @@ void SbiCodeGen::Save() for( sal_uInt16 nPass = 0 ; nPass < nPassCount ; nPass++ ) { if( nPass == 1 ) + { aProcName = aIfaceProcName; - + } PropertyMode ePropMode = pProc->getPropertyMode(); if( ePropMode != PROPERTY_MODE_NONE ) { @@ -249,8 +254,9 @@ void SbiCodeGen::Save() // Declare? -> Hidden if( pProc->GetLib().Len() > 0 ) + { pMeth->SetFlag( SBX_HIDDEN ); - + } pMeth->nStart = pProc->GetAddr(); pMeth->nLine1 = pProc->GetLine1(); pMeth->nLine2 = pProc->GetLine2(); @@ -275,24 +281,35 @@ void SbiCodeGen::Save() SbiSymDef* pPar = pPool->Get( i ); SbxDataType t = pPar->GetType(); if( !pPar->IsByVal() ) + { t = (SbxDataType) ( t | SbxBYREF ); + } if( pPar->GetDims() ) + { t = (SbxDataType) ( t | SbxARRAY ); + } // #33677 hand-over an Optional-Info sal_uInt16 nFlags = SBX_READ; if( pPar->IsOptional() ) + { nFlags |= SBX_OPTIONAL; - + } pInfo->AddParam( pPar->GetName(), t, nFlags ); sal_uInt32 nUserData = 0; sal_uInt16 nDefaultId = pPar->GetDefaultId(); if( nDefaultId ) + { nUserData |= nDefaultId; + } if( pPar->IsParamArray() ) + { nUserData |= PARAM_INFO_PARAMARRAY; + } if( pPar->IsWithBrackets() ) + { nUserData |= PARAM_INFO_WITHBRACKETS; + } if( nUserData ) { SbxParamInfo* pParam = (SbxParamInfo*)pInfo->GetParam( i ); @@ -301,7 +318,6 @@ void SbiCodeGen::Save() } pMeth->SetInfo( pInfo ); } - } // for( iPass... } } @@ -314,23 +330,29 @@ void SbiCodeGen::Save() p->MakeStrings( nSize ); sal_uInt16 i; for( i = 1; i <= nSize; i++ ) + { p->AddString( pPool->Find( i ) ); - + } // Insert types sal_uInt16 nCount = pParser->rTypeArray->Count(); for (i = 0; i < nCount; i++) + { p->AddType((SbxObject *)pParser->rTypeArray->Get(i)); - + } // Insert enum objects nCount = pParser->rEnumArray->Count(); for (i = 0; i < nCount; i++) + { p->AddEnum((SbxObject *)pParser->rEnumArray->Get(i)); - + } if( !p->IsError() ) + { rMod.pImage = p; + } else + { delete p; - + } rMod.EndDefinitions(); } diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx index 70d441e8003a..b2f5dc55080b 100644 --- a/basic/source/comp/dim.cxx +++ b/basic/source/comp/dim.cxx @@ -824,17 +824,25 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl ) { Next(); if( Next() == FIXSTRING ) + { pDef->GetLib() = aSym; + } else + { Error( SbERR_SYNTAX ); + } } if( Peek() == ALIAS ) { Next(); if( Next() == FIXSTRING ) + { pDef->GetAlias() = aSym; + } else + { Error( SbERR_SYNTAX ); + } } if( !bDecl ) { @@ -844,7 +852,9 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl ) if( pDef->GetAlias().Len() ) Error( SbERR_UNEXPECTED, ALIAS ); if( pDef->IsCdecl() ) + { Error( SbERR_UNEXPECTED, _CDECL_ ); + } pDef->SetCdecl( false ); pDef->GetLib().Erase(); pDef->GetAlias().Erase(); @@ -853,9 +863,13 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl ) { // ALIAS and CDECL only together with LIB if( pDef->GetAlias().Len() ) + { Error( SbERR_UNEXPECTED, ALIAS ); + } if( pDef->IsCdecl() ) + { Error( SbERR_UNEXPECTED, _CDECL_ ); + } pDef->SetCdecl( false ); pDef->GetAlias().Erase(); } @@ -927,9 +941,13 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl ) } TypeDecl( *pDef ); if( eType != SbxVARIANT && pDef->GetType() != eType ) + { Error( SbERR_BAD_DECLARATION, aName ); + } if( pDef->GetType() == SbxVARIANT && !( bFunc || bProp ) ) + { pDef->SetType( SbxEMPTY ); + } return pDef; } @@ -944,7 +962,9 @@ void SbiParser::DefDeclare( bool bPrivate ) { Next(); if( eCurTok != SUB && eCurTok != FUNCTION ) + { Error( SbERR_UNEXPECTED, eCurTok ); + } else { bool bFunction = (eCurTok == FUNCTION); @@ -953,7 +973,9 @@ void SbiParser::DefDeclare( bool bPrivate ) if( pDef ) { if( !pDef->GetLib().Len() ) + { Error( SbERR_EXPECTED, LIB ); + } // Is it already there? SbiSymDef* pOld = aPublics.Find( pDef->GetName() ); if( pOld ) @@ -967,11 +989,14 @@ void SbiParser::DefDeclare( bool bPrivate ) pDef = NULL; } else + { pDef->Match( p ); + } } else + { aPublics.Add( pDef ); - + } if ( pDef ) { pDef->SetPublic( !bPrivate ); @@ -996,8 +1021,9 @@ void SbiParser::DefDeclare( bool bPrivate ) SbxDataType eType = pDef->GetType(); if( bFunction ) + { aGen.Gen( _PARAM, 0, sal::static_int_cast< sal_uInt16 >( eType ) ); - + } if( nParCount > 1 ) { aGen.Gen( _ARGC ); @@ -1026,14 +1052,19 @@ void SbiParser::DefDeclare( bool bPrivate ) SbiOpcode eOp = pDef->IsCdecl() ? _CALLC : _CALL; sal_uInt16 nId = pDef->GetId(); if( pDef->GetAlias().Len() ) + { nId = ( nId & 0x8000 ) | aGblStrings.Add( pDef->GetAlias() ); + } if( nParCount > 1 ) + { nId |= 0x8000; + } aGen.Gen( eOp, nId, sal::static_int_cast< sal_uInt16 >( eType ) ); if( bFunction ) + { aGen.Gen( _PUT ); - + } aGen.Gen( _LEAVE ); } } @@ -1047,14 +1078,19 @@ void SbiParser::Attribute() while( Next() != EQ ) { if( Next() != DOT) + { break; + } } if( eCurTok != EQ ) + { Error( SbERR_SYNTAX ); + } else + { SbiExpression aValue( this ); - + } // Don't generate any code - just discard it. } @@ -1086,19 +1122,29 @@ void SbiParser::DefProc( bool bStatic, bool bPrivate ) { Next(); if( eCurTok == GET ) + { ePropertyMode = PROPERTY_MODE_GET; + } else if( eCurTok == LET ) + { ePropertyMode = PROPERTY_MODE_LET; + } else if( eCurTok == SET ) + { ePropertyMode = PROPERTY_MODE_SET; + } else + { Error( SbERR_EXPECTED, "Get or Let or Set" ); + } } SbiToken eExit = eCurTok; SbiProcDef* pDef = ProcDecl( false ); if( !pDef ) + { return; + } pDef->setPropertyMode( ePropertyMode ); // Is the Proc already declared? @@ -1137,10 +1183,13 @@ void SbiParser::DefProc( bool bStatic, bool bPrivate ) } } else + { aPublics.Add( pDef ), pProc = pDef; - + } if( !pProc ) + { return; + } pProc->SetPublic( !bPrivate ); // Now we set the search hierarchy for symbols as well as the @@ -1148,16 +1197,20 @@ void SbiParser::DefProc( bool bStatic, bool bPrivate ) aPublics.SetProcId( pProc->GetId() ); pProc->GetParams().SetParent( &aPublics ); if( bStatic ) - { + { if ( bVBASupportOn ) + { pProc->SetStatic( sal_True ); + } else + { Error( SbERR_NOT_IMPLEMENTED ); // STATIC SUB ... } - else + } + else { pProc->SetStatic( sal_False ); - } + } // Normal case: Local variable->parameter->global variable pProc->GetLocals().SetParent( &pProc->GetParams() ); pPool = &pProc->GetLocals(); @@ -1186,30 +1239,35 @@ void SbiParser::Static() void SbiParser::DefStatic( bool bPrivate ) { + SbiSymPool* p; + switch( Peek() ) { - case SUB: - case FUNCTION: - case PROPERTY: - // End global chain if necessary (not done in - // SbiParser::Parse() under these conditions - if( bNewGblDefs && nGblChain == 0 ) - { - nGblChain = aGen.Gen( _JUMP, 0 ); - bNewGblDefs = false; - } - Next(); - DefProc( true, bPrivate ); - break; - default: { - if( !pProc ) - Error( SbERR_NOT_IN_SUBR ); - // Reset the Pool, so that STATIC-Declarations go into the - // global Pool - SbiSymPool* p = pPool; pPool = &aPublics; - DefVar( _STATIC, true ); - pPool = p; - } break; + case SUB: + case FUNCTION: + case PROPERTY: + // End global chain if necessary (not done in + // SbiParser::Parse() under these conditions + if( bNewGblDefs && nGblChain == 0 ) + { + nGblChain = aGen.Gen( _JUMP, 0 ); + bNewGblDefs = false; + } + Next(); + DefProc( true, bPrivate ); + break; + default: + if( !pProc ) + { + Error( SbERR_NOT_IN_SUBR ); + } + // Reset the Pool, so that STATIC-Declarations go into the + // global Pool + p = pPool; + pPool = &aPublics; + DefVar( _STATIC, true ); + pPool = p; + break; } } diff --git a/basic/source/comp/exprgen.cxx b/basic/source/comp/exprgen.cxx index d752993b07fa..13ce100fe1cb 100644 --- a/basic/source/comp/exprgen.cxx +++ b/basic/source/comp/exprgen.cxx @@ -57,22 +57,26 @@ static OpTable aOpTable [] = { // Output of an element void SbiExprNode::Gen( RecursiveMode eRecMode ) { + sal_uInt16 nStringId; + if( IsConstant() ) { switch( GetType() ) { - case SbxEMPTY: pGen->Gen( _EMPTY ); break; - case SbxINTEGER: pGen->Gen( _CONST, (short) nVal ); break; - case SbxSTRING: - { - sal_uInt16 nStringId = pGen->GetParser()->aGblStrings.Add( aStrVal, sal_True ); - pGen->Gen( _SCONST, nStringId ); break; - } - default: - { - sal_uInt16 nStringId = pGen->GetParser()->aGblStrings.Add( nVal, eType ); - pGen->Gen( _NUMBER, nStringId ); - } + case SbxEMPTY: + pGen->Gen( _EMPTY ); + break; + case SbxINTEGER: + pGen->Gen( _CONST, (short) nVal ); + break; + case SbxSTRING: + nStringId = pGen->GetParser()->aGblStrings.Add( aStrVal, sal_True ); + pGen->Gen( _SCONST, nStringId ); + break; + default: + nStringId = pGen->GetParser()->aGblStrings.Add( nVal, eType ); + pGen->Gen( _NUMBER, nStringId ); + break; } } else if( IsOperand() ) @@ -92,10 +96,14 @@ void SbiExprNode::Gen( RecursiveMode eRecMode ) else if( eRecMode == UNDEFINED ) { if( aVar.pPar && aVar.pPar->IsBracket() ) + { bTreatFunctionAsParam = false; + } } if( !bTreatFunctionAsParam ) + { eOp = aVar.pDef->IsGlobal() ? _FIND_G : _FIND; + } } } // special treatment for WITH @@ -114,7 +122,9 @@ void SbiExprNode::Gen( RecursiveMode eRecMode ) SbiProcDef* pProc = aVar.pDef->GetProcDef(); if ( pGen->GetParser()->bClassModule ) + { eOp = _FIND_CM; + } else if ( aVar.pDef->IsStatic() || (pProc && pProc->IsStatic()) ) { eOp = _FIND_STATIC; @@ -123,7 +133,9 @@ void SbiExprNode::Gen( RecursiveMode eRecMode ) for( SbiExprNode* p = this; p; p = p->aVar.pNext ) { if( p == this && pWithParent_ != NULL ) + { pWithParent_->Gen(); + } p->GenElement( eOp ); eOp = _ELEM; } @@ -141,7 +153,9 @@ void SbiExprNode::Gen( RecursiveMode eRecMode ) { pLeft->Gen(); if( pRight ) + { pRight->Gen(); + } for( OpTable* p = aOpTable; p->eTok != NIL; p++ ) { if( p->eTok == eTok ) @@ -247,12 +261,16 @@ void SbiExpression::Gen( RecursiveMode eRecMode ) // If pExpr == .-term in With, approximately Gen for Basis-Object pExpr->Gen( eRecMode ); if( bByVal ) + { pParser->aGen.Gen( _BYVAL ); + } if( bBased ) { sal_uInt16 uBase = pParser->nBase; if( pParser->IsCompatible() ) + { uBase |= 0x8000; // #109275 Flag compatiblity + } pParser->aGen.Gen( _BASED, uBase ); pParser->aGen.Gen( _ARGV ); } diff --git a/basic/source/comp/exprtree.cxx b/basic/source/comp/exprtree.cxx index 1a4b465ded02..33857568b8bc 100644 --- a/basic/source/comp/exprtree.cxx +++ b/basic/source/comp/exprtree.cxx @@ -39,11 +39,17 @@ SbiExpression::SbiExpression( SbiParser* p, SbiExprType t, pNext = NULL; pExpr = (t != SbSTDEXPR ) ? Term( pKeywordSymbolInfo ) : Boolean(); if( t != SbSYMBOL ) + { pExpr->Optimize(); + } if( t == SbLVALUE && !pExpr->IsLvalue() ) + { p->Error( SbERR_LVALUE_EXPECTED ); + } if( t == SbOPERAND && !IsVariable() ) + { p->Error( SbERR_VAR_EXPECTED ); + } } SbiExpression::SbiExpression( SbiParser* p, double n, SbxDataType t ) @@ -82,12 +88,16 @@ SbiExpression::~SbiExpression() static sal_Bool DoParametersFollow( SbiParser* p, SbiExprType eCurExpr, SbiToken eTok ) { if( eTok == LPAREN ) + { return sal_True; + } // but only if similar to CALL! if( !p->WhiteSpace() || eCurExpr != SbSYMBOL ) + { return sal_False; - if ( eTok == NUMBER || eTok == MINUS || eTok == FIXSTRING - || eTok == SYMBOL || eTok == COMMA || eTok == DOT || eTok == NOT || eTok == BYVAL ) + } + if ( eTok == NUMBER || eTok == MINUS || eTok == FIXSTRING || + eTok == SYMBOL || eTok == COMMA || eTok == DOT || eTok == NOT || eTok == BYVAL ) { return sal_True; } @@ -97,7 +107,9 @@ static sal_Bool DoParametersFollow( SbiParser* p, SbiExprType eCurExpr, SbiToken // Urk the Next() / Peek() symantics are... weird tokens.Next(); if ( tokens.Peek() == ASSIGN ) + { return sal_True; + } } return sal_False; } @@ -118,13 +130,16 @@ static SbiSymDef* AddSym // procs must always get into a public pool SbiSymPool* pPool = &rPool; if( pPool->GetScope() != SbPUBLIC ) + { pPool = &rPool.GetParser()->aPublics; + } SbiProcDef* pProc = pPool->AddProc( rName ); // special treatment for Colls like Documents(1) if( eCurExpr == SbSTDEXPR ) + { bHasType = sal_True; - + } pDef = pProc; pDef->SetType( bHasType ? eType : SbxEMPTY ); if( pPar ) @@ -166,7 +181,9 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo ) { pNd = ObjTerm( *pDef ); if( pNd ) + { pNd->SetWithParent( pWithVar ); + } } if( !pNd ) { @@ -220,7 +237,9 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo ) while( eTok == LPAREN ) { if( pvMoreParLcl == NULL ) + { pvMoreParLcl = new SbiExprListVector(); + } SbiParameters* pAddPar = new SbiParameters( pParser ); pvMoreParLcl->push_back( pAddPar ); bError = bError || !pAddPar->IsValid(); @@ -236,7 +255,9 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo ) { bBracket = false; // Now the bracket for the first term is obsolete if( eType == SbxVARIANT ) + { eType = SbxOBJECT; + } else { // Name%. really does not work! @@ -257,18 +278,24 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo ) SbModule& rMod = pParser->aGen.GetModule(); SbxArray* pModMethods = rMod.GetMethods(); if( pModMethods->Find( aSym, SbxCLASS_DONTCARE ) ) + { pDef = NULL; + } } if( !pDef ) { if( bObj ) + { eType = SbxOBJECT; + } pDef = AddSym( eTok, *pParser->pPool, eCurExpr, aSym, eType, pPar ); // Looks like this is a local ( but undefined variable ) // if it is in a static procedure then make this Symbol // static if ( !bObj && pParser->pProc && pParser->pProc->IsStatic() ) + { pDef->SetStatic(); + } } else { @@ -277,16 +304,22 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo ) if( pConst ) { if( pConst->GetType() == SbxSTRING ) + { return new SbiExprNode( pParser, pConst->GetString() ); + } else + { return new SbiExprNode( pParser, pConst->GetValue(), pConst->GetType() ); + } } // 0 parameters come up to () if( pDef->GetDims() ) { if( pPar && pPar->GetSize() && pPar->GetSize() != pDef->GetDims() ) + { pParser->Error( SbERR_WRONG_DIMS ); + } } if( pDef->IsDefinedAs() ) { @@ -347,7 +380,9 @@ SbiExprNode* SbiExpression::Term( const KeywordSymbolInfo* pKeywordSymbolInfo ) } } if( !bError ) + { pNd->aVar.pNext = ObjTerm( *pDef ); + } } pParser->UnlockColumn(); @@ -393,19 +428,22 @@ SbiExprNode* SbiExpression::ObjTerm( SbiSymDef& rObj ) while( eTok == LPAREN ) { if( pvMoreParLcl == NULL ) + { pvMoreParLcl = new SbiExprListVector(); + } SbiParameters* pAddPar = new SbiParameters( pParser ); pvMoreParLcl->push_back( pAddPar ); bError = bError || !pPar->IsValid(); eTok = pParser->Peek(); } - } sal_Bool bObj = sal_Bool( ( eTok == DOT || eTok == EXCLAM ) && !pParser->WhiteSpace() ); if( bObj ) { if( eType == SbxVARIANT ) + { eType = SbxOBJECT; + } else { // Name%. does really not work! @@ -430,8 +468,9 @@ SbiExprNode* SbiExpression::ObjTerm( SbiSymDef& rObj ) if( bObj ) { if( pDef->GetType() == SbxVARIANT ) + { pDef->SetType( SbxOBJECT ); - + } if( pDef->GetType() != SbxOBJECT ) { pParser->Error( SbERR_BAD_DECLARATION, aSym ); @@ -462,67 +501,78 @@ SbiExprNode* SbiExpression::Operand( bool bUsedForTypeOf ) // test operand: switch( eTok = pParser->Peek() ) { - case SYMBOL: - pRes = Term(); - // process something like "IF Not r Is Nothing Then .." - if( !bUsedForTypeOf && pParser->IsVBASupportOn() && pParser->Peek() == IS ) - { - eTok = pParser->Next(); - pRes = new SbiExprNode( pParser, pRes, eTok, Like() ); - } - break; - case DOT: // .with - pRes = Term(); break; - case NUMBER: + case SYMBOL: + pRes = Term(); + // process something like "IF Not r Is Nothing Then .." + if( !bUsedForTypeOf && pParser->IsVBASupportOn() && pParser->Peek() == IS ) + { + eTok = pParser->Next(); + pRes = new SbiExprNode( pParser, pRes, eTok, Like() ); + } + break; + case DOT: // .with + pRes = Term(); break; + case NUMBER: + pParser->Next(); + pRes = new SbiExprNode( pParser, pParser->GetDbl(), pParser->GetType() ); + break; + case FIXSTRING: + pParser->Next(); + pRes = new SbiExprNode( pParser, pParser->GetSym() ); break; + case LPAREN: + pParser->Next(); + if( nParenLevel == 0 && m_eMode == EXPRMODE_LPAREN_PENDING && pParser->Peek() == RPAREN ) + { + m_eMode = EXPRMODE_EMPTY_PAREN; + pRes = new SbiExprNode(); // Dummy node pParser->Next(); - pRes = new SbiExprNode( pParser, pParser->GetDbl(), pParser->GetType() ); break; - case FIXSTRING: - pParser->Next(); - pRes = new SbiExprNode( pParser, pParser->GetSym() ); break; - case LPAREN: - pParser->Next(); - if( nParenLevel == 0 && m_eMode == EXPRMODE_LPAREN_PENDING && pParser->Peek() == RPAREN ) + } + nParenLevel++; + pRes = Boolean(); + if( pParser->Peek() != RPAREN ) + { + // If there was a LPARAM, it does not belong to the expression + if( nParenLevel == 1 && m_eMode == EXPRMODE_LPAREN_PENDING ) { - m_eMode = EXPRMODE_EMPTY_PAREN; - pRes = new SbiExprNode(); // Dummy node - pParser->Next(); - break; + m_eMode = EXPRMODE_LPAREN_NOT_NEEDED; } - nParenLevel++; - pRes = Boolean(); - if( pParser->Peek() != RPAREN ) + else { - // If there was a LPARAM, it does not belong to the expression - if( nParenLevel == 1 && m_eMode == EXPRMODE_LPAREN_PENDING ) - m_eMode = EXPRMODE_LPAREN_NOT_NEEDED; - else - pParser->Error( SbERR_BAD_BRACKETS ); + pParser->Error( SbERR_BAD_BRACKETS ); } - else + } + else + { + pParser->Next(); + if( nParenLevel == 1 && m_eMode == EXPRMODE_LPAREN_PENDING ) { - pParser->Next(); - if( nParenLevel == 1 && m_eMode == EXPRMODE_LPAREN_PENDING ) + SbiToken eTokAfterRParen = pParser->Peek(); + if( eTokAfterRParen == EQ || eTokAfterRParen == LPAREN || eTokAfterRParen == DOT ) { - SbiToken eTokAfterRParen = pParser->Peek(); - if( eTokAfterRParen == EQ || eTokAfterRParen == LPAREN || eTokAfterRParen == DOT ) - m_eMode = EXPRMODE_ARRAY_OR_OBJECT; - else - m_eMode = EXPRMODE_STANDARD; + m_eMode = EXPRMODE_ARRAY_OR_OBJECT; + } + else + { + m_eMode = EXPRMODE_STANDARD; } } - nParenLevel--; - break; - default: - // keywords here are OK at the moment! - if( pParser->IsKwd( eTok ) ) - pRes = Term(); - else - { - pParser->Next(); - pRes = new SbiExprNode( pParser, 1.0, SbxDOUBLE ); - pParser->Error( SbERR_UNEXPECTED, eTok ); - } + } + nParenLevel--; + break; + default: + // keywords here are OK at the moment! + if( pParser->IsKwd( eTok ) ) + { + pRes = Term(); + } + else + { + pParser->Next(); + pRes = new SbiExprNode( pParser, 1.0, SbxDOUBLE ); + pParser->Error( SbERR_UNEXPECTED, eTok ); + } + break; } return pRes; } @@ -585,7 +635,8 @@ SbiExprNode* SbiExpression::Exp() SbiExprNode* pNd = Unary(); if( m_eMode != EXPRMODE_EMPTY_PAREN ) { - while( pParser->Peek() == EXPON ) { + while( pParser->Peek() == EXPON ) + { SbiToken eTok = pParser->Next(); pNd = new SbiExprNode( pParser, pNd, eTok, Unary() ); } @@ -602,7 +653,9 @@ SbiExprNode* SbiExpression::MulDiv() { SbiToken eTok = pParser->Peek(); if( eTok != MUL && eTok != DIV ) + { break; + } eTok = pParser->Next(); pNd = new SbiExprNode( pParser, pNd, eTok, Exp() ); } @@ -615,7 +668,8 @@ SbiExprNode* SbiExpression::IntDiv() SbiExprNode* pNd = MulDiv(); if( m_eMode != EXPRMODE_EMPTY_PAREN ) { - while( pParser->Peek() == IDIV ) { + while( pParser->Peek() == IDIV ) + { SbiToken eTok = pParser->Next(); pNd = new SbiExprNode( pParser, pNd, eTok, MulDiv() ); } @@ -628,7 +682,8 @@ SbiExprNode* SbiExpression::Mod() SbiExprNode* pNd = IntDiv(); if( m_eMode != EXPRMODE_EMPTY_PAREN ) { - while( pParser->Peek() == MOD ) { + while( pParser->Peek() == MOD ) + { SbiToken eTok = pParser->Next(); pNd = new SbiExprNode( pParser, pNd, eTok, IntDiv() ); } @@ -645,7 +700,9 @@ SbiExprNode* SbiExpression::AddSub() { SbiToken eTok = pParser->Peek(); if( eTok != PLUS && eTok != MINUS ) + { break; + } eTok = pParser->Next(); pNd = new SbiExprNode( pParser, pNd, eTok, Mod() ); } @@ -662,7 +719,9 @@ SbiExprNode* SbiExpression::Cat() { SbiToken eTok = pParser->Peek(); if( eTok != CAT ) + { break; + } eTok = pParser->Next(); pNd = new SbiExprNode( pParser, pNd, eTok, AddSub() ); } @@ -820,10 +879,13 @@ short SbiConstExpression::GetShortValue() { double n = nVal; if( n > 0 ) + { n += .5; + } else + { n -= .5; - + } if( n > SbxMAXINT ) { n = SbxMAXINT; @@ -872,7 +934,9 @@ SbiExpression* SbiExprList::Get( short n ) { SbiExpression* p = pFirst; while( n-- && p ) + { p = p->pNext; + } return p; } @@ -886,8 +950,9 @@ void SbiExprList::addExpression( SbiExpression* pExpr ) SbiExpression* p = pFirst; while( p->pNext ) + { p = p->pNext; - + } p->pNext = pExpr; } @@ -911,8 +976,9 @@ SbiParameters::SbiParameters( SbiParser* p, bool bStandaloneExpression, bool bPa SbiExprList( p ) { if( !bPar ) + { return; - + } SbiExpression *pExpr; SbiToken eTok = pParser->Peek(); @@ -985,16 +1051,20 @@ SbiParameters::SbiParameters( SbiParser* p, bool bStandaloneExpression, bool bPa bBracket = true; delete pExpr; if( bByVal ) + { pParser->Error( SbERR_LVALUE_EXPECTED ); + } return; } } else + { pExpr = new SbiExpression( pParser ); - + } if( bByVal && pExpr->IsLvalue() ) + { pExpr->SetByVal(); - + } if( !bAssumeArrayMode ) { if( pParser->Peek() == ASSIGN ) @@ -1011,24 +1081,29 @@ SbiParameters::SbiParameters( SbiParser* p, bool bStandaloneExpression, bool bPa } pExpr->pNext = NULL; if( !pLast ) + { pFirst = pLast = pExpr; + } else + { pLast->pNext = pExpr, pLast = pExpr; + } nExpr++; bError = bError || !pExpr->IsValid(); if( bAssumeArrayMode ) + { break; - + } // next element? eTok = pParser->Peek(); if( eTok != COMMA ) { if( ( bBracket && eTok == RPAREN ) || pParser->IsEoln( eTok ) ) + { break; - pParser->Error( bBracket - ? SbERR_BAD_BRACKETS - : SbERR_EXPECTED, COMMA ); + } + pParser->Error( bBracket ? SbERR_BAD_BRACKETS : SbERR_EXPECTED, COMMA ); bError = true; } else @@ -1036,7 +1111,9 @@ SbiParameters::SbiParameters( SbiParser* p, bool bStandaloneExpression, bool bPa pParser->Next(); eTok = pParser->Peek(); if( ( bBracket && eTok == RPAREN ) || pParser->IsEoln( eTok ) ) + { break; + } } } // closing bracket @@ -1089,9 +1166,13 @@ SbiDimList::SbiDimList( SbiParser* p ) : SbiExprList( p ) bError = bError || !pExpr1->IsValid() || !pExpr2->IsValid(); pExpr1->pNext = pExpr2; if( !pLast ) + { pFirst = pExpr1; + } else + { pLast->pNext = pExpr1; + } pLast = pExpr2; nExpr += 2; } @@ -1102,9 +1183,13 @@ SbiDimList::SbiDimList( SbiParser* p ) : SbiExprList( p ) bConst = bConst && pExpr1->IsIntConstant(); bError = bError || !pExpr1->IsValid(); if( !pLast ) + { pFirst = pLast = pExpr1; + } else + { pLast->pNext = pExpr1, pLast = pExpr1; + } nExpr++; } nDim++; diff --git a/basic/source/comp/loops.cxx b/basic/source/comp/loops.cxx index b2e7eb7736c4..51953e068ca9 100644 --- a/basic/source/comp/loops.cxx +++ b/basic/source/comp/loops.cxx @@ -460,11 +460,19 @@ void SbiParser::On() SbiToken eTok = Peek(); String aString = SbiTokenizer::Symbol(eTok); if (aString.EqualsIgnoreCaseAscii("ERROR")) + { eTok = _ERROR_; // Error comes as SYMBOL - if( eTok != _ERROR_ && eTok != LOCAL ) OnGoto(); + } + if( eTok != _ERROR_ && eTok != LOCAL ) + { + OnGoto(); + } else { - if( eTok == LOCAL ) Next(); + if( eTok == LOCAL ) + { + Next(); + } Next (); // no more TestToken, as there'd be an error otherwise Next(); // get token after error @@ -476,7 +484,9 @@ void SbiParser::On() if( MayBeLabel() ) { if( eCurTok == NUMBER && !nVal ) + { aGen.Gen( _STDERROR ); + } else { sal_uInt32 nOff = pProc->GetLabels().Reference( aSym ); @@ -487,12 +497,18 @@ void SbiParser::On() { Next(); if( eCurTok == NUMBER && nVal == 1 ) + { aGen.Gen( _STDERROR ); + } else + { bError_ = true; + } } if( bError_ ) + { Error( SbERR_LABEL_EXPECTED ); + } } else if( eCurTok == RESUME ) { diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx index c1f175206a23..587b478fcf9e 100644 --- a/basic/source/comp/parser.cxx +++ b/basic/source/comp/parser.cxx @@ -628,11 +628,15 @@ void SbiParser::LSet() { SbiExpression aLvalue( this, SbLVALUE ); if( aLvalue.GetType() != SbxSTRING ) + { Error( SbERR_INVALID_OBJECT ); + } TestToken( EQ ); SbiSymDef* pDef = aLvalue.GetRealVar(); if( pDef && pDef->GetConstDef() ) + { Error( SbERR_DUPLICATE_DEF, pDef->GetName() ); + } SbiExpression aExpr( this ); aLvalue.Gen(); aExpr.Gen(); @@ -644,7 +648,9 @@ void SbiParser::RSet() { SbiExpression aLvalue( this, SbLVALUE ); if( aLvalue.GetType() != SbxSTRING ) + { Error( SbERR_INVALID_OBJECT ); + } TestToken( EQ ); SbiSymDef* pDef = aLvalue.GetRealVar(); if( pDef && pDef->GetConstDef() ) @@ -772,11 +778,17 @@ void SbiParser::Option() { SbiToken eTok = Next(); if( eTok == BINARY ) + { bText = false; + } else if( eTok == SYMBOL && GetSym().equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("text")) ) + { bText = true; + } else + { Error( SbERR_EXPECTED, "Text/Binary" ); + } break; } case COMPATIBLE: @@ -794,11 +806,15 @@ void SbiParser::Option() { bVBASupportOn = ( nVal == 1 ); if ( bVBASupportOn ) + { EnableCompatibility(); + } // if the module setting is different // reset it to what the Option tells us if ( bVBASupportOn != aGen.GetModule().IsVBACompat() ) + { aGen.GetModule().SetVBACompat( bVBASupportOn ); + } break; } } diff --git a/basic/source/comp/sbcomp.cxx b/basic/source/comp/sbcomp.cxx index b3ee0a18f5ec..a9288d3d1d2a 100644 --- a/basic/source/comp/sbcomp.cxx +++ b/basic/source/comp/sbcomp.cxx @@ -284,8 +284,9 @@ String lcl_dumpMethodParameters( SbMethod* pMethod ) { String aStr; if( pMethod == NULL ) + { return aStr; - + } SbxError eOld = SbxBase::GetError(); SbxArray* pParams = pMethod->GetParameters(); @@ -299,12 +300,16 @@ String lcl_dumpMethodParameters( SbMethod* pMethod ) SbxVariable* pVar = pParams->Get( nParam ); DBG_ASSERT( pVar, "Parameter?!" ); if ( pVar->GetName().Len() ) + { aStr += pVar->GetName(); + } else if ( pInfo ) { const SbxParamInfo* pParam = pInfo->GetParam( nParam ); if ( pParam ) + { aStr += pParam->aName; + } } aStr += '='; SbxDataType eType = pVar->GetType(); @@ -320,8 +325,9 @@ String lcl_dumpMethodParameters( SbMethod* pMethod ) SbxBase::ResetError(); if( eOld != SbxERR_OK ) + { SbxBase::SetError( eOld ); - + } return aStr; } @@ -386,7 +392,9 @@ void lcl_printTimeOutput( void ) { FunctionItem* pFunctionItem = it->second; if( pFunctionItem != NULL ) + { avFunctionItems.push_back( pFunctionItem ); + } } std::sort( avFunctionItems.begin(), avFunctionItems.end(), compareFunctionNetTime ); @@ -407,10 +415,12 @@ void lcl_printTimeOutput( void ) double dFctNetTimePercent = 100.0 * dFctNetTime / dTotalTime; int nSpaceCount = 30 - nNameLen; if( nSpaceCount < 0 ) + { nSpaceCount = 2; + } sprintf( TimeBuffer, "%s:%sCalled %d times\t%f ms (%f%%) / net %f (%f%%) ms", - pName, lcl_getSpaces( nSpaceCount ), pFunctionItem->m_nCallCount, - dFctTotalTime*1000.0, dFctTotalTimePercent, dFctNetTime*1000.0, dFctNetTimePercent ); + pName, lcl_getSpaces( nSpaceCount ), pFunctionItem->m_nCallCount, + dFctTotalTime*1000.0, dFctTotalTimePercent, dFctNetTime*1000.0, dFctNetTimePercent ); lcl_lineOut( TimeBuffer ); } } @@ -427,7 +437,9 @@ void dbg_InitTrace( void ) { #ifdef DBG_TRACE_PROFILING if( GbTimerOn ) + { GpTimer->continueTimer(); + } #endif GpGlobalFile = fopen( GpTraceFileName, "a+" ); return; @@ -435,15 +447,19 @@ void dbg_InitTrace( void ) GbInitTraceAlreadyCalled = true; if( const sal_Char* pcIniFileName = ::getenv( "OOO_BASICTRACEINI" ) ) + { lcl_ReadIniFile( pcIniFileName ); + } else if( GpTraceIniFile != NULL ) + { lcl_ReadIniFile( GpTraceIniFile ); - + } GpGlobalFile = fopen( GpTraceFileName, "w" ); GbSavTraceOn = GbTraceOn; if( !GbTraceOn ) + { lcl_lineOut( "### Program started with trace off ###" ); - + } #ifdef DBG_TRACE_PROFILING GpTimer = new canvas::tools::ElapsedTime(); GdStartTime = GpTimer->getElapsedTime(); @@ -459,14 +475,19 @@ void dbg_DeInitTrace( void ) #ifdef DBG_TRACE_PROFILING while( !GaCallEnterTimeStack.empty() ) + { GaCallEnterTimeStack.pop(); + } while( !GaFunctionItemStack.empty() ) + { GaFunctionItemStack.pop(); - + } lcl_printTimeOutput(); for( FunctionItemMap::iterator it = GaFunctionItemMap.begin() ; it != GaFunctionItemMap.end() ; ++it ) + { delete it->second; + } GaFunctionItemMap.clear(); if( GpGlobalFile ) @@ -478,7 +499,9 @@ void dbg_DeInitTrace( void ) if( GbInitOnlyAtOfficeStart ) { if( GbTimerOn ) + { GpTimer->pauseTimer(); + } } else { @@ -492,8 +515,9 @@ static sal_Int32 GnLastCallLvl = 0; void dbg_tracePrint( const String& aStr, sal_Int32 nCallLvl, bool bCallLvlRelativeToCurrent ) { if( bCallLvlRelativeToCurrent ) + { nCallLvl += GnLastCallLvl; - + } int nIndent = nCallLvl * GnIndentPerCallLevel; lcl_lineOut( OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr(), lcl_getSpaces( nIndent ) ); } @@ -501,12 +525,14 @@ void dbg_tracePrint( const String& aStr, sal_Int32 nCallLvl, bool bCallLvlRelati void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) { if( !GbTraceOn ) + { return; - + } #ifdef DBG_TRACE_PROFILING if( GbBlockSteps || GbBlockAll ) + { return; - + } double dCurTime = 0.0; bool bPrintTimeStamp = false; if( GbTimerOn ) @@ -562,8 +588,9 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) const rtl::OString& rStr_STMNT = rTraceTextData.m_aTraceStr_STMNT; bool bSTMT = false; if( rStr_STMNT.getLength() ) + { bSTMT = true; - + } char TimeBuffer[200]; #ifdef DBG_TRACE_PROFILING if( bPrintTimeStamp ) @@ -577,14 +604,16 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) if( bSTMT ) { lcl_lineOut( rStr_STMNT.getStr(), lcl_getSpaces( nIndent ), - (bPrintTimeStamp && !GbIncludePCodes) ? TimeBuffer : NULL ); + (bPrintTimeStamp && !GbIncludePCodes) ? TimeBuffer : NULL ); } if( !GbIncludePCodes ) { #ifdef DBG_TRACE_PROFILING if( GbTimerOn ) + { GpTimer->continueTimer(); + } #endif return; } @@ -594,12 +623,14 @@ void dbg_traceStep( SbModule* pModule, sal_uInt32 nPC, sal_Int32 nCallLvl ) if( rStr_PCode.getLength() ) { lcl_lineOut( rStr_PCode.getStr(), lcl_getSpaces( nIndent ), - bPrintTimeStamp ? TimeBuffer : NULL ); + bPrintTimeStamp ? TimeBuffer : NULL ); } #ifdef DBG_TRACE_PROFILING if( GbTimerOn ) + { GpTimer->continueTimer(); + } #endif } @@ -609,8 +640,9 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL static const char* pSeparator = "' ================================================================================"; if( !GbTraceOn ) + { return; - + } #ifdef DBG_TRACE_PROFILING double dCurTime = 0.0; double dExecutionTime = 0.0; @@ -651,8 +683,9 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL { FunctionItemMap::iterator itFunctionItem = GaFunctionItemMap.find( aCompleteFunctionName ); if( itFunctionItem != GaFunctionItemMap.end() ) + { pFunctionItem = itFunctionItem->second; - + } if( pFunctionItem == NULL ) { DBG_ASSERT( !bLeave, "No FunctionItem in leave!" ); @@ -710,13 +743,17 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL if( bOwnBlockAll ) { if( GbTimerOn ) + { GpTimer->continueTimer(); + } return; } #endif if( nCallLvl > 0 ) + { nCallLvl--; + } int nIndent = nCallLvl * GnIndentPerCallLevel; if( !bLeave && !bOwnBlockSteps ) { @@ -747,8 +784,9 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL aStr.AppendAscii( "]" ); } if( !bLeave ) + { aStr += lcl_dumpMethodParameters( pMethod ); - + } const char* pPostStr = NULL; #ifdef DBG_TRACE_PROFILING char TimeBuffer[200]; @@ -759,26 +797,34 @@ void dbg_traceNotifyCall( SbModule* pModule, SbMethod* pMethod, sal_Int32 nCallL } #endif lcl_lineOut( (!bLeave || !bOwnBlockSteps) ? OUStringToOString( rtl::OUString( aStr ), RTL_TEXTENCODING_ASCII_US ).getStr() : "}", - lcl_getSpaces( nIndent ), pPostStr ); + lcl_getSpaces( nIndent ), pPostStr ); if( !bLeave ) + { lcl_lineOut( "{", lcl_getSpaces( nIndent ) ); - + } if( bLeave && !bOwnBlockSteps ) + { lcl_lineOut( "" ); - + } #ifdef DBG_TRACE_PROFILING if( GbTimerOn ) + { GpTimer->continueTimer(); + } #endif } void dbg_traceNotifyError( SbError nTraceErr, const String& aTraceErrMsg, bool bTraceErrHandled, sal_Int32 nCallLvl ) { if( !GbTraceOn ) + { return; + } #ifdef DBG_TRACE_PROFILING if( GbBlockSteps || GbBlockAll ) + { return; + } #endif GnLastCallLvl = nCallLvl; @@ -871,7 +917,9 @@ void RTL_Impl_TraceCommand( StarBASIC* pBasic, SbxArray& rPar, sal_Bool bWrite ) lcl_lineOut( Buffer, lcl_getSpaces( nIndent ) ); if( eOld != SbxERR_OK ) + { SbxBase::SetError( eOld ); + } } } diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx index 395f19aa24ca..4c550497a423 100644 --- a/basic/source/comp/symtbl.cxx +++ b/basic/source/comp/symtbl.cxx @@ -168,7 +168,9 @@ void SbiSymPool::Add( SbiSymDef* pDef ) } if( !pDef->GetProcDef() ) + { pDef->nProcId = nProcId; + } pDef->pIn = this; aData.insert( aData.begin() + pDef->nPos, pDef ); } @@ -186,9 +188,13 @@ SbiSymDef* SbiSymPool::Find( const String& rName ) const return p; } if( pParent ) + { return pParent->Find( rName ); + } else + { return NULL; + } } @@ -198,12 +204,18 @@ SbiSymDef* SbiSymPool::FindId( sal_uInt16 n ) const { SbiSymDef* p = aData[ i ]; if( p->nId == n && ( !p->nProcId || ( p->nProcId == nProcId ) ) ) + { return p; + } } if( pParent ) + { return pParent->FindId( n ); + } else + { return NULL; + } } // find via position (from 0) @@ -211,20 +223,29 @@ SbiSymDef* SbiSymPool::FindId( sal_uInt16 n ) const SbiSymDef* SbiSymPool::Get( sal_uInt16 n ) const { if( n >= aData.size() ) + { return NULL; + } else + { return aData[ n ]; + } } sal_uInt32 SbiSymPool::Define( const String& rName ) { SbiSymDef* p = Find( rName ); if( p ) - { if( p->IsDefined() ) + { + if( p->IsDefined() ) + { pParser->Error( SbERR_LABEL_DEFINED, rName ); + } } else + { p = AddSym( rName ); + } return p->Define(); } @@ -232,7 +253,9 @@ sal_uInt32 SbiSymPool::Reference( const String& rName ) { SbiSymDef* p = Find( rName ); if( !p ) + { p = AddSym( rName ); + } // to be sure pParser->aGen.GenStmnt(); return p->Reference(); @@ -245,7 +268,9 @@ void SbiSymPool::CheckRefs() { SbiSymDef* p = aData[ i ]; if( !p->IsDefined() ) + { pParser->Error( SbERR_UNDEF_LABEL, p->GetName() ); + } } } @@ -300,7 +325,9 @@ SbiConstDef* SbiSymDef::GetConstDef() const String& SbiSymDef::GetName() { if( pIn ) + { aName = pIn->rStrings.Find( nId ); + } return aName; } @@ -354,7 +381,9 @@ sal_uInt32 SbiSymDef::Define() SbiSymPool& SbiSymDef::GetPool() { if( !pPool ) + { pPool = new SbiSymPool( pIn->pParser->aGblStrings, SbLOCAL ); // is dumped + } return *pPool; } @@ -422,7 +451,9 @@ void SbiProcDef::Match( SbiProcDef* pOld ) // no type matching - that is done during running // but is it maybe called with too little parameters? if( !po && !pn->IsOptional() && !pn->IsParamArray() ) + { break; + } po = pOld->aParams.Next(); } @@ -498,7 +529,9 @@ SbiConstDef* SbiConstDef::GetConstDef() SbiSymbols::~SbiSymbols() { for( const_iterator it = begin(); it != end(); ++it ) + { delete *it; + } }; diff --git a/basic/source/comp/token.cxx b/basic/source/comp/token.cxx index 0de57e6356b0..7ebcb17eeb43 100644 --- a/basic/source/comp/token.cxx +++ b/basic/source/comp/token.cxx @@ -28,7 +28,6 @@ static short nToken; // number of tokens static TokenTable* pTokTable; static TokenTable aTokTable_Basic [] = { - { CAT, "&" }, { MUL, "*" }, { PLUS, "+" }, @@ -188,16 +187,19 @@ TokenLabelInfo::TokenLabelInfo( void ) { m_pTokenCanBeLabelTab = new bool[VBASUPPORT+1]; for( int i = 0 ; i <= VBASUPPORT ; ++i ) + { m_pTokenCanBeLabelTab[i] = false; - + } // Token accepted as label by VBA SbiToken eLabelToken[] = { ACCESS, ALIAS, APPEND, BASE, BINARY, CLASSMODULE, - COMPARE, COMPATIBLE, DEFERR, _ERROR_, EXPLICIT, LIB, LINE, LPRINT, NAME, - TOBJECT, OUTPUT, PROPERTY, RANDOM, READ, STEP, STOP, TEXT, VBASUPPORT, NIL }; + COMPARE, COMPATIBLE, DEFERR, _ERROR_, EXPLICIT, LIB, LINE, LPRINT, NAME, + TOBJECT, OUTPUT, PROPERTY, RANDOM, READ, STEP, STOP, TEXT, VBASUPPORT, NIL }; SbiToken* pTok = eLabelToken; SbiToken eTok; for( pTok = eLabelToken ; (eTok = *pTok) != NIL ; ++pTok ) + { m_pTokenCanBeLabelTab[eTok] = true; + } } TokenLabelInfo::~TokenLabelInfo() @@ -218,7 +220,10 @@ SbiTokenizer::SbiTokenizer( const ::rtl::OUString& rSrc, StarBASIC* pb ) ePush = NIL; bEos = bKeywords = bErrorIsSymbol = true; if( !nToken ) - for( nToken = 0, tp = pTokTable; tp->t; nToken++, tp++ ) {} + { + for( nToken = 0, tp = pTokTable; tp->t; nToken++, tp++ ) + {} + } } SbiTokenizer::~SbiTokenizer() @@ -280,16 +285,17 @@ const ::rtl::OUString& SbiTokenizer::Symbol( SbiToken t ) } switch( t ) { - case NEG : - aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-")); - return aSym; - case EOS : - aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":/CRLF")); - return aSym; - case EOLN : - aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CRLF")); - return aSym; - default: break; + case NEG : + aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-")); + return aSym; + case EOS : + aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(":/CRLF")); + return aSym; + case EOLN : + aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CRLF")); + return aSym; + default: + break; } TokenTable* tp = pTokTable; for( short i = 0; i < nToken; i++, tp++ ) @@ -302,7 +308,9 @@ const ::rtl::OUString& SbiTokenizer::Symbol( SbiToken t ) } const sal_Unicode *p = aSym.getStr(); if (*p <= ' ') + { aSym = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("???")); + } return aSym; } @@ -313,7 +321,10 @@ const ::rtl::OUString& SbiTokenizer::Symbol( SbiToken t ) SbiToken SbiTokenizer::Next() { - if (bEof) return EOLN; + if (bEof) + { + return EOLN; + } // have read in one already? if( ePush != NIL ) { @@ -340,16 +351,23 @@ SbiToken SbiTokenizer::Next() bEos = false; if( bNumber ) + { return eCurTok = NUMBER; - + } else if( ( eScanType == SbxDATE || eScanType == SbxSTRING ) && !bSymbol ) + { return eCurTok = FIXSTRING; + } // Special cases of characters that are between "Z" and "a". ICompare() // evaluates the position of these characters in different ways. else if( aSym[0] == '^' ) + { return eCurTok = EXPON; + } else if( aSym[0] == '\\' ) + { return eCurTok = IDIV; + } else { if( eScanType != SbxVARIANT @@ -366,32 +384,52 @@ SbiToken SbiTokenizer::Next() sal_Int32 res = aSym.compareToIgnoreAsciiCaseAscii( tp->s ); if( res == 0 ) + { goto special; - + } if( res < 0 ) { - if ((ub - lb) == 2) ub = lb; - else ub = ub - delta; + if ((ub - lb) == 2) + { + ub = lb; + } + else + { + ub = ub - delta; + } } else { - if ((ub -lb) == 2) lb = ub; - else lb = lb + delta; + if ((ub -lb) == 2) + { + lb = ub; + } + else + { + lb = lb + delta; + } } - } while( delta ); + } + while( delta ); // Symbol? if not >= token sal_Unicode ch = aSym[0]; if( !theBasicCharClass::get().isAlpha( ch, bCompatible ) && !bSymbol ) + { return eCurTok = (SbiToken) (ch & 0x00FF); + } return eCurTok = SYMBOL; } special: // #i92642 bool bStartOfLine = (eCurTok == NIL || eCurTok == REM || eCurTok == EOLN); if( !bStartOfLine && (tp->t == NAME || tp->t == LINE) ) + { return eCurTok = SYMBOL; + } else if( tp->t == TEXT ) + { return eCurTok = SYMBOL; + } // maybe we can expand this for other statements that have parameters // that are keywords ( and those keywords are only used within such // statements ) @@ -400,8 +438,9 @@ special: // we just treat keyword 'append' as a normal 'SYMBOL'. // Also we accept Dim APPEND else if ( ( !bInStatement || eCurTok == DIM ) && tp->t == APPEND ) + { return eCurTok = SYMBOL; - + } // #i92642: Special LINE token handling -> SbiParser::Line() // END IF, CASE, SUB, DEF, FUNCTION, TYPE, CLASS, WITH @@ -419,15 +458,15 @@ special: 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; + 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; } nCol1 = nOldCol1; if( eCurTok == END ) @@ -447,13 +486,19 @@ special: eCurTok = tp->t; // AS: data types are keywords if( tp->t == AS ) + { bAs = true; + } else { if( bAs ) + { bAs = false; + } else if( eCurTok >= DATATYPE1 && eCurTok <= DATATYPE2 && (bErrorIsSymbol || eCurTok != _ERROR_) ) + { eCurTok = SYMBOL; + } } // CLASSMODULE, PROPERTY, GET, ENUM token only visible in compatible mode @@ -462,10 +507,13 @@ special: { // #129904 Suppress system if( eTok == STOP && aSym.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("system")) ) + { eCurTok = SYMBOL; - + } if( eTok == GET && bStartOfLine ) + { eCurTok = SYMBOL; + } } else { @@ -493,11 +541,15 @@ special: bool SbiTokenizer::MayBeLabel( bool bNeedsColon ) { if( eCurTok == SYMBOL || m_aTokenLabelInfo.canTokenBeLabel( eCurTok ) ) + { return bNeedsColon ? DoesColonFollow() : true; + } else + { return ( eCurTok == NUMBER && eScanType == SbxINTEGER && nVal >= 0 ); + } } #ifdef _MSC_VER |