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