1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbcomp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
34 #include <basic/sbx.hxx>
40 // #define DBG_SAVE_DISASSEMBLY
42 #ifdef DBG_SAVE_DISASSEMBLY
43 static bool dbg_bDisassemble
= true;
44 #include <comphelper/processfactory.hxx>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/ucb/XSimpleFileAccess3.hpp>
48 #include <com/sun/star/io/XTextOutputStream.hpp>
49 #include <com/sun/star/io/XActiveDataSource.hpp>
51 using namespace comphelper
;
53 using namespace com::sun::star::uno
;
54 using namespace com::sun::star::lang
;
55 using namespace com::sun::star::ucb
;
56 using namespace com::sun::star::io
;
58 void dbg_SaveDisassembly( SbModule
* pModule
)
60 bool bDisassemble
= dbg_bDisassemble
;
63 Reference
< XSimpleFileAccess3
> xSFI
;
64 Reference
< XTextOutputStream
> xTextOut
;
65 Reference
< XOutputStream
> xOut
;
66 Reference
< XMultiServiceFactory
> xSMgr
= getProcessServiceFactory();
69 Reference
< XSimpleFileAccess3
> xSFI
= Reference
< XSimpleFileAccess3
>( xSMgr
->createInstance
70 ( OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY
);
73 String
aFile( RTL_CONSTASCII_USTRINGPARAM("file:///d:/BasicAsm_") );
74 StarBASIC
* pBasic
= (StarBASIC
*)pModule
->GetParent();
77 aFile
+= pBasic
->GetName();
78 aFile
.AppendAscii( "_" );
80 aFile
+= pModule
->GetName();
81 aFile
.AppendAscii( ".txt" );
83 // String aFile( RTL_CONSTASCII_USTRINGPARAM("file:///d:/BasicAsm.txt") );
84 if( xSFI
->exists( aFile
) )
86 xOut
= xSFI
->openFileWrite( aFile
);
87 Reference
< XInterface
> x
= xSMgr
->createInstance( OUString::createFromAscii( "com.sun.star.io.TextOutputStream" ) );
88 Reference
< XActiveDataSource
> xADS( x
, UNO_QUERY
);
89 xADS
->setOutputStream( xOut
);
90 xTextOut
= Reference
< XTextOutputStream
>( x
, UNO_QUERY
);
96 String aDisassemblyStr
;
97 pModule
->Disassemble( aDisassemblyStr
);
98 xTextOut
->writeString( aDisassemblyStr
);
105 // Diese Routine ist hier definiert, damit der Compiler als eigenes Segment
106 // geladen werden kann.
108 BOOL
SbModule::Compile()
112 StarBASIC
* pBasic
= PTR_CAST(StarBASIC
,GetParent());
115 SbxBase::ResetError();
117 SbModule
* pOld
= pCMOD
;
120 SbiParser
* pParser
= new SbiParser( (StarBASIC
*) GetParent(), this );
121 while( pParser
->Parse() ) {}
122 if( !pParser
->GetErrors() )
123 pParser
->aGen
.Save();
125 // fuer den Disassembler
127 pImage
->aOUSource
= aOUSource
;
131 // Beim Compilieren eines Moduls werden die Modul-globalen
132 // Variablen aller Module ungueltig
133 BOOL bRet
= IsCompiled();
136 pBasic
->ClearAllModuleVars();
137 RemoveVars(); // remove 'this' Modules variables
138 // clear all method statics
139 for( USHORT i
= 0; i
< pMethods
->Count(); i
++ )
141 SbMethod
* p
= PTR_CAST(SbMethod
,pMethods
->Get( i
) );
146 // #i31510 Init other libs only if Basic isn't running
149 SbxObject
* pParent_
= pBasic
->GetParent();
151 pBasic
= PTR_CAST(StarBASIC
,pParent_
);
153 pBasic
->ClearAllModuleVars();
157 #ifdef DBG_SAVE_DISASSEMBLY
158 dbg_SaveDisassembly( this );
164 /**************************************************************************
166 * Syntax-Highlighting
168 **************************************************************************/
170 void StarBASIC::Highlight( const String
& rSrc
, SbTextPortions
& rList
)
172 SbiTokenizer
aTok( rSrc
);
173 aTok
.Hilite( rList
);