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 31*cdf0e10cSrcweir #include "sbcomp.hxx" 32*cdf0e10cSrcweir #include <stdio.h> 33*cdf0e10cSrcweir #include <string.h> 34*cdf0e10cSrcweir #include <ctype.h> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir SV_IMPL_PTRARR(SbiStrings,String*) 37*cdf0e10cSrcweir SV_IMPL_PTRARR(SbiSymbols,SbiSymDef*) 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // Alle Symbolnamen werden im Stringpool des Symbol-Pools abgelegt, damit 40*cdf0e10cSrcweir // alle Symbole im gleichen Case verarbeitet werden. Beim Speichern des 41*cdf0e10cSrcweir // Code-Images wird der globale Stringpool mit den entsprechenden Sympools 42*cdf0e10cSrcweir // gespeichert. Der lokale Stringpool nimmt alle Symbole auf, die nicht 43*cdf0e10cSrcweir // ins Image wandern (Labels, Konstantennamen etc). 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir /*************************************************************************** 46*cdf0e10cSrcweir |* 47*cdf0e10cSrcweir |* SbiStringPool 48*cdf0e10cSrcweir |* 49*cdf0e10cSrcweir ***************************************************************************/ 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir SbiStringPool::SbiStringPool( SbiParser* p ) 52*cdf0e10cSrcweir { 53*cdf0e10cSrcweir pParser = p; 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir SbiStringPool::~SbiStringPool() 57*cdf0e10cSrcweir {} 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir // Suchen 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir const String& SbiStringPool::Find( sal_uInt16 n ) const 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir if( !n || n > aData.Count() ) 64*cdf0e10cSrcweir return aEmpty; 65*cdf0e10cSrcweir else 66*cdf0e10cSrcweir return *aData.GetObject( n-1 ); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // Hinzufuegen eines Strings. Der String wird Case-Insensitiv 70*cdf0e10cSrcweir // verglichen. 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir short SbiStringPool::Add( const String& rVal, sal_Bool bNoCase ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir sal_uInt16 n = aData.Count(); 75*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < n; i++ ) 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir String* p = aData.GetObject( i ); 78*cdf0e10cSrcweir if( ( bNoCase && p->Equals( rVal ) ) 79*cdf0e10cSrcweir || ( !bNoCase && p->EqualsIgnoreCaseAscii( rVal ) ) ) 80*cdf0e10cSrcweir return i+1; 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir const String* pNew = new String( rVal ); 83*cdf0e10cSrcweir aData.Insert( pNew, n++ ); 84*cdf0e10cSrcweir return (short) n; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir short SbiStringPool::Add( double n, SbxDataType t ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir char buf[ 40 ]; 90*cdf0e10cSrcweir switch( t ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir case SbxINTEGER: snprintf( buf, sizeof(buf), "%d", (short) n ); break; 93*cdf0e10cSrcweir case SbxLONG: snprintf( buf, sizeof(buf), "%ld", (long) n ); break; 94*cdf0e10cSrcweir case SbxSINGLE: snprintf( buf, sizeof(buf), "%.6g", (float) n ); break; 95*cdf0e10cSrcweir case SbxDOUBLE: snprintf( buf, sizeof(buf), "%.16g", n ); break; 96*cdf0e10cSrcweir default: break; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir return Add( String::CreateFromAscii( buf ) ); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir /*************************************************************************** 102*cdf0e10cSrcweir |* 103*cdf0e10cSrcweir |* SbiSymPool 104*cdf0e10cSrcweir |* 105*cdf0e10cSrcweir ***************************************************************************/ 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir SbiSymPool::SbiSymPool( SbiStringPool& r, SbiSymScope s ) : rStrings( r ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir pParser = r.GetParser(); 110*cdf0e10cSrcweir eScope = s; 111*cdf0e10cSrcweir pParent = NULL; 112*cdf0e10cSrcweir nCur = 113*cdf0e10cSrcweir nProcId = 0; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir SbiSymPool::~SbiSymPool() 117*cdf0e10cSrcweir {} 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // Inhalt loeschen 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir void SbiSymPool::Clear() 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir aData.DeleteAndDestroy( 0, aData.Count() ); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir SbiSymDef* SbiSymPool::First() 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir nCur = (sal_uInt16) -1; 129*cdf0e10cSrcweir return Next(); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir SbiSymDef* SbiSymPool::Next() 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir if( ++nCur >= aData.Count() ) 135*cdf0e10cSrcweir return NULL; 136*cdf0e10cSrcweir else 137*cdf0e10cSrcweir return aData.GetObject( nCur ); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // Hinzufuegen eines Symbols 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir SbiSymDef* SbiSymPool::AddSym( const String& rName ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir SbiSymDef* p = new SbiSymDef( rName ); 145*cdf0e10cSrcweir p->nPos = aData.Count(); 146*cdf0e10cSrcweir p->nId = rStrings.Add( rName ); 147*cdf0e10cSrcweir p->nProcId = nProcId; 148*cdf0e10cSrcweir p->pIn = this; 149*cdf0e10cSrcweir const SbiSymDef* q = p; 150*cdf0e10cSrcweir aData.Insert( q, q->nPos ); 151*cdf0e10cSrcweir return p; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir SbiProcDef* SbiSymPool::AddProc( const String& rName ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir SbiProcDef* p = new SbiProcDef( pParser, rName ); 157*cdf0e10cSrcweir p->nPos = aData.Count(); 158*cdf0e10cSrcweir p->nId = rStrings.Add( rName ); 159*cdf0e10cSrcweir // Procs sind immer global 160*cdf0e10cSrcweir p->nProcId = 0; 161*cdf0e10cSrcweir p->pIn = this; 162*cdf0e10cSrcweir const SbiSymDef* q = p; 163*cdf0e10cSrcweir aData.Insert( q, q->nPos ); 164*cdf0e10cSrcweir return p; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // Hinzufuegen einer extern aufgebauten Symboldefinition 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir void SbiSymPool::Add( SbiSymDef* pDef ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir if( pDef && pDef->pIn != this ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir if( pDef->pIn ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir #ifdef DBG_UTIL 176*cdf0e10cSrcweir // schon in einem anderen Pool drin! 177*cdf0e10cSrcweir pParser->Error( SbERR_INTERNAL_ERROR, "Dbl Pool" ); 178*cdf0e10cSrcweir #endif 179*cdf0e10cSrcweir return; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir pDef->nPos = aData.Count(); 183*cdf0e10cSrcweir if( !pDef->nId ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir // Bei statischen Variablen muss ein eindeutiger Name 186*cdf0e10cSrcweir // im Stringpool erzeugt werden (Form ProcName:VarName) 187*cdf0e10cSrcweir String aName( pDef->aName ); 188*cdf0e10cSrcweir if( pDef->IsStatic() ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir aName = pParser->aGblStrings.Find( nProcId ); 191*cdf0e10cSrcweir aName += ':'; 192*cdf0e10cSrcweir aName += pDef->aName; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir pDef->nId = rStrings.Add( aName ); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir // Procs sind immer global 197*cdf0e10cSrcweir if( !pDef->GetProcDef() ) 198*cdf0e10cSrcweir pDef->nProcId = nProcId; 199*cdf0e10cSrcweir pDef->pIn = this; 200*cdf0e10cSrcweir const SbiSymDef* q = pDef; 201*cdf0e10cSrcweir aData.Insert( q, q->nPos ); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir // Suchen eines Eintrags ueber den Namen. Es wird auch im Parent gesucht. 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir SbiSymDef* SbiSymPool::Find( const String& rName ) const 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir sal_uInt16 nCount = aData.Count(); 210*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < nCount; i++ ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir SbiSymDef* p = aData.GetObject( nCount - i - 1 ); 213*cdf0e10cSrcweir if( ( !p->nProcId || ( p->nProcId == nProcId ) ) 214*cdf0e10cSrcweir && ( p->aName.EqualsIgnoreCaseAscii( rName ) ) ) 215*cdf0e10cSrcweir return p; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir if( pParent ) 218*cdf0e10cSrcweir return pParent->Find( rName ); 219*cdf0e10cSrcweir else 220*cdf0e10cSrcweir return NULL; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // Suchen ueber ID-Nummer 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir SbiSymDef* SbiSymPool::FindId( sal_uInt16 n ) const 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aData.Count(); i++ ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir SbiSymDef* p = aData.GetObject( i ); 230*cdf0e10cSrcweir if( p->nId == n && ( !p->nProcId || ( p->nProcId == nProcId ) ) ) 231*cdf0e10cSrcweir return p; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir if( pParent ) 234*cdf0e10cSrcweir return pParent->FindId( n ); 235*cdf0e10cSrcweir else 236*cdf0e10cSrcweir return NULL; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir // Suchen ueber Position (ab 0) 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir SbiSymDef* SbiSymPool::Get( sal_uInt16 n ) const 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir if( n >= aData.Count() ) 244*cdf0e10cSrcweir return NULL; 245*cdf0e10cSrcweir else 246*cdf0e10cSrcweir return aData.GetObject( n ); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir sal_uInt32 SbiSymPool::Define( const String& rName ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir SbiSymDef* p = Find( rName ); 252*cdf0e10cSrcweir if( p ) 253*cdf0e10cSrcweir { if( p->IsDefined() ) 254*cdf0e10cSrcweir pParser->Error( SbERR_LABEL_DEFINED, rName ); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir else 257*cdf0e10cSrcweir p = AddSym( rName ); 258*cdf0e10cSrcweir return p->Define(); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir sal_uInt32 SbiSymPool::Reference( const String& rName ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir SbiSymDef* p = Find( rName ); 264*cdf0e10cSrcweir if( !p ) 265*cdf0e10cSrcweir p = AddSym( rName ); 266*cdf0e10cSrcweir //Sicherheitshalber 267*cdf0e10cSrcweir pParser->aGen.GenStmnt(); 268*cdf0e10cSrcweir return p->Reference(); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir // Alle offenen Referenzen anmaulen 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir void SbiSymPool::CheckRefs() 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aData.Count(); i++ ) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir SbiSymDef* p = aData.GetObject( i ); 278*cdf0e10cSrcweir if( !p->IsDefined() ) 279*cdf0e10cSrcweir pParser->Error( SbERR_UNDEF_LABEL, p->GetName() ); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir /*************************************************************************** 284*cdf0e10cSrcweir |* 285*cdf0e10cSrcweir |* Symbol-Definitionen 286*cdf0e10cSrcweir |* 287*cdf0e10cSrcweir ***************************************************************************/ 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir SbiSymDef::SbiSymDef( const String& rName ) : aName( rName ) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir eType = SbxEMPTY; 292*cdf0e10cSrcweir nDims = 0; 293*cdf0e10cSrcweir nTypeId = 0; 294*cdf0e10cSrcweir nProcId = 0; 295*cdf0e10cSrcweir nId = 0; 296*cdf0e10cSrcweir nPos = 0; 297*cdf0e10cSrcweir nLen = 0; 298*cdf0e10cSrcweir nChain = 0; 299*cdf0e10cSrcweir bAs = 300*cdf0e10cSrcweir bNew = 301*cdf0e10cSrcweir bStatic = 302*cdf0e10cSrcweir bOpt = 303*cdf0e10cSrcweir bParamArray = 304*cdf0e10cSrcweir bWithEvents = 305*cdf0e10cSrcweir bWithBrackets = 306*cdf0e10cSrcweir bByVal = 307*cdf0e10cSrcweir bChained = 308*cdf0e10cSrcweir bGlobal = sal_False; 309*cdf0e10cSrcweir pIn = 310*cdf0e10cSrcweir pPool = NULL; 311*cdf0e10cSrcweir nDefaultId = 0; 312*cdf0e10cSrcweir nFixedStringLength = -1; 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir SbiSymDef::~SbiSymDef() 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir delete pPool; 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir SbiProcDef* SbiSymDef::GetProcDef() 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir return NULL; 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir SbiConstDef* SbiSymDef::GetConstDef() 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir return NULL; 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir // Wenn der Name benoetigt wird, den aktuellen Namen 331*cdf0e10cSrcweir // aus dem Stringpool nehmen 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir const String& SbiSymDef::GetName() 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir if( pIn ) 336*cdf0e10cSrcweir aName = pIn->rStrings.Find( nId ); 337*cdf0e10cSrcweir return aName; 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir // Eintragen eines Datentyps 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir void SbiSymDef::SetType( SbxDataType t ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir if( t == SbxVARIANT && pIn ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir sal_Unicode cu = aName.GetBuffer()[0]; 347*cdf0e10cSrcweir if( cu < 256 ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir char ch = (char)aName.GetBuffer()[0]; 350*cdf0e10cSrcweir if( ch == '_' ) ch = 'Z'; 351*cdf0e10cSrcweir int ch2 = toupper( ch ); 352*cdf0e10cSrcweir unsigned char c = (unsigned char)ch2; 353*cdf0e10cSrcweir if( c > 0 && c < 128 ) 354*cdf0e10cSrcweir t = pIn->pParser->eDefTypes[ ch2 - 'A' ]; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir eType = t; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir // Aufbau einer Backchain, falls noch nicht definiert 361*cdf0e10cSrcweir // Es wird der Wert zurueckgeliefert, der als Operand gespeichert 362*cdf0e10cSrcweir // werden soll. 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir sal_uInt32 SbiSymDef::Reference() 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir if( !bChained ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir sal_uInt32 n = nChain; 369*cdf0e10cSrcweir nChain = pIn->pParser->aGen.GetOffset(); 370*cdf0e10cSrcweir return n; 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir else return nChain; 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir // Definition eines Symbols. 376*cdf0e10cSrcweir // Hier wird der Backchain aufgeloest, falls vorhanden 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir sal_uInt32 SbiSymDef::Define() 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir sal_uInt32 n = pIn->pParser->aGen.GetPC(); 381*cdf0e10cSrcweir pIn->pParser->aGen.GenStmnt(); 382*cdf0e10cSrcweir if( nChain ) pIn->pParser->aGen.BackChain( nChain ); 383*cdf0e10cSrcweir nChain = n; 384*cdf0e10cSrcweir bChained = sal_True; 385*cdf0e10cSrcweir return nChain; 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir // Eine Symboldefinition kann einen eigenen Pool haben. Dies ist 389*cdf0e10cSrcweir // der Fall bei Objekten und Prozeduren (lokale Variable) 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir SbiSymPool& SbiSymDef::GetPool() 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir if( !pPool ) 394*cdf0e10cSrcweir pPool = new SbiSymPool( pIn->pParser->aGblStrings, SbLOCAL ); // wird gedumpt 395*cdf0e10cSrcweir return *pPool; 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir SbiSymScope SbiSymDef::GetScope() const 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir return pIn ? pIn->GetScope() : SbLOCAL; 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////// 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir // Die Prozedur-Definition hat drei Pools: 406*cdf0e10cSrcweir // 1) aParams: wird durch die Definition gefuellt. Enthaelt die Namen 407*cdf0e10cSrcweir // der Parameter, wie sie innerhalb des Rumpfes verwendet werden. 408*cdf0e10cSrcweir // Das erste Element ist der Returnwert. 409*cdf0e10cSrcweir // 2) pPool: saemtliche lokale Variable 410*cdf0e10cSrcweir // 3) aLabels: Labels 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir SbiProcDef::SbiProcDef( SbiParser* pParser, const String& rName, 413*cdf0e10cSrcweir sal_Bool bProcDecl ) 414*cdf0e10cSrcweir : SbiSymDef( rName ) 415*cdf0e10cSrcweir , aParams( pParser->aGblStrings, SbPARAM ) // wird gedumpt 416*cdf0e10cSrcweir , aLabels( pParser->aLclStrings, SbLOCAL ) // wird nicht gedumpt 417*cdf0e10cSrcweir , mbProcDecl( bProcDecl ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir aParams.SetParent( &pParser->aPublics ); 420*cdf0e10cSrcweir pPool = new SbiSymPool( pParser->aGblStrings, SbLOCAL ); // Locals 421*cdf0e10cSrcweir pPool->SetParent( &aParams ); 422*cdf0e10cSrcweir nLine1 = 423*cdf0e10cSrcweir nLine2 = 0; 424*cdf0e10cSrcweir mePropMode = PROPERTY_MODE_NONE; 425*cdf0e10cSrcweir bPublic = sal_True; 426*cdf0e10cSrcweir bCdecl = sal_False; 427*cdf0e10cSrcweir bStatic = sal_False; 428*cdf0e10cSrcweir // Fuer Returnwerte ist das erste Element der Parameterliste 429*cdf0e10cSrcweir // immer mit dem Namen und dem Typ der Proc definiert 430*cdf0e10cSrcweir aParams.AddSym( aName ); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir SbiProcDef::~SbiProcDef() 434*cdf0e10cSrcweir {} 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir SbiProcDef* SbiProcDef::GetProcDef() 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir return this; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir void SbiProcDef::SetType( SbxDataType t ) 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir SbiSymDef::SetType( t ); 444*cdf0e10cSrcweir aParams.Get( 0 )->SetType( eType ); 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir // Match mit einer Forward-Deklaration 448*cdf0e10cSrcweir // Falls der Match OK ist, wird pOld durch this im Pool ersetzt 449*cdf0e10cSrcweir // pOld wird immer geloescht! 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir void SbiProcDef::Match( SbiProcDef* pOld ) 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir SbiSymDef* po, *pn=NULL; 454*cdf0e10cSrcweir // Parameter 0 ist der Funktionsname 455*cdf0e10cSrcweir sal_uInt16 i; 456*cdf0e10cSrcweir for( i = 1; i < aParams.GetSize(); i++ ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir po = pOld->aParams.Get( i ); 459*cdf0e10cSrcweir pn = aParams.Get( i ); 460*cdf0e10cSrcweir // Kein Typabgleich; das wird beim Laufen erledigt 461*cdf0e10cSrcweir // aber ist sie evtl. mit zu wenigen Parametern aufgerufen 462*cdf0e10cSrcweir // worden? 463*cdf0e10cSrcweir if( !po && !pn->IsOptional() && !pn->IsParamArray() ) 464*cdf0e10cSrcweir break; 465*cdf0e10cSrcweir po = pOld->aParams.Next(); 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir // Wurden zu viele Parameter angegeben? 468*cdf0e10cSrcweir if( pn && i < aParams.GetSize() && pOld->pIn ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir // Die ganze Zeile markieren 471*cdf0e10cSrcweir pOld->pIn->GetParser()->SetCol1( 0 ); 472*cdf0e10cSrcweir pOld->pIn->GetParser()->Error( SbERR_BAD_DECLARATION, aName ); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir if( !pIn && pOld->pIn ) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir // Alten Eintrag durch neuen ersetzen 477*cdf0e10cSrcweir SbiSymDef** pData = (SbiSymDef**) pOld->pIn->aData.GetData(); 478*cdf0e10cSrcweir pData[ pOld->nPos ] = this; 479*cdf0e10cSrcweir nPos = pOld->nPos; 480*cdf0e10cSrcweir nId = pOld->nId; 481*cdf0e10cSrcweir pIn = pOld->pIn; 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir delete pOld; 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir void SbiProcDef::setPropertyMode( PropertyMode ePropMode ) 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir mePropMode = ePropMode; 489*cdf0e10cSrcweir if( mePropMode != PROPERTY_MODE_NONE ) 490*cdf0e10cSrcweir { 491*cdf0e10cSrcweir // Prop name = original scanned procedure name 492*cdf0e10cSrcweir maPropName = aName; 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir // CompleteProcName includes "Property xxx " 495*cdf0e10cSrcweir // to avoid conflicts with other symbols 496*cdf0e10cSrcweir String aCompleteProcName; 497*cdf0e10cSrcweir aCompleteProcName.AppendAscii( "Property " ); 498*cdf0e10cSrcweir switch( mePropMode ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir case PROPERTY_MODE_GET: aCompleteProcName.AppendAscii( "Get " ); break; 501*cdf0e10cSrcweir case PROPERTY_MODE_LET: aCompleteProcName.AppendAscii( "Let " ); break; 502*cdf0e10cSrcweir case PROPERTY_MODE_SET: aCompleteProcName.AppendAscii( "Set " ); break; 503*cdf0e10cSrcweir case PROPERTY_MODE_NONE: 504*cdf0e10cSrcweir DBG_ERROR( "Illegal PropertyMode PROPERTY_MODE_NONE" ); 505*cdf0e10cSrcweir break; 506*cdf0e10cSrcweir } 507*cdf0e10cSrcweir aCompleteProcName += aName; 508*cdf0e10cSrcweir aName = aCompleteProcName; 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////// 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir SbiConstDef::SbiConstDef( const String& rName ) 516*cdf0e10cSrcweir : SbiSymDef( rName ) 517*cdf0e10cSrcweir { 518*cdf0e10cSrcweir nVal = 0; eType = SbxINTEGER; 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir void SbiConstDef::Set( double n, SbxDataType t ) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir aVal.Erase(); nVal = n; eType = t; 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir void SbiConstDef::Set( const String& n ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir aVal = n; nVal = 0; eType = SbxSTRING; 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir SbiConstDef::~SbiConstDef() 532*cdf0e10cSrcweir {} 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir SbiConstDef* SbiConstDef::GetConstDef() 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir return this; 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir 539