merge the formfield patch from ooo-build
[ooovba.git] / basic / source / comp / sbcomp.cxx
blobd4203e7c43f8f2adeb546c1d40665166fc3a7664
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sbcomp.cxx,v $
10 * $Revision: 1.16 $
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>
35 #include "sbcomp.hxx"
36 #include "image.hxx"
39 // For debugging only
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;
52 using namespace rtl;
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;
61 if( bDisassemble )
63 Reference< XSimpleFileAccess3 > xSFI;
64 Reference< XTextOutputStream > xTextOut;
65 Reference< XOutputStream > xOut;
66 Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory();
67 if( xSMgr.is() )
69 Reference< XSimpleFileAccess3 > xSFI = Reference< XSimpleFileAccess3 >( xSMgr->createInstance
70 ( OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY );
71 if( xSFI.is() )
73 String aFile( RTL_CONSTASCII_USTRINGPARAM("file:///d:/BasicAsm_") );
74 StarBASIC* pBasic = (StarBASIC*)pModule->GetParent();
75 if( pBasic )
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 ) )
85 xSFI->kill( 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 );
94 if( xTextOut.is() )
96 String aDisassemblyStr;
97 pModule->Disassemble( aDisassemblyStr );
98 xTextOut->writeString( aDisassemblyStr );
100 xOut->closeOutput();
103 #endif
105 // Diese Routine ist hier definiert, damit der Compiler als eigenes Segment
106 // geladen werden kann.
108 BOOL SbModule::Compile()
110 if( pImage )
111 return TRUE;
112 StarBASIC* pBasic = PTR_CAST(StarBASIC,GetParent());
113 if( !pBasic )
114 return FALSE;
115 SbxBase::ResetError();
116 // Aktuelles Modul!
117 SbModule* pOld = pCMOD;
118 pCMOD = this;
120 SbiParser* pParser = new SbiParser( (StarBASIC*) GetParent(), this );
121 while( pParser->Parse() ) {}
122 if( !pParser->GetErrors() )
123 pParser->aGen.Save();
124 delete pParser;
125 // fuer den Disassembler
126 if( pImage )
127 pImage->aOUSource = aOUSource;
129 pCMOD = pOld;
131 // Beim Compilieren eines Moduls werden die Modul-globalen
132 // Variablen aller Module ungueltig
133 BOOL bRet = IsCompiled();
134 if( bRet )
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 ) );
142 if( p )
143 p->ClearStatics();
146 // #i31510 Init other libs only if Basic isn't running
147 if( pINST == NULL )
149 SbxObject* pParent_ = pBasic->GetParent();
150 if( pParent_ )
151 pBasic = PTR_CAST(StarBASIC,pParent_);
152 if( pBasic )
153 pBasic->ClearAllModuleVars();
157 #ifdef DBG_SAVE_DISASSEMBLY
158 dbg_SaveDisassembly( this );
159 #endif
161 return bRet;
164 /**************************************************************************
166 * Syntax-Highlighting
168 **************************************************************************/
170 void StarBASIC::Highlight( const String& rSrc, SbTextPortions& rList )
172 SbiTokenizer aTok( rSrc );
173 aTok.Hilite( rList );