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