xref: /AOO41X/main/basic/source/comp/dim.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_basic.hxx"
30*cdf0e10cSrcweir #include <basic/sbx.hxx>
31*cdf0e10cSrcweir #include "sbcomp.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir SbxObject* cloneTypeObjectImpl( const SbxObject& rTypeObj );
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // Deklaration einer Variablen
36*cdf0e10cSrcweir // Bei Fehlern wird bis zum Komma oder Newline geparst.
37*cdf0e10cSrcweir // Returnwert: eine neue Instanz, die eingefuegt und dann geloescht wird.
38*cdf0e10cSrcweir // Array-Indexe werden als SbiDimList zurueckgegeben
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir SbiSymDef* SbiParser::VarDecl( SbiDimList** ppDim, sal_Bool bStatic, sal_Bool bConst )
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir 	bool bWithEvents = false;
43*cdf0e10cSrcweir 	if( Peek() == WITHEVENTS )
44*cdf0e10cSrcweir 	{
45*cdf0e10cSrcweir 		Next();
46*cdf0e10cSrcweir 		bWithEvents = true;
47*cdf0e10cSrcweir 	}
48*cdf0e10cSrcweir 	if( !TestSymbol() ) return NULL;
49*cdf0e10cSrcweir 	SbxDataType t = eScanType;
50*cdf0e10cSrcweir 	SbiSymDef* pDef = bConst ? new SbiConstDef( aSym ) : new SbiSymDef( aSym );
51*cdf0e10cSrcweir 	SbiDimList* pDim = NULL;
52*cdf0e10cSrcweir 	// Klammern?
53*cdf0e10cSrcweir 	if( Peek() == LPAREN )
54*cdf0e10cSrcweir 	{
55*cdf0e10cSrcweir 		pDim = new SbiDimList( this );
56*cdf0e10cSrcweir 		if( !pDim->GetDims() )
57*cdf0e10cSrcweir 			pDef->SetWithBrackets();
58*cdf0e10cSrcweir 	}
59*cdf0e10cSrcweir 	pDef->SetType( t );
60*cdf0e10cSrcweir 	if( bStatic )
61*cdf0e10cSrcweir 		pDef->SetStatic();
62*cdf0e10cSrcweir 	if( bWithEvents )
63*cdf0e10cSrcweir 		pDef->SetWithEvents();
64*cdf0e10cSrcweir 	TypeDecl( *pDef );
65*cdf0e10cSrcweir 	if( !ppDim && pDim )
66*cdf0e10cSrcweir 	{
67*cdf0e10cSrcweir 		if(pDim->GetDims() )
68*cdf0e10cSrcweir 			Error( SbERR_EXPECTED, "()" );
69*cdf0e10cSrcweir 		delete pDim;
70*cdf0e10cSrcweir 	}
71*cdf0e10cSrcweir 	else if( ppDim )
72*cdf0e10cSrcweir 		*ppDim = pDim;
73*cdf0e10cSrcweir 	return pDef;
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir // Aufloesen einer AS-Typdeklaration
77*cdf0e10cSrcweir // Der Datentyp wird in die uebergebene Variable eingetragen
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir void SbiParser::TypeDecl( SbiSymDef& rDef, sal_Bool bAsNewAlreadyParsed )
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 	SbxDataType eType = rDef.GetType();
82*cdf0e10cSrcweir 	short nSize = 0;
83*cdf0e10cSrcweir 	if( bAsNewAlreadyParsed || Peek() == AS )
84*cdf0e10cSrcweir 	{
85*cdf0e10cSrcweir 		if( !bAsNewAlreadyParsed )
86*cdf0e10cSrcweir 			Next();
87*cdf0e10cSrcweir 		rDef.SetDefinedAs();
88*cdf0e10cSrcweir 		String aType;
89*cdf0e10cSrcweir 		SbiToken eTok = Next();
90*cdf0e10cSrcweir 		if( !bAsNewAlreadyParsed && eTok == NEW )
91*cdf0e10cSrcweir 		{
92*cdf0e10cSrcweir 			rDef.SetNew();
93*cdf0e10cSrcweir 			eTok = Next();
94*cdf0e10cSrcweir 		}
95*cdf0e10cSrcweir 		switch( eTok )
96*cdf0e10cSrcweir 		{
97*cdf0e10cSrcweir 			case ANY:
98*cdf0e10cSrcweir 				if( rDef.IsNew() )
99*cdf0e10cSrcweir 					Error( SbERR_SYNTAX );
100*cdf0e10cSrcweir 				eType = SbxVARIANT; break;
101*cdf0e10cSrcweir 			case TINTEGER:
102*cdf0e10cSrcweir 			case TLONG:
103*cdf0e10cSrcweir 			case TSINGLE:
104*cdf0e10cSrcweir 			case TDOUBLE:
105*cdf0e10cSrcweir 			case TCURRENCY:
106*cdf0e10cSrcweir 			case TDATE:
107*cdf0e10cSrcweir 			case TSTRING:
108*cdf0e10cSrcweir 			case TOBJECT:
109*cdf0e10cSrcweir 			case _ERROR_:
110*cdf0e10cSrcweir 			case TBOOLEAN:
111*cdf0e10cSrcweir 			case TVARIANT:
112*cdf0e10cSrcweir 			case TBYTE:
113*cdf0e10cSrcweir 				if( rDef.IsNew() )
114*cdf0e10cSrcweir 					Error( SbERR_SYNTAX );
115*cdf0e10cSrcweir 				eType = (eTok==TBYTE) ? SbxBYTE : SbxDataType( eTok - TINTEGER + SbxINTEGER );
116*cdf0e10cSrcweir 				if( eType == SbxSTRING )
117*cdf0e10cSrcweir 				{
118*cdf0e10cSrcweir 					// STRING*n ?
119*cdf0e10cSrcweir 					if( Peek() == MUL )
120*cdf0e10cSrcweir 					{		// fixed size!
121*cdf0e10cSrcweir 						Next();
122*cdf0e10cSrcweir 						SbiConstExpression aSize( this );
123*cdf0e10cSrcweir 						nSize = aSize.GetShortValue();
124*cdf0e10cSrcweir 						if( nSize < 0 || (bVBASupportOn && nSize <= 0) )
125*cdf0e10cSrcweir 							Error( SbERR_OUT_OF_RANGE );
126*cdf0e10cSrcweir 						else
127*cdf0e10cSrcweir 							rDef.SetFixedStringLength( nSize );
128*cdf0e10cSrcweir 					}
129*cdf0e10cSrcweir 				}
130*cdf0e10cSrcweir 				break;
131*cdf0e10cSrcweir 			case SYMBOL: // kann nur ein TYPE oder eine Objektklasse sein!
132*cdf0e10cSrcweir 				if( eScanType != SbxVARIANT )
133*cdf0e10cSrcweir 					Error( SbERR_SYNTAX );
134*cdf0e10cSrcweir 				else
135*cdf0e10cSrcweir 				{
136*cdf0e10cSrcweir 					String aCompleteName = aSym;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 					// #52709 DIM AS NEW fuer Uno mit voll-qualifizierten Namen
139*cdf0e10cSrcweir 					if( Peek() == DOT )
140*cdf0e10cSrcweir 					{
141*cdf0e10cSrcweir 						String aDotStr( '.' );
142*cdf0e10cSrcweir 						while( Peek() == DOT )
143*cdf0e10cSrcweir 						{
144*cdf0e10cSrcweir 							aCompleteName += aDotStr;
145*cdf0e10cSrcweir 							Next();
146*cdf0e10cSrcweir                             SbiToken ePeekTok = Peek();
147*cdf0e10cSrcweir 							if( ePeekTok == SYMBOL || IsKwd( ePeekTok ) )
148*cdf0e10cSrcweir 							{
149*cdf0e10cSrcweir 								Next();
150*cdf0e10cSrcweir 								aCompleteName += aSym;
151*cdf0e10cSrcweir 							}
152*cdf0e10cSrcweir 							else
153*cdf0e10cSrcweir 							{
154*cdf0e10cSrcweir 								Next();
155*cdf0e10cSrcweir 								Error( SbERR_UNEXPECTED, SYMBOL );
156*cdf0e10cSrcweir 								break;
157*cdf0e10cSrcweir 							}
158*cdf0e10cSrcweir 						}
159*cdf0e10cSrcweir 					}
160*cdf0e10cSrcweir 					else if( rEnumArray->Find( aCompleteName, SbxCLASS_OBJECT ) )
161*cdf0e10cSrcweir 					{
162*cdf0e10cSrcweir 						eType = SbxLONG;
163*cdf0e10cSrcweir 						break;
164*cdf0e10cSrcweir 					}
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 					// In den String-Pool uebernehmen
167*cdf0e10cSrcweir 					rDef.SetTypeId( aGblStrings.Add( aCompleteName ) );
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 					if( rDef.IsNew() && pProc == NULL )
170*cdf0e10cSrcweir 						aRequiredTypes.push_back( aCompleteName );
171*cdf0e10cSrcweir 				}
172*cdf0e10cSrcweir 				eType = SbxOBJECT;
173*cdf0e10cSrcweir 				break;
174*cdf0e10cSrcweir 			case FIXSTRING: // new syntax for complex UNO types
175*cdf0e10cSrcweir 				rDef.SetTypeId( aGblStrings.Add( aSym ) );
176*cdf0e10cSrcweir 				eType = SbxOBJECT;
177*cdf0e10cSrcweir 				break;
178*cdf0e10cSrcweir 			default:
179*cdf0e10cSrcweir 				Error( SbERR_UNEXPECTED, eTok );
180*cdf0e10cSrcweir 				Next();
181*cdf0e10cSrcweir 		}
182*cdf0e10cSrcweir 		// Die Variable koennte mit Suffix deklariert sein
183*cdf0e10cSrcweir 		if( rDef.GetType() != SbxVARIANT )
184*cdf0e10cSrcweir 		{
185*cdf0e10cSrcweir 			if( rDef.GetType() != eType )
186*cdf0e10cSrcweir 				Error( SbERR_VAR_DEFINED, rDef.GetName() );
187*cdf0e10cSrcweir 			else if( eType == SbxSTRING && rDef.GetLen() != nSize )
188*cdf0e10cSrcweir 				Error( SbERR_VAR_DEFINED, rDef.GetName() );
189*cdf0e10cSrcweir 		}
190*cdf0e10cSrcweir 		rDef.SetType( eType );
191*cdf0e10cSrcweir 		rDef.SetLen( nSize );
192*cdf0e10cSrcweir 	}
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // Hier werden Variable, Arrays und Strukturen definiert.
196*cdf0e10cSrcweir // DIM/PRIVATE/PUBLIC/GLOBAL
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir void SbiParser::Dim()
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir 	DefVar( _DIM, ( pProc && bVBASupportOn ) ? pProc->IsStatic() : sal_False );
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir void SbiParser::DefVar( SbiOpcode eOp, sal_Bool bStatic )
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir 	SbiSymPool* pOldPool = pPool;
206*cdf0e10cSrcweir 	sal_Bool bSwitchPool = sal_False;
207*cdf0e10cSrcweir 	sal_Bool bPersistantGlobal = sal_False;
208*cdf0e10cSrcweir 	SbiToken eFirstTok = eCurTok;
209*cdf0e10cSrcweir 	if( pProc && ( eCurTok == GLOBAL || eCurTok == PUBLIC || eCurTok == PRIVATE ) )
210*cdf0e10cSrcweir 		Error( SbERR_NOT_IN_SUBR, eCurTok );
211*cdf0e10cSrcweir 	if( eCurTok == PUBLIC || eCurTok == GLOBAL )
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir 		bSwitchPool = sal_True;		// im richtigen Moment auf globalen Pool schalten
214*cdf0e10cSrcweir     	if( eCurTok == GLOBAL )
215*cdf0e10cSrcweir             bPersistantGlobal = sal_True;
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir 	// behavior in VBA is that a module scope variable's lifetime is
218*cdf0e10cSrcweir 	// tied to the document. e.g. a module scope variable is global
219*cdf0e10cSrcweir    	if(  GetBasic()->IsDocBasic() && bVBASupportOn && !pProc )
220*cdf0e10cSrcweir 		bPersistantGlobal = sal_True;
221*cdf0e10cSrcweir 	// PRIVATE ist Synonym fuer DIM
222*cdf0e10cSrcweir 	// _CONST_?
223*cdf0e10cSrcweir 	sal_Bool bConst = sal_False;
224*cdf0e10cSrcweir 	if( eCurTok == _CONST_ )
225*cdf0e10cSrcweir 		bConst = sal_True;
226*cdf0e10cSrcweir 	else if( Peek() == _CONST_ )
227*cdf0e10cSrcweir 		Next(), bConst = sal_True;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	// #110004 It can also be a sub/function
230*cdf0e10cSrcweir 	if( !bConst && (eCurTok == SUB || eCurTok == FUNCTION || eCurTok == PROPERTY ||
231*cdf0e10cSrcweir 					eCurTok == STATIC || eCurTok == ENUM || eCurTok == DECLARE || eCurTok == TYPE) )
232*cdf0e10cSrcweir 	{
233*cdf0e10cSrcweir 		// Next token is read here, because !bConst
234*cdf0e10cSrcweir 		bool bPrivate = ( eFirstTok == PRIVATE );
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 		if( eCurTok == STATIC )
237*cdf0e10cSrcweir 		{
238*cdf0e10cSrcweir 			Next();
239*cdf0e10cSrcweir 			DefStatic( bPrivate );
240*cdf0e10cSrcweir 		}
241*cdf0e10cSrcweir 		else if( eCurTok == SUB || eCurTok == FUNCTION || eCurTok == PROPERTY )
242*cdf0e10cSrcweir 		{
243*cdf0e10cSrcweir 			// End global chain if necessary (not done in
244*cdf0e10cSrcweir 			// SbiParser::Parse() under these conditions
245*cdf0e10cSrcweir 			if( bNewGblDefs && nGblChain == 0 )
246*cdf0e10cSrcweir 			{
247*cdf0e10cSrcweir 				nGblChain = aGen.Gen( _JUMP, 0 );
248*cdf0e10cSrcweir 				bNewGblDefs = sal_False;
249*cdf0e10cSrcweir 			}
250*cdf0e10cSrcweir 			Next();
251*cdf0e10cSrcweir 			DefProc( sal_False, bPrivate );
252*cdf0e10cSrcweir 			return;
253*cdf0e10cSrcweir 		}
254*cdf0e10cSrcweir 		else if( eCurTok == ENUM )
255*cdf0e10cSrcweir 		{
256*cdf0e10cSrcweir 			Next();
257*cdf0e10cSrcweir 			DefEnum( bPrivate );
258*cdf0e10cSrcweir 			return;
259*cdf0e10cSrcweir 		}
260*cdf0e10cSrcweir 		else if( eCurTok == DECLARE )
261*cdf0e10cSrcweir 		{
262*cdf0e10cSrcweir 			Next();
263*cdf0e10cSrcweir 			DefDeclare( bPrivate );
264*cdf0e10cSrcweir 			return;
265*cdf0e10cSrcweir 		}
266*cdf0e10cSrcweir 		// #i109049
267*cdf0e10cSrcweir 		else if( eCurTok == TYPE )
268*cdf0e10cSrcweir 		{
269*cdf0e10cSrcweir 			Next();
270*cdf0e10cSrcweir 			DefType( bPrivate );
271*cdf0e10cSrcweir 			return;
272*cdf0e10cSrcweir 		}
273*cdf0e10cSrcweir 	}
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir #ifdef SHARED
276*cdf0e10cSrcweir #define tmpSHARED
277*cdf0e10cSrcweir #undef SHARED
278*cdf0e10cSrcweir #endif
279*cdf0e10cSrcweir 	// SHARED wird ignoriert
280*cdf0e10cSrcweir 	if( Peek() == SHARED ) Next();
281*cdf0e10cSrcweir #ifdef tmpSHARED
282*cdf0e10cSrcweir #define SHARED
283*cdf0e10cSrcweir #undef tmpSHARED
284*cdf0e10cSrcweir #endif
285*cdf0e10cSrcweir 	// PRESERVE nur bei REDIM
286*cdf0e10cSrcweir 	if( Peek() == PRESERVE )
287*cdf0e10cSrcweir 	{
288*cdf0e10cSrcweir 		Next();
289*cdf0e10cSrcweir 		if( eOp == _REDIM )
290*cdf0e10cSrcweir 			eOp = _REDIMP;
291*cdf0e10cSrcweir 		else
292*cdf0e10cSrcweir 			Error( SbERR_UNEXPECTED, eCurTok );
293*cdf0e10cSrcweir 	}
294*cdf0e10cSrcweir 	SbiSymDef* pDef;
295*cdf0e10cSrcweir 	SbiDimList* pDim;
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 	// AB 9.7.97, #40689, Statics -> Modul-Initialisierung, in Sub ueberspringen
298*cdf0e10cSrcweir 	sal_uInt32 nEndOfStaticLbl = 0;
299*cdf0e10cSrcweir 	if( !bVBASupportOn && bStatic )
300*cdf0e10cSrcweir 	{
301*cdf0e10cSrcweir 		nEndOfStaticLbl = aGen.Gen( _JUMP, 0 );
302*cdf0e10cSrcweir 		aGen.Statement();	// bei static hier nachholen
303*cdf0e10cSrcweir 	}
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	sal_Bool bDefined = sal_False;
306*cdf0e10cSrcweir 	while( ( pDef = VarDecl( &pDim, bStatic, bConst ) ) != NULL )
307*cdf0e10cSrcweir 	{
308*cdf0e10cSrcweir 		EnableErrors();
309*cdf0e10cSrcweir 		// Variable suchen:
310*cdf0e10cSrcweir 		if( bSwitchPool )
311*cdf0e10cSrcweir 			pPool = &aGlobals;
312*cdf0e10cSrcweir 		SbiSymDef* pOld = pPool->Find( pDef->GetName() );
313*cdf0e10cSrcweir 		// AB 31.3.1996, #25651#, auch in Runtime-Library suchen
314*cdf0e10cSrcweir 		sal_Bool bRtlSym = sal_False;
315*cdf0e10cSrcweir 		if( !pOld )
316*cdf0e10cSrcweir 		{
317*cdf0e10cSrcweir 			pOld = CheckRTLForSym( pDef->GetName(), SbxVARIANT );
318*cdf0e10cSrcweir 			if( pOld )
319*cdf0e10cSrcweir 				bRtlSym = sal_True;
320*cdf0e10cSrcweir 		}
321*cdf0e10cSrcweir 		if( pOld && !(eOp == _REDIM || eOp == _REDIMP) )
322*cdf0e10cSrcweir 		{
323*cdf0e10cSrcweir 			if( pDef->GetScope() == SbLOCAL && pOld->GetScope() != SbLOCAL )
324*cdf0e10cSrcweir 				pOld = NULL;
325*cdf0e10cSrcweir 		}
326*cdf0e10cSrcweir 		if( pOld )
327*cdf0e10cSrcweir 		{
328*cdf0e10cSrcweir 			bDefined = sal_True;
329*cdf0e10cSrcweir 			// Bei RTL-Symbol immer Fehler
330*cdf0e10cSrcweir 			if( !bRtlSym && (eOp == _REDIM || eOp == _REDIMP) )
331*cdf0e10cSrcweir 			{
332*cdf0e10cSrcweir 				// Bei REDIM die Attribute vergleichen
333*cdf0e10cSrcweir 				SbxDataType eDefType;
334*cdf0e10cSrcweir 				bool bError_ = false;
335*cdf0e10cSrcweir 				if( pOld->IsStatic() )
336*cdf0e10cSrcweir 				{
337*cdf0e10cSrcweir 					bError_ = true;
338*cdf0e10cSrcweir 				}
339*cdf0e10cSrcweir 				else if( pOld->GetType() != ( eDefType = pDef->GetType() ) )
340*cdf0e10cSrcweir 				{
341*cdf0e10cSrcweir 					if( !( eDefType == SbxVARIANT && !pDef->IsDefinedAs() ) )
342*cdf0e10cSrcweir 						bError_ = true;
343*cdf0e10cSrcweir 				}
344*cdf0e10cSrcweir 				if( bError_ )
345*cdf0e10cSrcweir 					Error( SbERR_VAR_DEFINED, pDef->GetName() );
346*cdf0e10cSrcweir 			}
347*cdf0e10cSrcweir 			else
348*cdf0e10cSrcweir 				Error( SbERR_VAR_DEFINED, pDef->GetName() );
349*cdf0e10cSrcweir 			delete pDef; pDef = pOld;
350*cdf0e10cSrcweir 		}
351*cdf0e10cSrcweir 		else
352*cdf0e10cSrcweir 			pPool->Add( pDef );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir 		// #36374: Variable vor Unterscheidung IsNew() anlegen
355*cdf0e10cSrcweir 		// Sonst Error bei Dim Identifier As New Type und option explicit
356*cdf0e10cSrcweir 		if( !bDefined && !(eOp == _REDIM || eOp == _REDIMP)
357*cdf0e10cSrcweir                       && ( !bConst || pDef->GetScope() == SbGLOBAL ) )
358*cdf0e10cSrcweir 		{
359*cdf0e10cSrcweir 			// Variable oder globale Konstante deklarieren
360*cdf0e10cSrcweir 			SbiOpcode eOp2;
361*cdf0e10cSrcweir 			switch ( pDef->GetScope() )
362*cdf0e10cSrcweir 			{
363*cdf0e10cSrcweir 				case SbGLOBAL:	eOp2 = bPersistantGlobal ? _GLOBAL_P : _GLOBAL;
364*cdf0e10cSrcweir                                 goto global;
365*cdf0e10cSrcweir 				case SbPUBLIC:	eOp2 = bPersistantGlobal ? _PUBLIC_P : _PUBLIC;
366*cdf0e10cSrcweir 								// AB 9.7.97, #40689, kein eigener Opcode mehr
367*cdf0e10cSrcweir 								if( bVBASupportOn && bStatic )
368*cdf0e10cSrcweir 								{
369*cdf0e10cSrcweir 									eOp2 = _STATIC;
370*cdf0e10cSrcweir 									break;
371*cdf0e10cSrcweir 								}
372*cdf0e10cSrcweir 				global:			aGen.BackChain( nGblChain );
373*cdf0e10cSrcweir 								nGblChain = 0;
374*cdf0e10cSrcweir 								bGblDefs = bNewGblDefs = sal_True;
375*cdf0e10cSrcweir 								break;
376*cdf0e10cSrcweir 				default:		eOp2 = _LOCAL;
377*cdf0e10cSrcweir 			}
378*cdf0e10cSrcweir 			sal_uInt32 nOpnd2 = sal::static_int_cast< sal_uInt16 >( pDef->GetType() );
379*cdf0e10cSrcweir 			if( pDef->IsWithEvents() )
380*cdf0e10cSrcweir 				nOpnd2 |= SBX_TYPE_WITH_EVENTS_FLAG;
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 			if( bCompatible && pDef->IsNew() )
383*cdf0e10cSrcweir 				nOpnd2 |= SBX_TYPE_DIM_AS_NEW_FLAG;
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 			short nFixedStringLength = pDef->GetFixedStringLength();
386*cdf0e10cSrcweir 			if( nFixedStringLength >= 0 )
387*cdf0e10cSrcweir 				nOpnd2 |= (SBX_FIXED_LEN_STRING_FLAG + (sal_uInt32(nFixedStringLength) << 17));		// len = all bits above 0x10000
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 			if( pDim != NULL && pDim->GetDims() > 0 )
390*cdf0e10cSrcweir 				nOpnd2 |= SBX_TYPE_VAR_TO_DIM_FLAG;
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 			aGen.Gen( eOp2, pDef->GetId(), nOpnd2 );
393*cdf0e10cSrcweir 		}
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 		// Initialisierung fuer selbstdefinierte Datentypen
396*cdf0e10cSrcweir 		// und per NEW angelegte Variable
397*cdf0e10cSrcweir 		if( pDef->GetType() == SbxOBJECT
398*cdf0e10cSrcweir 		 && pDef->GetTypeId() )
399*cdf0e10cSrcweir 		{
400*cdf0e10cSrcweir 			if( !bCompatible && !pDef->IsNew() )
401*cdf0e10cSrcweir 			{
402*cdf0e10cSrcweir 				String aTypeName( aGblStrings.Find( pDef->GetTypeId() ) );
403*cdf0e10cSrcweir 				if( rTypeArray->Find( aTypeName, SbxCLASS_OBJECT ) == NULL )
404*cdf0e10cSrcweir 					Error( SbERR_UNDEF_TYPE, aTypeName );
405*cdf0e10cSrcweir 			}
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 			if( bConst )
408*cdf0e10cSrcweir 			{
409*cdf0e10cSrcweir 				Error( SbERR_SYNTAX );
410*cdf0e10cSrcweir 			}
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 			if( pDim )
413*cdf0e10cSrcweir 			{
414*cdf0e10cSrcweir                 if( eOp == _REDIMP )
415*cdf0e10cSrcweir                 {
416*cdf0e10cSrcweir 					SbiExpression aExpr( this, *pDef, NULL );
417*cdf0e10cSrcweir 					aExpr.Gen();
418*cdf0e10cSrcweir 					aGen.Gen( _REDIMP_ERASE );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 				    pDef->SetDims( pDim->GetDims() );
421*cdf0e10cSrcweir 				    SbiExpression aExpr2( this, *pDef, pDim );
422*cdf0e10cSrcweir 				    aExpr2.Gen();
423*cdf0e10cSrcweir     				aGen.Gen( _DCREATE_REDIMP, pDef->GetId(), pDef->GetTypeId() );
424*cdf0e10cSrcweir                 }
425*cdf0e10cSrcweir                 else
426*cdf0e10cSrcweir                 {
427*cdf0e10cSrcweir 				    pDef->SetDims( pDim->GetDims() );
428*cdf0e10cSrcweir 				    SbiExpression aExpr( this, *pDef, pDim );
429*cdf0e10cSrcweir 				    aExpr.Gen();
430*cdf0e10cSrcweir 	    			aGen.Gen( _DCREATE, pDef->GetId(), pDef->GetTypeId() );
431*cdf0e10cSrcweir                 }
432*cdf0e10cSrcweir 			}
433*cdf0e10cSrcweir 			else
434*cdf0e10cSrcweir 			{
435*cdf0e10cSrcweir 				SbiExpression aExpr( this, *pDef );
436*cdf0e10cSrcweir 				aExpr.Gen();
437*cdf0e10cSrcweir 				SbiOpcode eOp_ = pDef->IsNew() ? _CREATE : _TCREATE;
438*cdf0e10cSrcweir 				aGen.Gen( eOp_, pDef->GetId(), pDef->GetTypeId() );
439*cdf0e10cSrcweir 				aGen.Gen( _SET );
440*cdf0e10cSrcweir 			}
441*cdf0e10cSrcweir 		}
442*cdf0e10cSrcweir 		else
443*cdf0e10cSrcweir 		{
444*cdf0e10cSrcweir 			if( bConst )
445*cdf0e10cSrcweir 			{
446*cdf0e10cSrcweir 				// Konstanten-Definition
447*cdf0e10cSrcweir 				if( pDim )
448*cdf0e10cSrcweir 				{
449*cdf0e10cSrcweir 					Error( SbERR_SYNTAX );
450*cdf0e10cSrcweir 					delete pDim;
451*cdf0e10cSrcweir 				}
452*cdf0e10cSrcweir 				SbiExpression aVar( this, *pDef );
453*cdf0e10cSrcweir 				if( !TestToken( EQ ) )
454*cdf0e10cSrcweir 					goto MyBreak;	// AB 24.6.1996 (s.u.)
455*cdf0e10cSrcweir 				SbiConstExpression aExpr( this );
456*cdf0e10cSrcweir 				if( !bDefined && aExpr.IsValid() )
457*cdf0e10cSrcweir 				{
458*cdf0e10cSrcweir 					if( pDef->GetScope() == SbGLOBAL )
459*cdf0e10cSrcweir 					{
460*cdf0e10cSrcweir 						// Nur Code fuer globale Konstante erzeugen!
461*cdf0e10cSrcweir 						aVar.Gen();
462*cdf0e10cSrcweir 						aExpr.Gen();
463*cdf0e10cSrcweir 						aGen.Gen( _PUTC );
464*cdf0e10cSrcweir 					}
465*cdf0e10cSrcweir 					SbiConstDef* pConst = pDef->GetConstDef();
466*cdf0e10cSrcweir 					if( aExpr.GetType() == SbxSTRING )
467*cdf0e10cSrcweir 						pConst->Set( aExpr.GetString() );
468*cdf0e10cSrcweir 					else
469*cdf0e10cSrcweir 						pConst->Set( aExpr.GetValue(), aExpr.GetType() );
470*cdf0e10cSrcweir 				}
471*cdf0e10cSrcweir 			}
472*cdf0e10cSrcweir 			else if( pDim )
473*cdf0e10cSrcweir 			{
474*cdf0e10cSrcweir 				// Die Variable dimensionieren
475*cdf0e10cSrcweir 				// Bei REDIM die Var vorher loeschen
476*cdf0e10cSrcweir 				if( eOp == _REDIM )
477*cdf0e10cSrcweir 				{
478*cdf0e10cSrcweir 					SbiExpression aExpr( this, *pDef, NULL );
479*cdf0e10cSrcweir 					aExpr.Gen();
480*cdf0e10cSrcweir 					if ( bVBASupportOn )
481*cdf0e10cSrcweir 						// delete the array but
482*cdf0e10cSrcweir 						// clear the variable ( this
483*cdf0e10cSrcweir 						// allows the processing of
484*cdf0e10cSrcweir 						// the param to happen as normal without errors ( ordinary ERASE just clears the array )
485*cdf0e10cSrcweir 						aGen.Gen( _ERASE_CLEAR );
486*cdf0e10cSrcweir 					else
487*cdf0e10cSrcweir 						aGen.Gen( _ERASE );
488*cdf0e10cSrcweir 				}
489*cdf0e10cSrcweir 				else if( eOp == _REDIMP )
490*cdf0e10cSrcweir 				{
491*cdf0e10cSrcweir 					SbiExpression aExpr( this, *pDef, NULL );
492*cdf0e10cSrcweir 					aExpr.Gen();
493*cdf0e10cSrcweir 					aGen.Gen( _REDIMP_ERASE );
494*cdf0e10cSrcweir 				}
495*cdf0e10cSrcweir 				pDef->SetDims( pDim->GetDims() );
496*cdf0e10cSrcweir                 if( bPersistantGlobal )
497*cdf0e10cSrcweir                     pDef->SetGlobal( sal_True );
498*cdf0e10cSrcweir 				SbiExpression aExpr( this, *pDef, pDim );
499*cdf0e10cSrcweir 				aExpr.Gen();
500*cdf0e10cSrcweir                 pDef->SetGlobal( sal_False );
501*cdf0e10cSrcweir 				aGen.Gen( (eOp == _STATIC) ? _DIM : eOp );
502*cdf0e10cSrcweir 			}
503*cdf0e10cSrcweir 		}
504*cdf0e10cSrcweir 		if( !TestComma() )
505*cdf0e10cSrcweir 			goto MyBreak;	// AB 24.6.1996 (s.u.)
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 		// #27963# AB, 24.6.1996
508*cdf0e10cSrcweir 		// Einfuehrung bSwitchPool (s.o.): pPool darf beim VarDecl-Aufruf
509*cdf0e10cSrcweir 		// noch nicht auf &aGlobals gesetzt sein.
510*cdf0e10cSrcweir 		// Ansonsten soll das Verhalten aber absolut identisch bleiben,
511*cdf0e10cSrcweir 		// d.h. pPool muss immer am Schleifen-Ende zurueckgesetzt werden.
512*cdf0e10cSrcweir 		// auch bei break
513*cdf0e10cSrcweir 		pPool = pOldPool;
514*cdf0e10cSrcweir 		continue;		// MyBreak �berspingen
515*cdf0e10cSrcweir 	MyBreak:
516*cdf0e10cSrcweir 		pPool = pOldPool;
517*cdf0e10cSrcweir 		break;
518*cdf0e10cSrcweir 	}
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 	// AB 9.7.97, #40689, Sprung ueber Statics-Deklaration abschliessen
521*cdf0e10cSrcweir 	if( !bVBASupportOn && bStatic )
522*cdf0e10cSrcweir 	{
523*cdf0e10cSrcweir 		// globalen Chain pflegen
524*cdf0e10cSrcweir 		nGblChain = aGen.Gen( _JUMP, 0 );
525*cdf0e10cSrcweir 		bGblDefs = bNewGblDefs = sal_True;
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 		// fuer Sub Sprung auf Ende der statics eintragen
528*cdf0e10cSrcweir 		aGen.BackChain( nEndOfStaticLbl );
529*cdf0e10cSrcweir 	}
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir 	//pPool = pOldPool;
532*cdf0e10cSrcweir }
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir // Hier werden Arrays redimensioniert.
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir void SbiParser::ReDim()
537*cdf0e10cSrcweir {
538*cdf0e10cSrcweir 	DefVar( _REDIM, (  pProc && bVBASupportOn ) ? pProc->IsStatic() : sal_False );
539*cdf0e10cSrcweir }
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir // ERASE array, ...
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir void SbiParser::Erase()
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir 	while( !bAbort )
546*cdf0e10cSrcweir 	{
547*cdf0e10cSrcweir 		SbiExpression aExpr( this, SbLVALUE );
548*cdf0e10cSrcweir 		aExpr.Gen();
549*cdf0e10cSrcweir 		aGen.Gen( _ERASE );
550*cdf0e10cSrcweir 		if( !TestComma() ) break;
551*cdf0e10cSrcweir 	}
552*cdf0e10cSrcweir }
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir // Deklaration eines Datentyps
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir void SbiParser::Type()
557*cdf0e10cSrcweir {
558*cdf0e10cSrcweir 	DefType( sal_False );
559*cdf0e10cSrcweir }
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir void SbiParser::DefType( sal_Bool bPrivate )
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir 	// TODO: Use bPrivate
564*cdf0e10cSrcweir     (void)bPrivate;
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 	// Neues Token lesen, es muss ein Symbol sein
567*cdf0e10cSrcweir 	if (!TestSymbol())
568*cdf0e10cSrcweir 		return;
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir 	if (rTypeArray->Find(aSym,SbxCLASS_OBJECT))
571*cdf0e10cSrcweir 	{
572*cdf0e10cSrcweir 		Error( SbERR_VAR_DEFINED, aSym );
573*cdf0e10cSrcweir 		return;
574*cdf0e10cSrcweir 	}
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir 	SbxObject *pType = new SbxObject(aSym);
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir 	SbiSymDef* pElem;
579*cdf0e10cSrcweir 	SbiDimList* pDim = NULL;
580*cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir 	while( !bDone && !IsEof() )
583*cdf0e10cSrcweir 	{
584*cdf0e10cSrcweir 		switch( Peek() )
585*cdf0e10cSrcweir 		{
586*cdf0e10cSrcweir 			case ENDTYPE :
587*cdf0e10cSrcweir 				pElem = NULL;
588*cdf0e10cSrcweir 				bDone = sal_True;
589*cdf0e10cSrcweir 				Next();
590*cdf0e10cSrcweir 			break;
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir 			case EOLN :
593*cdf0e10cSrcweir 			case REM :
594*cdf0e10cSrcweir 				pElem = NULL;
595*cdf0e10cSrcweir 				Next();
596*cdf0e10cSrcweir 			break;
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir 			default:
599*cdf0e10cSrcweir 				pDim = NULL;
600*cdf0e10cSrcweir 				pElem = VarDecl(&pDim,sal_False,sal_False);
601*cdf0e10cSrcweir 				if( !pElem )
602*cdf0e10cSrcweir 					bDone = sal_True;	// Error occured
603*cdf0e10cSrcweir 		}
604*cdf0e10cSrcweir 		if( pElem )
605*cdf0e10cSrcweir 		{
606*cdf0e10cSrcweir 			SbxArray *pTypeMembers = pType->GetProperties();
607*cdf0e10cSrcweir 			String aElemName = pElem->GetName();
608*cdf0e10cSrcweir 			if( pTypeMembers->Find( aElemName, SbxCLASS_DONTCARE) )
609*cdf0e10cSrcweir 				Error (SbERR_VAR_DEFINED);
610*cdf0e10cSrcweir 			else
611*cdf0e10cSrcweir 			{
612*cdf0e10cSrcweir 				SbxDataType eElemType = pElem->GetType();
613*cdf0e10cSrcweir 				SbxProperty *pTypeElem = new SbxProperty( aElemName, eElemType );
614*cdf0e10cSrcweir 				if( pDim )
615*cdf0e10cSrcweir 				{
616*cdf0e10cSrcweir 					SbxDimArray* pArray = new SbxDimArray( pElem->GetType() );
617*cdf0e10cSrcweir 					if ( pDim->GetSize() )
618*cdf0e10cSrcweir 					{
619*cdf0e10cSrcweir 						// Dimension the target array
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 						for ( short i=0; i<pDim->GetSize();++i )
622*cdf0e10cSrcweir 						{
623*cdf0e10cSrcweir 							sal_Int32 ub = -1;
624*cdf0e10cSrcweir 							sal_Int32 lb = nBase;
625*cdf0e10cSrcweir 							SbiExprNode* pNode =  pDim->Get(i)->GetExprNode();
626*cdf0e10cSrcweir 							ub = pNode->GetNumber();
627*cdf0e10cSrcweir 							if ( !pDim->Get( i )->IsBased() ) // each dim is low/up
628*cdf0e10cSrcweir 							{
629*cdf0e10cSrcweir 								if (  ++i >= pDim->GetSize() ) // trouble
630*cdf0e10cSrcweir 									StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
631*cdf0e10cSrcweir 								pNode =  pDim->Get(i)->GetExprNode();
632*cdf0e10cSrcweir 								lb = ub;
633*cdf0e10cSrcweir 								ub = pNode->GetNumber();
634*cdf0e10cSrcweir 							}
635*cdf0e10cSrcweir 							else if ( !bCompatible )
636*cdf0e10cSrcweir 								ub += nBase;
637*cdf0e10cSrcweir 							pArray->AddDim32( lb, ub );
638*cdf0e10cSrcweir 						}
639*cdf0e10cSrcweir 						pArray->setHasFixedSize( true );
640*cdf0e10cSrcweir 					}
641*cdf0e10cSrcweir 					else
642*cdf0e10cSrcweir 						pArray->unoAddDim( 0, -1 ); // variant array
643*cdf0e10cSrcweir 					sal_uInt16 nSavFlags = pTypeElem->GetFlags();
644*cdf0e10cSrcweir 					// need to reset the FIXED flag
645*cdf0e10cSrcweir 					// when calling PutObject ( because the type will not match Object )
646*cdf0e10cSrcweir 					pTypeElem->ResetFlag( SBX_FIXED );
647*cdf0e10cSrcweir 					pTypeElem->PutObject( pArray );
648*cdf0e10cSrcweir 					pTypeElem->SetFlags( nSavFlags );
649*cdf0e10cSrcweir 				}
650*cdf0e10cSrcweir 				// Nested user type?
651*cdf0e10cSrcweir 				if( eElemType == SbxOBJECT )
652*cdf0e10cSrcweir 				{
653*cdf0e10cSrcweir 					sal_uInt16 nElemTypeId = pElem->GetTypeId();
654*cdf0e10cSrcweir 					if( nElemTypeId != 0 )
655*cdf0e10cSrcweir 					{
656*cdf0e10cSrcweir 						String aTypeName( aGblStrings.Find( nElemTypeId ) );
657*cdf0e10cSrcweir 						SbxObject* pTypeObj = static_cast< SbxObject* >( rTypeArray->Find( aTypeName, SbxCLASS_OBJECT ) );
658*cdf0e10cSrcweir 						if( pTypeObj != NULL )
659*cdf0e10cSrcweir 						{
660*cdf0e10cSrcweir 							SbxObject* pCloneObj = cloneTypeObjectImpl( *pTypeObj );
661*cdf0e10cSrcweir 							pTypeElem->PutObject( pCloneObj );
662*cdf0e10cSrcweir 						}
663*cdf0e10cSrcweir 					}
664*cdf0e10cSrcweir 				}
665*cdf0e10cSrcweir 				delete pDim;
666*cdf0e10cSrcweir 				pTypeMembers->Insert( pTypeElem, pTypeMembers->Count() );
667*cdf0e10cSrcweir 			}
668*cdf0e10cSrcweir 			delete pElem;
669*cdf0e10cSrcweir 		}
670*cdf0e10cSrcweir 	}
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir 	pType->Remove( XubString( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_DONTCARE );
673*cdf0e10cSrcweir 	pType->Remove( XubString( RTL_CONSTASCII_USTRINGPARAM("Parent") ), SbxCLASS_DONTCARE );
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir 	rTypeArray->Insert (pType,rTypeArray->Count());
676*cdf0e10cSrcweir }
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir // Declaration of Enum type
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir void SbiParser::Enum()
682*cdf0e10cSrcweir {
683*cdf0e10cSrcweir 	DefEnum( sal_False );
684*cdf0e10cSrcweir }
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir void SbiParser::DefEnum( sal_Bool bPrivate )
687*cdf0e10cSrcweir {
688*cdf0e10cSrcweir 	// Neues Token lesen, es muss ein Symbol sein
689*cdf0e10cSrcweir 	if (!TestSymbol())
690*cdf0e10cSrcweir 		return;
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir 	String aEnumName = aSym;
693*cdf0e10cSrcweir 	if( rEnumArray->Find(aEnumName,SbxCLASS_OBJECT) )
694*cdf0e10cSrcweir 	{
695*cdf0e10cSrcweir 		Error( SbERR_VAR_DEFINED, aSym );
696*cdf0e10cSrcweir 		return;
697*cdf0e10cSrcweir 	}
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir 	SbxObject *pEnum = new SbxObject( aEnumName );
700*cdf0e10cSrcweir 	if( bPrivate )
701*cdf0e10cSrcweir 		pEnum->SetFlag( SBX_PRIVATE );
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir 	SbiSymDef* pElem;
704*cdf0e10cSrcweir 	SbiDimList* pDim;
705*cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir 	// Starting with -1 to make first default value 0 after ++
708*cdf0e10cSrcweir 	sal_Int32 nCurrentEnumValue = -1;
709*cdf0e10cSrcweir 	while( !bDone && !IsEof() )
710*cdf0e10cSrcweir 	{
711*cdf0e10cSrcweir 		switch( Peek() )
712*cdf0e10cSrcweir 		{
713*cdf0e10cSrcweir 			case ENDENUM :
714*cdf0e10cSrcweir 				pElem = NULL;
715*cdf0e10cSrcweir 				bDone = sal_True;
716*cdf0e10cSrcweir 				Next();
717*cdf0e10cSrcweir 			break;
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir 			case EOLN :
720*cdf0e10cSrcweir 			case REM :
721*cdf0e10cSrcweir 				pElem = NULL;
722*cdf0e10cSrcweir 				Next();
723*cdf0e10cSrcweir 			break;
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir 			default:
726*cdf0e10cSrcweir 			{
727*cdf0e10cSrcweir 				// TODO: Check existing!
728*cdf0e10cSrcweir 				sal_Bool bDefined = sal_False;
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir 				pDim = NULL;
731*cdf0e10cSrcweir 				pElem = VarDecl( &pDim, sal_False, sal_True );
732*cdf0e10cSrcweir 				if( !pElem )
733*cdf0e10cSrcweir 				{
734*cdf0e10cSrcweir 					bDone = sal_True;	// Error occured
735*cdf0e10cSrcweir 					break;
736*cdf0e10cSrcweir 				}
737*cdf0e10cSrcweir 				else if( pDim )
738*cdf0e10cSrcweir 				{
739*cdf0e10cSrcweir 					delete pDim;
740*cdf0e10cSrcweir 					Error( SbERR_SYNTAX );
741*cdf0e10cSrcweir 					bDone = sal_True;	// Error occured
742*cdf0e10cSrcweir 					break;
743*cdf0e10cSrcweir 				}
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir 				SbiExpression aVar( this, *pElem );
746*cdf0e10cSrcweir 				if( Peek() == EQ )
747*cdf0e10cSrcweir 				{
748*cdf0e10cSrcweir 					Next();
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir 					SbiConstExpression aExpr( this );
751*cdf0e10cSrcweir 					if( !bDefined && aExpr.IsValid() )
752*cdf0e10cSrcweir 					{
753*cdf0e10cSrcweir 						SbxVariableRef xConvertVar = new SbxVariable();
754*cdf0e10cSrcweir 						if( aExpr.GetType() == SbxSTRING )
755*cdf0e10cSrcweir 							xConvertVar->PutString( aExpr.GetString() );
756*cdf0e10cSrcweir 						else
757*cdf0e10cSrcweir 							xConvertVar->PutDouble( aExpr.GetValue() );
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir 						nCurrentEnumValue = xConvertVar->GetLong();
760*cdf0e10cSrcweir 					}
761*cdf0e10cSrcweir 				}
762*cdf0e10cSrcweir 				else
763*cdf0e10cSrcweir 					nCurrentEnumValue++;
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir 				SbiSymPool* pPoolToUse = bPrivate ? pPool : &aGlobals;
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir 				SbiSymDef* pOld = pPoolToUse->Find( pElem->GetName() );
768*cdf0e10cSrcweir 				if( pOld )
769*cdf0e10cSrcweir 				{
770*cdf0e10cSrcweir 					Error( SbERR_VAR_DEFINED, pElem->GetName() );
771*cdf0e10cSrcweir 					bDone = sal_True;	// Error occured
772*cdf0e10cSrcweir 					break;
773*cdf0e10cSrcweir 				}
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir 				pPool->Add( pElem );
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir 				if( !bPrivate )
778*cdf0e10cSrcweir 				{
779*cdf0e10cSrcweir 					SbiOpcode eOp = _GLOBAL;
780*cdf0e10cSrcweir 					aGen.BackChain( nGblChain );
781*cdf0e10cSrcweir 					nGblChain = 0;
782*cdf0e10cSrcweir 					bGblDefs = bNewGblDefs = sal_True;
783*cdf0e10cSrcweir 					aGen.Gen(
784*cdf0e10cSrcweir                         eOp, pElem->GetId(),
785*cdf0e10cSrcweir                         sal::static_int_cast< sal_uInt16 >( pElem->GetType() ) );
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir 					aVar.Gen();
788*cdf0e10cSrcweir 					sal_uInt16 nStringId = aGen.GetParser()->aGblStrings.Add( nCurrentEnumValue, SbxLONG );
789*cdf0e10cSrcweir 					aGen.Gen( _NUMBER, nStringId );
790*cdf0e10cSrcweir 					aGen.Gen( _PUTC );
791*cdf0e10cSrcweir 				}
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir 				SbiConstDef* pConst = pElem->GetConstDef();
794*cdf0e10cSrcweir 				pConst->Set( nCurrentEnumValue, SbxLONG );
795*cdf0e10cSrcweir 			}
796*cdf0e10cSrcweir 		}
797*cdf0e10cSrcweir 		if( pElem )
798*cdf0e10cSrcweir 		{
799*cdf0e10cSrcweir 			SbxArray *pEnumMembers = pEnum->GetProperties();
800*cdf0e10cSrcweir 			SbxProperty *pEnumElem = new SbxProperty( pElem->GetName(), SbxLONG );
801*cdf0e10cSrcweir 			pEnumElem->PutLong( nCurrentEnumValue );
802*cdf0e10cSrcweir 			pEnumElem->ResetFlag( SBX_WRITE );
803*cdf0e10cSrcweir 			pEnumElem->SetFlag( SBX_CONST );
804*cdf0e10cSrcweir 			pEnumMembers->Insert( pEnumElem, pEnumMembers->Count() );
805*cdf0e10cSrcweir 		}
806*cdf0e10cSrcweir 	}
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir 	pEnum->Remove( XubString( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_DONTCARE );
809*cdf0e10cSrcweir 	pEnum->Remove( XubString( RTL_CONSTASCII_USTRINGPARAM("Parent") ), SbxCLASS_DONTCARE );
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir 	rEnumArray->Insert( pEnum, rEnumArray->Count() );
812*cdf0e10cSrcweir }
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir // Prozedur-Deklaration
816*cdf0e10cSrcweir // das erste Token ist bereits eingelesen (SUB/FUNCTION)
817*cdf0e10cSrcweir // xxx Name [LIB "name"[ALIAS "name"]][(Parameter)][AS TYPE]
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir SbiProcDef* SbiParser::ProcDecl( sal_Bool bDecl )
820*cdf0e10cSrcweir {
821*cdf0e10cSrcweir 	sal_Bool bFunc = sal_Bool( eCurTok == FUNCTION );
822*cdf0e10cSrcweir 	sal_Bool bProp = sal_Bool( eCurTok == GET || eCurTok == SET || eCurTok == LET );
823*cdf0e10cSrcweir 	if( !TestSymbol() ) return NULL;
824*cdf0e10cSrcweir 	String aName( aSym );
825*cdf0e10cSrcweir 	SbxDataType eType = eScanType;
826*cdf0e10cSrcweir 	SbiProcDef* pDef = new SbiProcDef( this, aName, true );
827*cdf0e10cSrcweir 	pDef->SetType( eType );
828*cdf0e10cSrcweir 	if( Peek() == _CDECL_ )
829*cdf0e10cSrcweir 	{
830*cdf0e10cSrcweir 		Next(); pDef->SetCdecl();
831*cdf0e10cSrcweir 	}
832*cdf0e10cSrcweir 	if( Peek() == LIB )
833*cdf0e10cSrcweir 	{
834*cdf0e10cSrcweir 		Next();
835*cdf0e10cSrcweir 		if( Next() == FIXSTRING )
836*cdf0e10cSrcweir 			pDef->GetLib() = aSym;
837*cdf0e10cSrcweir 		else
838*cdf0e10cSrcweir 			Error( SbERR_SYNTAX );
839*cdf0e10cSrcweir 	}
840*cdf0e10cSrcweir 	if( Peek() == ALIAS )
841*cdf0e10cSrcweir 	{
842*cdf0e10cSrcweir 		Next();
843*cdf0e10cSrcweir 		if( Next() == FIXSTRING )
844*cdf0e10cSrcweir 			pDef->GetAlias() = aSym;
845*cdf0e10cSrcweir 		else
846*cdf0e10cSrcweir 			Error( SbERR_SYNTAX );
847*cdf0e10cSrcweir 	}
848*cdf0e10cSrcweir 	if( !bDecl )
849*cdf0e10cSrcweir 	{
850*cdf0e10cSrcweir 		// CDECL, LIB und ALIAS sind unzulaessig
851*cdf0e10cSrcweir 		if( pDef->GetLib().Len() )
852*cdf0e10cSrcweir 			Error( SbERR_UNEXPECTED, LIB );
853*cdf0e10cSrcweir 		if( pDef->GetAlias().Len() )
854*cdf0e10cSrcweir 			Error( SbERR_UNEXPECTED, ALIAS );
855*cdf0e10cSrcweir 		if( pDef->IsCdecl() )
856*cdf0e10cSrcweir 			Error( SbERR_UNEXPECTED, _CDECL_ );
857*cdf0e10cSrcweir 		pDef->SetCdecl( sal_False );
858*cdf0e10cSrcweir 		pDef->GetLib().Erase();
859*cdf0e10cSrcweir 		pDef->GetAlias().Erase();
860*cdf0e10cSrcweir 	}
861*cdf0e10cSrcweir 	else if( !pDef->GetLib().Len() )
862*cdf0e10cSrcweir 	{
863*cdf0e10cSrcweir 		// ALIAS und CDECL nur zusammen mit LIB
864*cdf0e10cSrcweir 		if( pDef->GetAlias().Len() )
865*cdf0e10cSrcweir 			Error( SbERR_UNEXPECTED, ALIAS );
866*cdf0e10cSrcweir 		if( pDef->IsCdecl() )
867*cdf0e10cSrcweir 			Error( SbERR_UNEXPECTED, _CDECL_ );
868*cdf0e10cSrcweir 		pDef->SetCdecl( sal_False );
869*cdf0e10cSrcweir 		pDef->GetAlias().Erase();
870*cdf0e10cSrcweir 	}
871*cdf0e10cSrcweir 	// Klammern?
872*cdf0e10cSrcweir 	if( Peek() == LPAREN )
873*cdf0e10cSrcweir 	{
874*cdf0e10cSrcweir 		Next();
875*cdf0e10cSrcweir 		if( Peek() == RPAREN )
876*cdf0e10cSrcweir 			Next();
877*cdf0e10cSrcweir 		else
878*cdf0e10cSrcweir 		  for(;;) {
879*cdf0e10cSrcweir 			sal_Bool bByVal = sal_False;
880*cdf0e10cSrcweir 			sal_Bool bOptional = sal_False;
881*cdf0e10cSrcweir 			sal_Bool bParamArray = sal_False;
882*cdf0e10cSrcweir 			while( Peek() == BYVAL || Peek() == BYREF || Peek() == _OPTIONAL_ )
883*cdf0e10cSrcweir 			{
884*cdf0e10cSrcweir 				if		( Peek() == BYVAL )		Next(), bByVal = sal_True;
885*cdf0e10cSrcweir 				else if	( Peek() == BYREF )		Next(), bByVal = sal_False;
886*cdf0e10cSrcweir 				else if	( Peek() == _OPTIONAL_ )	Next(), bOptional = sal_True;
887*cdf0e10cSrcweir 			}
888*cdf0e10cSrcweir 			if( bCompatible && Peek() == PARAMARRAY )
889*cdf0e10cSrcweir 			{
890*cdf0e10cSrcweir 				if( bByVal || bOptional )
891*cdf0e10cSrcweir 					Error( SbERR_UNEXPECTED, PARAMARRAY );
892*cdf0e10cSrcweir 				Next();
893*cdf0e10cSrcweir 				bParamArray = sal_True;
894*cdf0e10cSrcweir 			}
895*cdf0e10cSrcweir 			SbiSymDef* pPar = VarDecl( NULL, sal_False, sal_False );
896*cdf0e10cSrcweir 			if( !pPar )
897*cdf0e10cSrcweir 				break;
898*cdf0e10cSrcweir 			if( bByVal )
899*cdf0e10cSrcweir 				pPar->SetByVal();
900*cdf0e10cSrcweir 			if( bOptional )
901*cdf0e10cSrcweir 				pPar->SetOptional();
902*cdf0e10cSrcweir 			if( bParamArray )
903*cdf0e10cSrcweir 				pPar->SetParamArray();
904*cdf0e10cSrcweir 			pDef->GetParams().Add( pPar );
905*cdf0e10cSrcweir 			SbiToken eTok = Next();
906*cdf0e10cSrcweir 			if( eTok != COMMA && eTok != RPAREN )
907*cdf0e10cSrcweir 			{
908*cdf0e10cSrcweir 				sal_Bool bError2 = sal_True;
909*cdf0e10cSrcweir 				if( bOptional && bCompatible && eTok == EQ )
910*cdf0e10cSrcweir 				{
911*cdf0e10cSrcweir 					SbiConstExpression* pDefaultExpr = new SbiConstExpression( this );
912*cdf0e10cSrcweir 					SbxDataType eType2 = pDefaultExpr->GetType();
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir 					sal_uInt16 nStringId;
915*cdf0e10cSrcweir 					if( eType2 == SbxSTRING )
916*cdf0e10cSrcweir 						nStringId = aGblStrings.Add( pDefaultExpr->GetString() );
917*cdf0e10cSrcweir 					else
918*cdf0e10cSrcweir 						nStringId = aGblStrings.Add( pDefaultExpr->GetValue(), eType2 );
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir 					pPar->SetDefaultId( nStringId );
921*cdf0e10cSrcweir 					delete pDefaultExpr;
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir 					eTok = Next();
924*cdf0e10cSrcweir 					if( eTok == COMMA || eTok == RPAREN )
925*cdf0e10cSrcweir 						bError2 = sal_False;
926*cdf0e10cSrcweir 				}
927*cdf0e10cSrcweir 				if( bError2 )
928*cdf0e10cSrcweir 				{
929*cdf0e10cSrcweir 					Error( SbERR_EXPECTED, RPAREN );
930*cdf0e10cSrcweir 					break;
931*cdf0e10cSrcweir 				}
932*cdf0e10cSrcweir 			}
933*cdf0e10cSrcweir 			if( eTok == RPAREN )
934*cdf0e10cSrcweir 				break;
935*cdf0e10cSrcweir 		}
936*cdf0e10cSrcweir 	}
937*cdf0e10cSrcweir 	TypeDecl( *pDef );
938*cdf0e10cSrcweir 	if( eType != SbxVARIANT && pDef->GetType() != eType )
939*cdf0e10cSrcweir 		Error( SbERR_BAD_DECLARATION, aName );
940*cdf0e10cSrcweir //	if( pDef->GetType() == SbxOBJECT )
941*cdf0e10cSrcweir //		pDef->SetType( SbxVARIANT ),
942*cdf0e10cSrcweir //		Error( SbERR_SYNTAX );
943*cdf0e10cSrcweir 	if( pDef->GetType() == SbxVARIANT && !( bFunc || bProp ) )
944*cdf0e10cSrcweir 		pDef->SetType( SbxEMPTY );
945*cdf0e10cSrcweir 	return pDef;
946*cdf0e10cSrcweir }
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir // DECLARE
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir void SbiParser::Declare()
951*cdf0e10cSrcweir {
952*cdf0e10cSrcweir 	DefDeclare( sal_False );
953*cdf0e10cSrcweir }
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir void SbiParser::DefDeclare( sal_Bool bPrivate )
956*cdf0e10cSrcweir {
957*cdf0e10cSrcweir 	Next();
958*cdf0e10cSrcweir 	if( eCurTok != SUB && eCurTok != FUNCTION )
959*cdf0e10cSrcweir 	  Error( SbERR_UNEXPECTED, eCurTok );
960*cdf0e10cSrcweir 	else
961*cdf0e10cSrcweir 	{
962*cdf0e10cSrcweir 		bool bFunction = (eCurTok == FUNCTION);
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir 		SbiProcDef* pDef = ProcDecl( sal_True );
965*cdf0e10cSrcweir 		if( pDef )
966*cdf0e10cSrcweir 		{
967*cdf0e10cSrcweir 			if( !pDef->GetLib().Len() )
968*cdf0e10cSrcweir 				Error( SbERR_EXPECTED, LIB );
969*cdf0e10cSrcweir 			// gibts den schon?
970*cdf0e10cSrcweir 			SbiSymDef* pOld = aPublics.Find( pDef->GetName() );
971*cdf0e10cSrcweir 			if( pOld )
972*cdf0e10cSrcweir 			{
973*cdf0e10cSrcweir 				SbiProcDef* p = pOld->GetProcDef();
974*cdf0e10cSrcweir 				if( !p )
975*cdf0e10cSrcweir 				{
976*cdf0e10cSrcweir 					// Als Variable deklariert
977*cdf0e10cSrcweir 					Error( SbERR_BAD_DECLARATION, pDef->GetName() );
978*cdf0e10cSrcweir 					delete pDef;
979*cdf0e10cSrcweir 					pDef = NULL;
980*cdf0e10cSrcweir 				}
981*cdf0e10cSrcweir 				else
982*cdf0e10cSrcweir 					pDef->Match( p );
983*cdf0e10cSrcweir 			}
984*cdf0e10cSrcweir 			else
985*cdf0e10cSrcweir 				aPublics.Add( pDef );
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir 			if ( pDef )
988*cdf0e10cSrcweir 			{
989*cdf0e10cSrcweir 				pDef->SetPublic( !bPrivate );
990*cdf0e10cSrcweir 
991*cdf0e10cSrcweir 				// New declare handling
992*cdf0e10cSrcweir 				if( pDef->GetLib().Len() > 0 )
993*cdf0e10cSrcweir 				{
994*cdf0e10cSrcweir 					if( bNewGblDefs && nGblChain == 0 )
995*cdf0e10cSrcweir 					{
996*cdf0e10cSrcweir 						nGblChain = aGen.Gen( _JUMP, 0 );
997*cdf0e10cSrcweir 						bNewGblDefs = sal_False;
998*cdf0e10cSrcweir 					}
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir 					sal_uInt16 nSavLine = nLine;
1001*cdf0e10cSrcweir 					aGen.Statement();
1002*cdf0e10cSrcweir 					pDef->Define();
1003*cdf0e10cSrcweir 					pDef->SetLine1( nSavLine );
1004*cdf0e10cSrcweir 					pDef->SetLine2( nSavLine );
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir 					SbiSymPool& rPool = pDef->GetParams();
1007*cdf0e10cSrcweir 					sal_uInt16 nParCount = rPool.GetSize();
1008*cdf0e10cSrcweir 
1009*cdf0e10cSrcweir 					SbxDataType eType = pDef->GetType();
1010*cdf0e10cSrcweir 					if( bFunction )
1011*cdf0e10cSrcweir 						aGen.Gen( _PARAM, 0, sal::static_int_cast< sal_uInt16 >( eType ) );
1012*cdf0e10cSrcweir 
1013*cdf0e10cSrcweir 					if( nParCount > 1 )
1014*cdf0e10cSrcweir 					{
1015*cdf0e10cSrcweir 						aGen.Gen( _ARGC );
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir 						for( sal_uInt16 i = 1 ; i < nParCount ; ++i )
1018*cdf0e10cSrcweir 						{
1019*cdf0e10cSrcweir 							SbiSymDef* pParDef = rPool.Get( i );
1020*cdf0e10cSrcweir 							SbxDataType eParType = pParDef->GetType();
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir 							aGen.Gen( _PARAM, i, sal::static_int_cast< sal_uInt16 >( eParType ) );
1023*cdf0e10cSrcweir 							aGen.Gen( _ARGV );
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir 							sal_uInt16 nTyp = sal::static_int_cast< sal_uInt16 >( pParDef->GetType() );
1026*cdf0e10cSrcweir 							if( pParDef->IsByVal() )
1027*cdf0e10cSrcweir 							{
1028*cdf0e10cSrcweir 								// Reset to avoid additional byval in call to wrapper function
1029*cdf0e10cSrcweir 								pParDef->SetByVal( sal_False );
1030*cdf0e10cSrcweir 								nTyp |= 0x8000;
1031*cdf0e10cSrcweir 							}
1032*cdf0e10cSrcweir 							aGen.Gen( _ARGTYP, nTyp );
1033*cdf0e10cSrcweir 						}
1034*cdf0e10cSrcweir 					}
1035*cdf0e10cSrcweir 
1036*cdf0e10cSrcweir 					aGen.Gen( _LIB, aGblStrings.Add( pDef->GetLib() ) );
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir 					SbiOpcode eOp = pDef->IsCdecl() ? _CALLC : _CALL;
1039*cdf0e10cSrcweir 					sal_uInt16 nId = pDef->GetId();
1040*cdf0e10cSrcweir 					if( pDef->GetAlias().Len() )
1041*cdf0e10cSrcweir 						nId = ( nId & 0x8000 ) | aGblStrings.Add( pDef->GetAlias() );
1042*cdf0e10cSrcweir 					if( nParCount > 1 )
1043*cdf0e10cSrcweir 						nId |= 0x8000;
1044*cdf0e10cSrcweir 					aGen.Gen( eOp, nId, sal::static_int_cast< sal_uInt16 >( eType ) );
1045*cdf0e10cSrcweir 
1046*cdf0e10cSrcweir 					if( bFunction )
1047*cdf0e10cSrcweir 						aGen.Gen( _PUT );
1048*cdf0e10cSrcweir 
1049*cdf0e10cSrcweir 					aGen.Gen( _LEAVE );
1050*cdf0e10cSrcweir 				}
1051*cdf0e10cSrcweir 			}
1052*cdf0e10cSrcweir 		}
1053*cdf0e10cSrcweir 	}
1054*cdf0e10cSrcweir }
1055*cdf0e10cSrcweir 
1056*cdf0e10cSrcweir // Aufruf einer SUB oder FUNCTION
1057*cdf0e10cSrcweir 
1058*cdf0e10cSrcweir void SbiParser::Call()
1059*cdf0e10cSrcweir {
1060*cdf0e10cSrcweir 	String aName( aSym );
1061*cdf0e10cSrcweir 	SbiExpression aVar( this, SbSYMBOL );
1062*cdf0e10cSrcweir 	aVar.Gen( FORCE_CALL );
1063*cdf0e10cSrcweir 	aGen.Gen( _GET );
1064*cdf0e10cSrcweir }
1065*cdf0e10cSrcweir 
1066*cdf0e10cSrcweir // SUB/FUNCTION
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir void SbiParser::SubFunc()
1069*cdf0e10cSrcweir {
1070*cdf0e10cSrcweir 	DefProc( sal_False, sal_False );
1071*cdf0e10cSrcweir }
1072*cdf0e10cSrcweir 
1073*cdf0e10cSrcweir // Einlesen einer Prozedur
1074*cdf0e10cSrcweir 
1075*cdf0e10cSrcweir sal_Bool runsInSetup( void );
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir void SbiParser::DefProc( sal_Bool bStatic, sal_Bool bPrivate )
1078*cdf0e10cSrcweir {
1079*cdf0e10cSrcweir 	sal_uInt16 l1 = nLine, l2 = nLine;
1080*cdf0e10cSrcweir 	sal_Bool bSub = sal_Bool( eCurTok == SUB );
1081*cdf0e10cSrcweir 	sal_Bool bProperty = sal_Bool( eCurTok == PROPERTY );
1082*cdf0e10cSrcweir 	PropertyMode ePropertyMode = PROPERTY_MODE_NONE;
1083*cdf0e10cSrcweir 	if( bProperty )
1084*cdf0e10cSrcweir 	{
1085*cdf0e10cSrcweir 		Next();
1086*cdf0e10cSrcweir 		if( eCurTok == GET )
1087*cdf0e10cSrcweir 			ePropertyMode = PROPERTY_MODE_GET;
1088*cdf0e10cSrcweir 		else if( eCurTok == LET )
1089*cdf0e10cSrcweir 			ePropertyMode = PROPERTY_MODE_LET;
1090*cdf0e10cSrcweir 		else if( eCurTok == SET )
1091*cdf0e10cSrcweir 			ePropertyMode = PROPERTY_MODE_SET;
1092*cdf0e10cSrcweir 		else
1093*cdf0e10cSrcweir 			Error( SbERR_EXPECTED, "Get or Let or Set" );
1094*cdf0e10cSrcweir 	}
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir 	SbiToken eExit = eCurTok;
1097*cdf0e10cSrcweir 	SbiProcDef* pDef = ProcDecl( sal_False );
1098*cdf0e10cSrcweir 	if( !pDef )
1099*cdf0e10cSrcweir 		return;
1100*cdf0e10cSrcweir 	pDef->setPropertyMode( ePropertyMode );
1101*cdf0e10cSrcweir 
1102*cdf0e10cSrcweir 	// Ist die Proc bereits deklariert?
1103*cdf0e10cSrcweir 	SbiSymDef* pOld = aPublics.Find( pDef->GetName() );
1104*cdf0e10cSrcweir 	if( pOld )
1105*cdf0e10cSrcweir 	{
1106*cdf0e10cSrcweir 		bool bError_ = false;
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir 		pProc = pOld->GetProcDef();
1109*cdf0e10cSrcweir 		if( !pProc )
1110*cdf0e10cSrcweir 		{
1111*cdf0e10cSrcweir 			// Als Variable deklariert
1112*cdf0e10cSrcweir 			Error( SbERR_BAD_DECLARATION, pDef->GetName() );
1113*cdf0e10cSrcweir 			delete pDef;
1114*cdf0e10cSrcweir 			pProc = NULL;
1115*cdf0e10cSrcweir 			bError_ = true;
1116*cdf0e10cSrcweir 		}
1117*cdf0e10cSrcweir 		// #100027: Multiple declaration -> Error
1118*cdf0e10cSrcweir 		// #112787: Not for setup, REMOVE for 8
1119*cdf0e10cSrcweir 		else if( !runsInSetup() && pProc->IsUsedForProcDecl() )
1120*cdf0e10cSrcweir 		{
1121*cdf0e10cSrcweir 			PropertyMode ePropMode = pDef->getPropertyMode();
1122*cdf0e10cSrcweir 			if( ePropMode == PROPERTY_MODE_NONE || ePropMode == pProc->getPropertyMode() )
1123*cdf0e10cSrcweir 			{
1124*cdf0e10cSrcweir 				Error( SbERR_PROC_DEFINED, pDef->GetName() );
1125*cdf0e10cSrcweir 				delete pDef;
1126*cdf0e10cSrcweir 				pProc = NULL;
1127*cdf0e10cSrcweir 				bError_ = true;
1128*cdf0e10cSrcweir 			}
1129*cdf0e10cSrcweir 		}
1130*cdf0e10cSrcweir 
1131*cdf0e10cSrcweir 		if( !bError_ )
1132*cdf0e10cSrcweir 		{
1133*cdf0e10cSrcweir 			pDef->Match( pProc );
1134*cdf0e10cSrcweir 			pProc = pDef;
1135*cdf0e10cSrcweir 		}
1136*cdf0e10cSrcweir 	}
1137*cdf0e10cSrcweir 	else
1138*cdf0e10cSrcweir 		aPublics.Add( pDef ), pProc = pDef;
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir 	if( !pProc )
1141*cdf0e10cSrcweir 		return;
1142*cdf0e10cSrcweir 	pProc->SetPublic( !bPrivate );
1143*cdf0e10cSrcweir 
1144*cdf0e10cSrcweir 	// Nun setzen wir die Suchhierarchie fuer Symbole sowie die aktuelle
1145*cdf0e10cSrcweir 	// Prozedur.
1146*cdf0e10cSrcweir 	aPublics.SetProcId( pProc->GetId() );
1147*cdf0e10cSrcweir 	pProc->GetParams().SetParent( &aPublics );
1148*cdf0e10cSrcweir 	if( bStatic )
1149*cdf0e10cSrcweir         {
1150*cdf0e10cSrcweir 		if ( bVBASupportOn )
1151*cdf0e10cSrcweir 			pProc->SetStatic( sal_True );
1152*cdf0e10cSrcweir 		else
1153*cdf0e10cSrcweir 			Error( SbERR_NOT_IMPLEMENTED ); // STATIC SUB ...
1154*cdf0e10cSrcweir         }
1155*cdf0e10cSrcweir  	else
1156*cdf0e10cSrcweir 	{
1157*cdf0e10cSrcweir 		pProc->SetStatic( sal_False );
1158*cdf0e10cSrcweir         }
1159*cdf0e10cSrcweir 	// Normalfall: Lokale Variable->Parameter->Globale Variable
1160*cdf0e10cSrcweir 	pProc->GetLocals().SetParent( &pProc->GetParams() );
1161*cdf0e10cSrcweir 	pPool = &pProc->GetLocals();
1162*cdf0e10cSrcweir 
1163*cdf0e10cSrcweir 	pProc->Define();
1164*cdf0e10cSrcweir 	OpenBlock( eExit );
1165*cdf0e10cSrcweir 	StmntBlock( bSub ? ENDSUB : (bProperty ? ENDPROPERTY : ENDFUNC) );
1166*cdf0e10cSrcweir 	l2 = nLine;
1167*cdf0e10cSrcweir 	pProc->SetLine1( l1 );
1168*cdf0e10cSrcweir 	pProc->SetLine2( l2 );
1169*cdf0e10cSrcweir 	pPool = &aPublics;
1170*cdf0e10cSrcweir 	aPublics.SetProcId( 0 );
1171*cdf0e10cSrcweir 	// Offene Labels?
1172*cdf0e10cSrcweir 	pProc->GetLabels().CheckRefs();
1173*cdf0e10cSrcweir 	CloseBlock();
1174*cdf0e10cSrcweir 	aGen.Gen( _LEAVE );
1175*cdf0e10cSrcweir 	pProc = NULL;
1176*cdf0e10cSrcweir }
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir // STATIC variable|procedure
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir void SbiParser::Static()
1181*cdf0e10cSrcweir {
1182*cdf0e10cSrcweir 	DefStatic( sal_False );
1183*cdf0e10cSrcweir }
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir void SbiParser::DefStatic( sal_Bool bPrivate )
1186*cdf0e10cSrcweir {
1187*cdf0e10cSrcweir 	switch( Peek() )
1188*cdf0e10cSrcweir 	{
1189*cdf0e10cSrcweir 		case SUB:
1190*cdf0e10cSrcweir 		case FUNCTION:
1191*cdf0e10cSrcweir 		case PROPERTY:
1192*cdf0e10cSrcweir 			// End global chain if necessary (not done in
1193*cdf0e10cSrcweir 			// SbiParser::Parse() under these conditions
1194*cdf0e10cSrcweir 			if( bNewGblDefs && nGblChain == 0 )
1195*cdf0e10cSrcweir 			{
1196*cdf0e10cSrcweir 				nGblChain = aGen.Gen( _JUMP, 0 );
1197*cdf0e10cSrcweir 				bNewGblDefs = sal_False;
1198*cdf0e10cSrcweir 			}
1199*cdf0e10cSrcweir 			Next();
1200*cdf0e10cSrcweir 			DefProc( sal_True, bPrivate );
1201*cdf0e10cSrcweir 			break;
1202*cdf0e10cSrcweir 		default: {
1203*cdf0e10cSrcweir 			if( !pProc )
1204*cdf0e10cSrcweir 				Error( SbERR_NOT_IN_SUBR );
1205*cdf0e10cSrcweir 			// Pool umsetzen, damit STATIC-Deklarationen im globalen
1206*cdf0e10cSrcweir 			// Pool landen
1207*cdf0e10cSrcweir 			SbiSymPool* p = pPool; pPool = &aPublics;
1208*cdf0e10cSrcweir 			DefVar( _STATIC, sal_True );
1209*cdf0e10cSrcweir 			pPool = p;
1210*cdf0e10cSrcweir 			} break;
1211*cdf0e10cSrcweir 	}
1212*cdf0e10cSrcweir }
1213*cdf0e10cSrcweir 
1214