1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_BASIC_SBMOD_HXX
21 #define INCLUDED_BASIC_SBMOD_HXX
23 #include <basic/sbdef.hxx>
24 #include <basic/sbxobj.hxx>
25 #include <basic/sbxdef.hxx>
26 #include <basic/sbx.hxx>
27 #include <rtl/ustring.hxx>
31 #include <basic/basicdllapi.h>
32 #include <com/sun/star/uno/Reference.hxx>
34 namespace com::sun::star::script
{ class XInvocation
; }
38 typedef std::deque
< sal_uInt16
> SbiBreakpoints
;
40 class SbClassModuleObject
;
41 class CodeCompleteDataCache
;
44 class ModuleInitDependencyMap
;
45 struct ClassModuleRunInitItem
;
48 class BASIC_DLLPUBLIC SbModule
: public SbxObject
50 friend class SbiCodeGen
;
51 friend class SbMethod
;
52 friend class SbiRuntime
;
53 friend class StarBASIC
;
54 friend class SbClassModuleObject
;
56 std::vector
< OUString
> mModuleVariableNames
;
58 BASIC_DLLPRIVATE
static void implClearIfVarDependsOnDeletedBasic( SbxVariable
* pVar
, StarBASIC
* pDeletedBasic
);
60 SbModule(const SbModule
&) = delete;
61 SbModule
& operator=(const SbModule
&) = delete;
63 css::uno::Reference
< css::script::XInvocation
> mxWrapper
;
66 std::unique_ptr
<SbiImage
> pImage
; // the Image
67 std::unique_ptr
<SbiBreakpoints
> pBreaks
; // Breakpoints
68 std::unique_ptr
<SbClassData
> pClassData
;
71 SbxObjectRef pDocObject
; // an impl object ( used by Document Modules )
74 static void implProcessModuleRunInit( ModuleInitDependencyMap
& rMap
, ClassModuleRunInitItem
& rItem
);
75 void StartDefinitions();
76 SbMethod
* GetMethod( const OUString
&, SbxDataType
);
77 SbProperty
* GetProperty( const OUString
&, SbxDataType
);
78 void GetProcedureProperty( const OUString
&, SbxDataType
);
79 void GetIfaceMapperMethod( const OUString
&, SbMethod
* );
80 void EndDefinitions( bool=false );
81 void Run( SbMethod
* );
83 void ClearPrivateVars();
84 void ClearVarsDependingOnDeletedBasic( StarBASIC
* pDeletedBasic
);
85 void GlobalRunInit( bool bBasicStart
); // for all modules
86 void GlobalRunDeInit();
87 const sal_uInt8
* FindNextStmnt( const sal_uInt8
*, sal_uInt16
&, sal_uInt16
& ) const;
88 const sal_uInt8
* FindNextStmnt( const sal_uInt8
*, sal_uInt16
&, sal_uInt16
&,
89 bool bFollowJumps
, const SbiImage
* pImg
=nullptr ) const;
90 virtual bool LoadData( SvStream
&, sal_uInt16
) override
;
91 virtual bool StoreData( SvStream
& ) const override
;
92 virtual bool LoadCompleted() override
;
93 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
94 void handleProcedureProperties( SfxBroadcaster
& rBC
, const SfxHint
& rHint
);
95 virtual ~SbModule() override
;
97 SBX_DECL_PERSIST_NODATA(SBXID_BASICMOD
,2);
98 SbModule( const OUString
&, bool bCompat
= false );
99 virtual void SetParent( SbxObject
* ) override
;
100 virtual void Clear() override
;
102 virtual SbxVariable
* Find( const OUString
&, SbxClassType
) override
;
104 const OUString
& GetSource() const;
105 const OUString
& GetSource32() const { return aOUSource
;}
106 void SetSource32( const OUString
& r
);
109 bool IsCompiled() const;
110 const SbxObject
* FindType( const OUString
& aTypeName
) const;
112 bool IsBreakable( sal_uInt16 nLine
) const;
113 bool IsBP( sal_uInt16 nLine
) const;
114 bool SetBP( sal_uInt16 nLine
);
115 bool ClearBP( sal_uInt16 nLine
);
118 // Store only image, no source (needed for new password protection)
119 void StoreBinaryData( SvStream
& );
120 void LoadBinaryData( SvStream
& );
121 bool ExceedsLegacyModuleSize();
122 void fixUpMethodStart( bool bCvtToLegacy
, SbiImage
* pImg
= nullptr ) const;
124 bool IsVBACompat() const { return mbVBACompat
;}
125 void SetVBACompat( bool bCompat
);
126 sal_Int32
GetModuleType() { return mnType
; }
127 void SetModuleType( sal_Int32 nType
) { mnType
= nType
; }
128 bool isProxyModule() { return bIsProxyModule
; }
129 void AddVarName( const OUString
& aName
);
131 css::uno::Reference
< css::script::XInvocation
> const & GetUnoModule();
132 bool createCOMWrapperForIface( css::uno::Any
& o_rRetAny
, SbClassModuleObject
* pProxyClassModuleObject
);
133 void GetCodeCompleteDataFromParse(CodeCompleteDataCache
& aCache
);
134 const SbxArrayRef
& GetMethods() { return pMethods
;}
135 SbMethod
* FindMethod( const OUString
&, SbxClassType
);
136 static OUString
GetKeywordCase( const OUString
& sKeyword
);
139 typedef tools::SvRef
<SbModule
> SbModuleRef
;
140 typedef std::vector
<SbModuleRef
> SbModules
;
142 // Object class for instances of class modules
143 class BASIC_DLLPUBLIC SbClassModuleObject
: public SbModule
145 SbModule
* mpClassModule
;
146 bool mbInitializeEventDone
;
149 SbClassModuleObject( SbModule
* pClassModule
);
150 virtual ~SbClassModuleObject() override
;
152 // Overridden to support NameAccess etc.
153 virtual SbxVariable
* Find( const OUString
&, SbxClassType
) override
;
155 virtual void Notify( SfxBroadcaster
&, const SfxHint
& rHint
) override
;
157 SbModule
* getClassModule()
158 { return mpClassModule
; }
160 void triggerInitializeEvent();
161 void triggerTerminateEvent();
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */