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