xref: /trunk/main/basic/inc/basic/sbmod.hxx (revision 7fef15a0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SB_SBMOD_HXX
25 #define _SB_SBMOD_HXX
26 
27 #include <com/sun/star/script/XInvocation.hpp>
28 #include "basic/basicdllapi.h"
29 #include <basic/sbdef.hxx>
30 #include <basic/sbxobj.hxx>
31 #include <basic/sbxdef.hxx>
32 #include <rtl/ustring.hxx>
33 #include <vector>
34 
35 #include <deque>
36 
37 class SbMethod;
38 class SbProperty;
39 class SbiRuntime;
40 typedef std::deque< sal_uInt16 > SbiBreakpoints;
41 class SbiImage;
42 class SbProcedureProperty;
43 class SbIfaceMapperMethod;
44 class SbClassModuleObject;
45 
46 class ModuleInitDependencyMap;
47 struct ClassModuleRunInitItem;
48 struct SbClassData;
49 class SbModuleImpl;
50 
51 class BASIC_DLLPUBLIC SbModule : public SbxObject
52 {
53 	friend class	TestToolObj;	// allows module initialisation at runtime
54 	friend class	SbiCodeGen;
55 	friend class	SbMethod;
56 	friend class	SbiRuntime;
57 	friend class	StarBASIC;
58 	friend class	SbClassModuleObject;
59 
60 	SbModuleImpl*	mpSbModuleImpl;		// Impl data
61     std::vector< String > mModuleVariableNames;
62 
63 	void 			implClearIfVarDependsOnDeletedBasic( SbxVariable* pVar, StarBASIC* pDeletedBasic );
64 
65 protected:
66     com::sun::star::uno::Reference< com::sun::star::script::XInvocation > mxWrapper;
67     ::rtl::OUString     aOUSource;
68     String              aComment;
69     SbiImage*           pImage;        // the Image
70     SbiBreakpoints*     pBreaks;       // Breakpoints
71     SbClassData*        pClassData;
72 	sal_Bool mbVBACompat;
73 	sal_Int32 mnType;
74 	SbxObjectRef pDocObject; // an impl object ( used by Document Modules )
75 	bool 	bIsProxyModule;
76 
77 	static void		implProcessModuleRunInit( ModuleInitDependencyMap& rMap, ClassModuleRunInitItem& rItem );
78 	void			StartDefinitions();
79 	SbMethod*		GetMethod( const String&, SbxDataType );
80 	SbProperty*		GetProperty( const String&, SbxDataType );
81 	SbProcedureProperty* GetProcedureProperty( const String&, SbxDataType );
82 	SbIfaceMapperMethod* GetIfaceMapperMethod( const String&, SbMethod* );
83 	void			EndDefinitions( sal_Bool=sal_False );
84 	sal_uInt16 			Run( SbMethod* );
85 	void			RunInit();
86 	void 			ClearPrivateVars();
87 	void 			ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic );
88 	void			GlobalRunInit( sal_Bool bBasicStart );	// for all modules
89 	void			GlobalRunDeInit( void );
90 	const sal_uInt8* 	FindNextStmnt( const sal_uInt8*, sal_uInt16&, sal_uInt16& ) const;
91 	const sal_uInt8* 	FindNextStmnt( const sal_uInt8*, sal_uInt16&, sal_uInt16&,
92 						sal_Bool bFollowJumps, const SbiImage* pImg=NULL ) const;
93 	virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
94 	virtual sal_Bool StoreData( SvStream& ) const;
95 	virtual sal_Bool LoadCompleted();
96 	virtual void SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
97 							 const SfxHint& rHint, const TypeId& rHintType );
98 	void handleProcedureProperties( SfxBroadcaster& rBC, const SfxHint& rHint );
99 	virtual ~SbModule();
100 public:
101 	SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_BASICMOD,2);
102 	TYPEINFO();
103 					SbModule( const String&, sal_Bool bCompat = sal_False );
104 	virtual void	SetParent( SbxObject* );
105 	virtual void 	Clear();
106 
107 	virtual SbxVariable* Find( const String&, SbxClassType );
108 
109 	virtual const String& 	GetSource() const;
110     const ::rtl::OUString& 	GetSource32() const;
GetComment() const111 	const String&	GetComment() const            { return aComment; }
112 	virtual void	SetSource( const String& r );
113 	void	        SetSource32( const ::rtl::OUString& r );
114 	void			SetComment( const String& r );
115 
116 	virtual sal_Bool	Compile();
117 	sal_Bool 			Disassemble( String& rText );
118 	virtual sal_Bool	IsCompiled() const;
119 	const SbxObject* FindType( String aTypeName ) const;
120 
121 	virtual sal_Bool	IsBreakable( sal_uInt16 nLine ) const;
122 	virtual size_t	GetBPCount() const;
123 	virtual sal_uInt16	GetBP( size_t n ) const;
124 	virtual sal_Bool	IsBP( sal_uInt16 nLine ) const;
125 	virtual sal_Bool	SetBP( sal_uInt16 nLine );
126 	virtual sal_Bool	ClearBP( sal_uInt16 nLine );
127 	virtual void	ClearAllBP();
128 
129 	// Lines of Subs
130 	virtual SbMethod*	GetFunctionForLine( sal_uInt16 );
131 
132     // Store only image, no source (needed for new password protection)
133    	sal_Bool StoreBinaryData( SvStream& );
134    	sal_Bool StoreBinaryData( SvStream&, sal_uInt16 nVer );
135 	sal_Bool LoadBinaryData( SvStream&, sal_uInt16 nVer );
136 	sal_Bool LoadBinaryData( SvStream& );
137 	sal_Bool ExceedsLegacyModuleSize();
138 	void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const;
139     sal_Bool IsVBACompat() const;
140     void SetVBACompat( sal_Bool bCompat );
GetModuleType()141     sal_Int32 GetModuleType() { return mnType; }
SetModuleType(sal_Int32 nType)142     void SetModuleType( sal_Int32 nType ) { mnType = nType; }
isProxyModule()143 	bool isProxyModule() { return bIsProxyModule; }
144 	void AddVarName( const String& aName );
145 	void RemoveVars();
146     ::com::sun::star::uno::Reference< ::com::sun::star::script::XInvocation > GetUnoModule();
147 	bool createCOMWrapperForIface( ::com::sun::star::uno::Any& o_rRetAny, SbClassModuleObject* pProxyClassModuleObject );
148 };
149 
150 #ifndef __SB_SBMODULEREF_HXX
151 #define __SB_SBMODULEREF_HXX
152 
153 SV_DECL_IMPL_REF(SbModule)
154 
155 #endif
156 
157 class SbClassModuleImpl;
158 
159 // Object class for instances of class modules
160 class BASIC_DLLPUBLIC SbClassModuleObject : public SbModule
161 {
162 	SbClassModuleImpl* mpSbClassModuleImpl;
163 
164 	SbModule*	mpClassModule;
165 	bool		mbInitializeEventDone;
166 
167 public:
168 	TYPEINFO();
169 	SbClassModuleObject( SbModule* pClassModule );
170 	~SbClassModuleObject();
171 
172 	// Overridden to support NameAccess etc.
173 	virtual SbxVariable* Find( const String&, SbxClassType );
174 
175 	virtual void SFX_NOTIFY( SfxBroadcaster&, const TypeId&, const SfxHint& rHint, const TypeId& );
176 
getClassModule(void)177 	SbModule* getClassModule( void )
178 		{ return mpClassModule; }
179 
180 	void triggerInitializeEvent( void );
181 	void triggerTerminateEvent( void );
182 };
183 
184 #ifndef __SB_SBCLASSMODULEREF_HXX
185 #define __SB_SBCLASSMODULEREF_HXX
186 
187 SV_DECL_IMPL_REF(SbClassModuleObject);
188 
189 #endif
190 
191 #endif
192