xref: /AOO41X/main/basic/source/runtime/step1.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_basic.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <stdlib.h>
32*cdf0e10cSrcweir #include <rtl/math.hxx>
33*cdf0e10cSrcweir #include <basic/sbuno.hxx>
34*cdf0e10cSrcweir #include "runtime.hxx"
35*cdf0e10cSrcweir #include "sbintern.hxx"
36*cdf0e10cSrcweir #include "iosys.hxx"
37*cdf0e10cSrcweir #include "image.hxx"
38*cdf0e10cSrcweir #include "sbunoobj.hxx"
39*cdf0e10cSrcweir #include "errobject.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir bool checkUnoObjectType( SbUnoObject* refVal, const ::rtl::OUString& aClass );
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir // Laden einer numerischen Konstanten (+ID)
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir void SbiRuntime::StepLOADNC( sal_uInt32 nOp1 )
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir 	SbxVariable* p = new SbxVariable( SbxDOUBLE );
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 	// #57844 Lokalisierte Funktion benutzen
50*cdf0e10cSrcweir 	String aStr = pImg->GetString( static_cast<short>( nOp1 ) );
51*cdf0e10cSrcweir 	// Auch , zulassen !!!
52*cdf0e10cSrcweir 	sal_uInt16 iComma = aStr.Search( ',' );
53*cdf0e10cSrcweir 	if( iComma != STRING_NOTFOUND )
54*cdf0e10cSrcweir 	{
55*cdf0e10cSrcweir 		String aStr1 = aStr.Copy( 0, iComma );
56*cdf0e10cSrcweir 		String aStr2 = aStr.Copy( iComma + 1 );
57*cdf0e10cSrcweir 		aStr = aStr1;
58*cdf0e10cSrcweir 		aStr += '.';
59*cdf0e10cSrcweir 		aStr += aStr2;
60*cdf0e10cSrcweir 	}
61*cdf0e10cSrcweir     double n = ::rtl::math::stringToDouble( aStr, '.', ',', NULL, NULL );
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 	p->PutDouble( n );
64*cdf0e10cSrcweir 	PushVar( p );
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir // Laden einer Stringkonstanten (+ID)
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir void SbiRuntime::StepLOADSC( sal_uInt32 nOp1 )
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 	SbxVariable* p = new SbxVariable;
72*cdf0e10cSrcweir 	p->PutString( pImg->GetString( static_cast<short>( nOp1 ) ) );
73*cdf0e10cSrcweir 	PushVar( p );
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir // Immediate Load (+Wert)
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir void SbiRuntime::StepLOADI( sal_uInt32 nOp1 )
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	SbxVariable* p = new SbxVariable;
81*cdf0e10cSrcweir 	p->PutInteger( static_cast<sal_Int16>( nOp1 ) );
82*cdf0e10cSrcweir 	PushVar( p );
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir // Speichern eines named Arguments in Argv (+Arg-Nr ab 1!)
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir void SbiRuntime::StepARGN( sal_uInt32 nOp1 )
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	if( !refArgv )
90*cdf0e10cSrcweir 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
91*cdf0e10cSrcweir 	else
92*cdf0e10cSrcweir 	{
93*cdf0e10cSrcweir 		String aAlias( pImg->GetString( static_cast<short>( nOp1 ) ) );
94*cdf0e10cSrcweir 		SbxVariableRef pVal = PopVar();
95*cdf0e10cSrcweir 		refArgv->Put( pVal, nArgc );
96*cdf0e10cSrcweir 		refArgv->PutAlias( aAlias, nArgc++ );
97*cdf0e10cSrcweir 	}
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir // Konvertierung des Typs eines Arguments in Argv fuer DECLARE-Fkt. (+Typ)
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir void SbiRuntime::StepARGTYP( sal_uInt32 nOp1 )
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 	if( !refArgv )
105*cdf0e10cSrcweir 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
106*cdf0e10cSrcweir 	else
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir 		sal_Bool bByVal = (nOp1 & 0x8000) != 0;			// Ist BYVAL verlangt?
109*cdf0e10cSrcweir 		SbxDataType t = (SbxDataType) (nOp1 & 0x7FFF);
110*cdf0e10cSrcweir 		SbxVariable* pVar = refArgv->Get( refArgv->Count() - 1 );	// letztes Arg
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 		// BYVAL pr�fen
113*cdf0e10cSrcweir 		if( pVar->GetRefCount() > 2 )		// 2 ist normal f�r BYVAL
114*cdf0e10cSrcweir 		{
115*cdf0e10cSrcweir 			// Parameter ist eine Referenz
116*cdf0e10cSrcweir 			if( bByVal )
117*cdf0e10cSrcweir 			{
118*cdf0e10cSrcweir 				// Call by Value ist verlangt -> Kopie anlegen
119*cdf0e10cSrcweir 				pVar = new SbxVariable( *pVar );
120*cdf0e10cSrcweir 				pVar->SetFlag( SBX_READWRITE );
121*cdf0e10cSrcweir 				refExprStk->Put( pVar, refArgv->Count() - 1 );
122*cdf0e10cSrcweir 			}
123*cdf0e10cSrcweir 			else
124*cdf0e10cSrcweir 				pVar->SetFlag( SBX_REFERENCE );		// Ref-Flag f�r DllMgr
125*cdf0e10cSrcweir 		}
126*cdf0e10cSrcweir 		else
127*cdf0e10cSrcweir 		{
128*cdf0e10cSrcweir 			// Parameter ist KEINE Referenz
129*cdf0e10cSrcweir 			if( bByVal )
130*cdf0e10cSrcweir 				pVar->ResetFlag( SBX_REFERENCE );	// Keine Referenz -> OK
131*cdf0e10cSrcweir 			else
132*cdf0e10cSrcweir 				Error( SbERR_BAD_PARAMETERS );		// Referenz verlangt
133*cdf0e10cSrcweir 		}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 		if( pVar->GetType() != t )
136*cdf0e10cSrcweir 		{
137*cdf0e10cSrcweir 			// Variant, damit richtige Konvertierung
138*cdf0e10cSrcweir 			// Ausserdem Fehler, wenn SbxBYREF
139*cdf0e10cSrcweir 			pVar->Convert( SbxVARIANT );
140*cdf0e10cSrcweir 			pVar->Convert( t );
141*cdf0e10cSrcweir 		}
142*cdf0e10cSrcweir 	}
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir // String auf feste Laenge bringen (+Laenge)
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir void SbiRuntime::StepPAD( sal_uInt32 nOp1 )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	SbxVariable* p = GetTOS();
150*cdf0e10cSrcweir 	String& s = (String&)(const String&) *p;
151*cdf0e10cSrcweir 	if( s.Len() > nOp1 )
152*cdf0e10cSrcweir 		s.Erase( static_cast<xub_StrLen>( nOp1 ) );
153*cdf0e10cSrcweir 	else
154*cdf0e10cSrcweir 		s.Expand( static_cast<xub_StrLen>( nOp1 ), ' ' );
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir // Sprung (+Target)
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir void SbiRuntime::StepJUMP( sal_uInt32 nOp1 )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir #ifdef DBG_UTIL
162*cdf0e10cSrcweir 	// #QUESTION shouln't this be
163*cdf0e10cSrcweir 	// if( (sal_uInt8*)( nOp1+pImagGetCode() ) >= pImg->GetCodeSize() )
164*cdf0e10cSrcweir 	if( nOp1 >= pImg->GetCodeSize() )
165*cdf0e10cSrcweir 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
166*cdf0e10cSrcweir #endif
167*cdf0e10cSrcweir 	pCode = (const sal_uInt8*) pImg->GetCode() + nOp1;
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir // TOS auswerten, bedingter Sprung (+Target)
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir void SbiRuntime::StepJUMPT( sal_uInt32 nOp1 )
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir 	SbxVariableRef p = PopVar();
175*cdf0e10cSrcweir 	if( p->GetBool() )
176*cdf0e10cSrcweir 		StepJUMP( nOp1 );
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir // TOS auswerten, bedingter Sprung (+Target)
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir void SbiRuntime::StepJUMPF( sal_uInt32 nOp1 )
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir 	SbxVariableRef p = PopVar();
184*cdf0e10cSrcweir 	if( !p->GetBool() )
185*cdf0e10cSrcweir 		StepJUMP( nOp1 );
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir // TOS auswerten, Sprung in JUMP-Tabelle (+MaxVal)
189*cdf0e10cSrcweir // Sieht so aus:
190*cdf0e10cSrcweir // ONJUMP 2
191*cdf0e10cSrcweir // JUMP target1
192*cdf0e10cSrcweir // JUMP target2
193*cdf0e10cSrcweir // ...
194*cdf0e10cSrcweir //Falls im Operanden 0x8000 gesetzt ist, Returnadresse pushen (ON..GOSUB)
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir void SbiRuntime::StepONJUMP( sal_uInt32 nOp1 )
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir 	SbxVariableRef p = PopVar();
199*cdf0e10cSrcweir 	sal_Int16 n = p->GetInteger();
200*cdf0e10cSrcweir 	if( nOp1 & 0x8000 )
201*cdf0e10cSrcweir 	{
202*cdf0e10cSrcweir 		nOp1 &= 0x7FFF;
203*cdf0e10cSrcweir 		//PushGosub( pCode + 3 * nOp1 );
204*cdf0e10cSrcweir 		PushGosub( pCode + 5 * nOp1 );
205*cdf0e10cSrcweir 	}
206*cdf0e10cSrcweir 	if( n < 1 || static_cast<sal_uInt32>(n) > nOp1 )
207*cdf0e10cSrcweir 		n = static_cast<sal_Int16>( nOp1 + 1 );
208*cdf0e10cSrcweir 	//nOp1 = (sal_uInt32) ( (const char*) pCode - pImg->GetCode() ) + 3 * --n;
209*cdf0e10cSrcweir 	nOp1 = (sal_uInt32) ( (const char*) pCode - pImg->GetCode() ) + 5 * --n;
210*cdf0e10cSrcweir 	StepJUMP( nOp1 );
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir // UP-Aufruf (+Target)
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir void SbiRuntime::StepGOSUB( sal_uInt32 nOp1 )
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	PushGosub( pCode );
218*cdf0e10cSrcweir 	if( nOp1 >= pImg->GetCodeSize() )
219*cdf0e10cSrcweir 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
220*cdf0e10cSrcweir 	pCode = (const sal_uInt8*) pImg->GetCode() + nOp1;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir // UP-Return (+0 oder Target)
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir void SbiRuntime::StepRETURN( sal_uInt32 nOp1 )
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir 	PopGosub();
228*cdf0e10cSrcweir 	if( nOp1 )
229*cdf0e10cSrcweir 		StepJUMP( nOp1 );
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir // FOR-Variable testen (+Endlabel)
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir void SbiRuntime::StepTESTFOR( sal_uInt32 nOp1 )
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir 	if( !pForStk )
237*cdf0e10cSrcweir 	{
238*cdf0e10cSrcweir 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
239*cdf0e10cSrcweir 		return;
240*cdf0e10cSrcweir 	}
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 	bool bEndLoop = false;
243*cdf0e10cSrcweir 	switch( pForStk->eForType )
244*cdf0e10cSrcweir 	{
245*cdf0e10cSrcweir 		case FOR_TO:
246*cdf0e10cSrcweir 		{
247*cdf0e10cSrcweir 			SbxOperator eOp = ( pForStk->refInc->GetDouble() < 0 ) ? SbxLT : SbxGT;
248*cdf0e10cSrcweir 			if( pForStk->refVar->Compare( eOp, *pForStk->refEnd ) )
249*cdf0e10cSrcweir 				bEndLoop = true;
250*cdf0e10cSrcweir 			break;
251*cdf0e10cSrcweir 		}
252*cdf0e10cSrcweir 		case FOR_EACH_ARRAY:
253*cdf0e10cSrcweir 		{
254*cdf0e10cSrcweir 			SbiForStack* p = pForStk;
255*cdf0e10cSrcweir 			if( p->pArrayCurIndices == NULL )
256*cdf0e10cSrcweir 			{
257*cdf0e10cSrcweir 				bEndLoop = true;
258*cdf0e10cSrcweir 			}
259*cdf0e10cSrcweir 			else
260*cdf0e10cSrcweir 			{
261*cdf0e10cSrcweir 				SbxDimArray* pArray = (SbxDimArray*)(SbxVariable*)p->refEnd;
262*cdf0e10cSrcweir 				short nDims = pArray->GetDims();
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 				// Empty array?
265*cdf0e10cSrcweir 				if( nDims == 1 && p->pArrayLowerBounds[0] > p->pArrayUpperBounds[0] )
266*cdf0e10cSrcweir 				{
267*cdf0e10cSrcweir 					bEndLoop = true;
268*cdf0e10cSrcweir 					break;
269*cdf0e10cSrcweir 				}
270*cdf0e10cSrcweir 				SbxVariable* pVal = pArray->Get32( p->pArrayCurIndices );
271*cdf0e10cSrcweir 				*(p->refVar) = *pVal;
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 				bool bFoundNext = false;
274*cdf0e10cSrcweir 				for( short i = 0 ; i < nDims ; i++ )
275*cdf0e10cSrcweir 				{
276*cdf0e10cSrcweir 					if( p->pArrayCurIndices[i] < p->pArrayUpperBounds[i] )
277*cdf0e10cSrcweir 					{
278*cdf0e10cSrcweir 						bFoundNext = true;
279*cdf0e10cSrcweir 						p->pArrayCurIndices[i]++;
280*cdf0e10cSrcweir 						for( short j = i - 1 ; j >= 0 ; j-- )
281*cdf0e10cSrcweir 							p->pArrayCurIndices[j] = p->pArrayLowerBounds[j];
282*cdf0e10cSrcweir 						break;
283*cdf0e10cSrcweir 					}
284*cdf0e10cSrcweir 				}
285*cdf0e10cSrcweir 				if( !bFoundNext )
286*cdf0e10cSrcweir 				{
287*cdf0e10cSrcweir 					delete[] p->pArrayCurIndices;
288*cdf0e10cSrcweir 					p->pArrayCurIndices = NULL;
289*cdf0e10cSrcweir 				}
290*cdf0e10cSrcweir 			}
291*cdf0e10cSrcweir 			break;
292*cdf0e10cSrcweir 		}
293*cdf0e10cSrcweir 		case FOR_EACH_COLLECTION:
294*cdf0e10cSrcweir 		{
295*cdf0e10cSrcweir 			BasicCollection* pCollection = (BasicCollection*)(SbxVariable*)pForStk->refEnd;
296*cdf0e10cSrcweir 			SbxArrayRef xItemArray = pCollection->xItemArray;
297*cdf0e10cSrcweir 			sal_Int32 nCount = xItemArray->Count32();
298*cdf0e10cSrcweir 			if( pForStk->nCurCollectionIndex < nCount )
299*cdf0e10cSrcweir 			{
300*cdf0e10cSrcweir 				SbxVariable* pRes = xItemArray->Get32( pForStk->nCurCollectionIndex );
301*cdf0e10cSrcweir 				pForStk->nCurCollectionIndex++;
302*cdf0e10cSrcweir 				(*pForStk->refVar) = *pRes;
303*cdf0e10cSrcweir 			}
304*cdf0e10cSrcweir 			else
305*cdf0e10cSrcweir 			{
306*cdf0e10cSrcweir 				bEndLoop = true;
307*cdf0e10cSrcweir 			}
308*cdf0e10cSrcweir 			break;
309*cdf0e10cSrcweir 		}
310*cdf0e10cSrcweir 		case FOR_EACH_XENUMERATION:
311*cdf0e10cSrcweir 		{
312*cdf0e10cSrcweir 			SbiForStack* p = pForStk;
313*cdf0e10cSrcweir 			if( p->xEnumeration->hasMoreElements() )
314*cdf0e10cSrcweir 			{
315*cdf0e10cSrcweir 				Any aElem = p->xEnumeration->nextElement();
316*cdf0e10cSrcweir 				SbxVariableRef xVar = new SbxVariable( SbxVARIANT );
317*cdf0e10cSrcweir 				unoToSbxValue( (SbxVariable*)xVar, aElem );
318*cdf0e10cSrcweir 				(*pForStk->refVar) = *xVar;
319*cdf0e10cSrcweir 			}
320*cdf0e10cSrcweir 			else
321*cdf0e10cSrcweir 			{
322*cdf0e10cSrcweir 				bEndLoop = true;
323*cdf0e10cSrcweir 			}
324*cdf0e10cSrcweir 			break;
325*cdf0e10cSrcweir 		}
326*cdf0e10cSrcweir 	}
327*cdf0e10cSrcweir 	if( bEndLoop )
328*cdf0e10cSrcweir 	{
329*cdf0e10cSrcweir 		PopFor();
330*cdf0e10cSrcweir 		StepJUMP( nOp1 );
331*cdf0e10cSrcweir 	}
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir // Tos+1 <= Tos+2 <= Tos, 2xremove (+Target)
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir void SbiRuntime::StepCASETO( sal_uInt32 nOp1 )
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir 	if( !refCaseStk || !refCaseStk->Count() )
339*cdf0e10cSrcweir 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
340*cdf0e10cSrcweir 	else
341*cdf0e10cSrcweir 	{
342*cdf0e10cSrcweir 		SbxVariableRef xTo   = PopVar();
343*cdf0e10cSrcweir 		SbxVariableRef xFrom = PopVar();
344*cdf0e10cSrcweir 		SbxVariableRef xCase = refCaseStk->Get( refCaseStk->Count() - 1 );
345*cdf0e10cSrcweir 		if( *xCase >= *xFrom && *xCase <= *xTo )
346*cdf0e10cSrcweir 			StepJUMP( nOp1 );
347*cdf0e10cSrcweir 	}
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir // Fehler-Handler
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir void SbiRuntime::StepERRHDL( sal_uInt32 nOp1 )
353*cdf0e10cSrcweir {
354*cdf0e10cSrcweir 	const sal_uInt8* p = pCode;
355*cdf0e10cSrcweir 	StepJUMP( nOp1 );
356*cdf0e10cSrcweir 	pError = pCode;
357*cdf0e10cSrcweir 	pCode = p;
358*cdf0e10cSrcweir 	pInst->aErrorMsg = String();
359*cdf0e10cSrcweir 	pInst->nErr = 0;
360*cdf0e10cSrcweir 	pInst->nErl = 0;
361*cdf0e10cSrcweir 	nError = 0;
362*cdf0e10cSrcweir 	SbxErrObject::getUnoErrObject()->Clear();
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir // Resume nach Fehlern (+0=statement, 1=next or Label)
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir void SbiRuntime::StepRESUME( sal_uInt32 nOp1 )
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir 	// AB #32714 Resume ohne Error? -> Fehler
370*cdf0e10cSrcweir 	if( !bInError )
371*cdf0e10cSrcweir 	{
372*cdf0e10cSrcweir 		Error( SbERR_BAD_RESUME );
373*cdf0e10cSrcweir 		return;
374*cdf0e10cSrcweir 	}
375*cdf0e10cSrcweir 	if( nOp1 )
376*cdf0e10cSrcweir 	{
377*cdf0e10cSrcweir 		// Code-Zeiger auf naechstes Statement setzen
378*cdf0e10cSrcweir 		sal_uInt16 n1, n2;
379*cdf0e10cSrcweir 		pCode = pMod->FindNextStmnt( pErrCode, n1, n2, sal_True, pImg );
380*cdf0e10cSrcweir 	}
381*cdf0e10cSrcweir 	else
382*cdf0e10cSrcweir 		pCode = pErrStmnt;
383*cdf0e10cSrcweir 	if ( pError ) // current in error handler ( and got a Resume Next statment )
384*cdf0e10cSrcweir 		SbxErrObject::getUnoErrObject()->Clear();
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 	if( nOp1 > 1 )
387*cdf0e10cSrcweir 		StepJUMP( nOp1 );
388*cdf0e10cSrcweir 	pInst->aErrorMsg = String();
389*cdf0e10cSrcweir 	pInst->nErr = 0;
390*cdf0e10cSrcweir 	pInst->nErl = 0;
391*cdf0e10cSrcweir 	nError = 0;
392*cdf0e10cSrcweir 	bInError = sal_False;
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 	// Error-Stack loeschen
395*cdf0e10cSrcweir 	SbErrorStack*& rErrStack = GetSbData()->pErrStack;
396*cdf0e10cSrcweir 	delete rErrStack;
397*cdf0e10cSrcweir 	rErrStack = NULL;
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir // Kanal schliessen (+Kanal, 0=Alle)
401*cdf0e10cSrcweir void SbiRuntime::StepCLOSE( sal_uInt32 nOp1 )
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir 	SbError err;
404*cdf0e10cSrcweir 	if( !nOp1 )
405*cdf0e10cSrcweir 		pIosys->Shutdown();
406*cdf0e10cSrcweir 	else
407*cdf0e10cSrcweir 	{
408*cdf0e10cSrcweir 		err = pIosys->GetError();
409*cdf0e10cSrcweir 		if( !err )
410*cdf0e10cSrcweir 		{
411*cdf0e10cSrcweir 			pIosys->Close();
412*cdf0e10cSrcweir 		}
413*cdf0e10cSrcweir 	}
414*cdf0e10cSrcweir 	err = pIosys->GetError();
415*cdf0e10cSrcweir 	Error( err );
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir // Zeichen ausgeben (+char)
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir void SbiRuntime::StepPRCHAR( sal_uInt32 nOp1 )
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir 	ByteString s( (char) nOp1 );
423*cdf0e10cSrcweir 	pIosys->Write( s );
424*cdf0e10cSrcweir 	Error( pIosys->GetError() );
425*cdf0e10cSrcweir }
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir // Check, ob TOS eine bestimmte Objektklasse ist (+StringID)
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir bool SbiRuntime::implIsClass( SbxObject* pObj, const String& aClass )
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir 	bool bRet = true;
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 	if( aClass.Len() != 0 )
434*cdf0e10cSrcweir 	{
435*cdf0e10cSrcweir 		bRet = pObj->IsClass( aClass );
436*cdf0e10cSrcweir 		if( !bRet )
437*cdf0e10cSrcweir 			bRet = aClass.EqualsIgnoreCaseAscii( String( RTL_CONSTASCII_USTRINGPARAM("object") ) );
438*cdf0e10cSrcweir 		if( !bRet )
439*cdf0e10cSrcweir 		{
440*cdf0e10cSrcweir 			String aObjClass = pObj->GetClassName();
441*cdf0e10cSrcweir 			SbModule* pClassMod = pCLASSFAC->FindClass( aObjClass );
442*cdf0e10cSrcweir 			SbClassData* pClassData;
443*cdf0e10cSrcweir 			if( pClassMod && (pClassData=pClassMod->pClassData) != NULL )
444*cdf0e10cSrcweir 			{
445*cdf0e10cSrcweir 				SbxVariable* pClassVar =
446*cdf0e10cSrcweir 					pClassData->mxIfaces->Find( aClass, SbxCLASS_DONTCARE );
447*cdf0e10cSrcweir 				bRet = (pClassVar != NULL);
448*cdf0e10cSrcweir 			}
449*cdf0e10cSrcweir 		}
450*cdf0e10cSrcweir 	}
451*cdf0e10cSrcweir 	return bRet;
452*cdf0e10cSrcweir }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir bool SbiRuntime::checkClass_Impl( const SbxVariableRef& refVal,
455*cdf0e10cSrcweir 	const String& aClass, bool bRaiseErrors, bool bDefault )
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir 	bool bOk = bDefault;
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 	SbxDataType t = refVal->GetType();
460*cdf0e10cSrcweir 	if( t == SbxOBJECT )
461*cdf0e10cSrcweir 	{
462*cdf0e10cSrcweir 		SbxObject* pObj;
463*cdf0e10cSrcweir 		SbxVariable* pVal = (SbxVariable*)refVal;
464*cdf0e10cSrcweir 		if( pVal->IsA( TYPE(SbxObject) ) )
465*cdf0e10cSrcweir 			pObj = (SbxObject*) pVal;
466*cdf0e10cSrcweir 		else
467*cdf0e10cSrcweir 		{
468*cdf0e10cSrcweir 			pObj = (SbxObject*) refVal->GetObject();
469*cdf0e10cSrcweir 			if( pObj && !pObj->IsA( TYPE(SbxObject) ) )
470*cdf0e10cSrcweir 				pObj = NULL;
471*cdf0e10cSrcweir 		}
472*cdf0e10cSrcweir 		if( pObj )
473*cdf0e10cSrcweir 		{
474*cdf0e10cSrcweir 			if( !implIsClass( pObj, aClass ) )
475*cdf0e10cSrcweir 			{
476*cdf0e10cSrcweir 				if ( bVBAEnabled && pObj->IsA( TYPE(SbUnoObject) ) )
477*cdf0e10cSrcweir 				{
478*cdf0e10cSrcweir 					SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,pObj);
479*cdf0e10cSrcweir 					bOk = checkUnoObjectType( pUnoObj, aClass );
480*cdf0e10cSrcweir 				}
481*cdf0e10cSrcweir 				else
482*cdf0e10cSrcweir 					bOk = false;
483*cdf0e10cSrcweir 				if ( !bOk )
484*cdf0e10cSrcweir 				{
485*cdf0e10cSrcweir 					if( bRaiseErrors )
486*cdf0e10cSrcweir 						Error( SbERR_INVALID_USAGE_OBJECT );
487*cdf0e10cSrcweir 				}
488*cdf0e10cSrcweir 			}
489*cdf0e10cSrcweir 			else
490*cdf0e10cSrcweir 			{
491*cdf0e10cSrcweir 				bOk = true;
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 				SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pObj);
494*cdf0e10cSrcweir 				if( pClassModuleObject != NULL )
495*cdf0e10cSrcweir 					pClassModuleObject->triggerInitializeEvent();
496*cdf0e10cSrcweir 			}
497*cdf0e10cSrcweir 		}
498*cdf0e10cSrcweir 	}
499*cdf0e10cSrcweir 	else
500*cdf0e10cSrcweir 	{
501*cdf0e10cSrcweir 		if ( !bVBAEnabled )
502*cdf0e10cSrcweir 		{
503*cdf0e10cSrcweir 			if( bRaiseErrors )
504*cdf0e10cSrcweir 				Error( SbERR_NEEDS_OBJECT );
505*cdf0e10cSrcweir 			bOk = false;
506*cdf0e10cSrcweir 		}
507*cdf0e10cSrcweir 	}
508*cdf0e10cSrcweir 	return bOk;
509*cdf0e10cSrcweir }
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir void SbiRuntime::StepSETCLASS_impl( sal_uInt32 nOp1, bool bHandleDflt )
512*cdf0e10cSrcweir {
513*cdf0e10cSrcweir 	SbxVariableRef refVal = PopVar();
514*cdf0e10cSrcweir 	SbxVariableRef refVar = PopVar();
515*cdf0e10cSrcweir 	String aClass( pImg->GetString( static_cast<short>( nOp1 ) ) );
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir 	bool bOk = checkClass_Impl( refVal, aClass, true );
518*cdf0e10cSrcweir 	if( bOk )
519*cdf0e10cSrcweir 		StepSET_Impl( refVal, refVar, bHandleDflt ); // don't do handle dflt prop for a "proper" set
520*cdf0e10cSrcweir }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir void SbiRuntime::StepVBASETCLASS( sal_uInt32 nOp1 )
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir 	StepSETCLASS_impl( nOp1, false );
525*cdf0e10cSrcweir }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir void SbiRuntime::StepSETCLASS( sal_uInt32 nOp1 )
528*cdf0e10cSrcweir {
529*cdf0e10cSrcweir 	StepSETCLASS_impl( nOp1, true );
530*cdf0e10cSrcweir }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir void SbiRuntime::StepTESTCLASS( sal_uInt32 nOp1 )
533*cdf0e10cSrcweir {
534*cdf0e10cSrcweir 	SbxVariableRef xObjVal = PopVar();
535*cdf0e10cSrcweir 	String aClass( pImg->GetString( static_cast<short>( nOp1 ) ) );
536*cdf0e10cSrcweir 	bool bDefault = !bVBAEnabled;
537*cdf0e10cSrcweir 	bool bOk = checkClass_Impl( xObjVal, aClass, false, bDefault );
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 	SbxVariable* pRet = new SbxVariable;
540*cdf0e10cSrcweir 	pRet->PutBool( bOk );
541*cdf0e10cSrcweir 	PushVar( pRet );
542*cdf0e10cSrcweir }
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir // Library fuer anschliessenden Declare-Call definieren
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir void SbiRuntime::StepLIB( sal_uInt32 nOp1 )
547*cdf0e10cSrcweir {
548*cdf0e10cSrcweir 	aLibName = pImg->GetString( static_cast<short>( nOp1 ) );
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir // TOS wird um BASE erhoeht, BASE davor gepusht (+BASE)
552*cdf0e10cSrcweir // Dieser Opcode wird vor DIM/REDIM-Anweisungen gepusht,
553*cdf0e10cSrcweir // wenn nur ein Index angegeben wurde.
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir void SbiRuntime::StepBASED( sal_uInt32 nOp1 )
556*cdf0e10cSrcweir {
557*cdf0e10cSrcweir 	SbxVariable* p1 = new SbxVariable;
558*cdf0e10cSrcweir 	SbxVariableRef x2 = PopVar();
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 	// #109275 Check compatiblity mode
561*cdf0e10cSrcweir 	bool bCompatible = ((nOp1 & 0x8000) != 0);
562*cdf0e10cSrcweir 	sal_uInt16 uBase = static_cast<sal_uInt16>(nOp1 & 1);		// Can only be 0 or 1
563*cdf0e10cSrcweir 	p1->PutInteger( uBase );
564*cdf0e10cSrcweir 	if( !bCompatible )
565*cdf0e10cSrcweir 		x2->Compute( SbxPLUS, *p1 );
566*cdf0e10cSrcweir 	PushVar( x2 );	// erst die Expr
567*cdf0e10cSrcweir 	PushVar( p1 );	// dann die Base
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir 
574