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>
30 #include <basic/basicdllapi.h>
31 #include <com/sun/star/uno/Reference.hxx>
33 namespace com::sun::star::script
{ class XInvocation
; }
37 typedef std::deque
< sal_uInt16
> SbiBreakpoints
;
39 class SbClassModuleObject
;
40 class CodeCompleteDataCache
;
43 class ModuleInitDependencyMap
;
44 struct ClassModuleRunInitItem
;
47 class BASIC_DLLPUBLIC SbModule
: public SbxObject
49 friend class SbiCodeGen
;
50 friend class SbMethod
;
51 friend class SbiRuntime
;
52 friend class StarBASIC
;
53 friend class SbClassModuleObject
;
55 std::vector
< OUString
> mModuleVariableNames
;
57 BASIC_DLLPRIVATE
static void implClearIfVarDependsOnDeletedBasic( SbxVariable
* pVar
, StarBASIC
* pDeletedBasic
);
59 SbModule(const SbModule
&) = delete;
60 SbModule
& operator=(const SbModule
&) = delete;
62 css::uno::Reference
< css::script::XInvocation
> mxWrapper
;
65 SbiImage
* pImage
; // the Image
66 SbiBreakpoints
* pBreaks
; // Breakpoints
67 std::unique_ptr
<SbClassData
> pClassData
;
70 SbxObjectRef pDocObject
; // an impl object ( used by Document Modules )
73 static void implProcessModuleRunInit( ModuleInitDependencyMap
& rMap
, ClassModuleRunInitItem
& rItem
);
74 void StartDefinitions();
75 SbMethod
* GetMethod( const OUString
&, SbxDataType
);
76 SbProperty
* GetProperty( const OUString
&, SbxDataType
);
77 void GetProcedureProperty( const OUString
&, SbxDataType
);
78 void GetIfaceMapperMethod( const OUString
&, SbMethod
* );
79 void EndDefinitions( bool=false );
80 void Run( SbMethod
* );
82 void ClearPrivateVars();
83 void ClearVarsDependingOnDeletedBasic( StarBASIC
* pDeletedBasic
);
84 void GlobalRunInit( bool bBasicStart
); // for all modules
85 void GlobalRunDeInit();
86 const sal_uInt8
* FindNextStmnt( const sal_uInt8
*, sal_uInt16
&, sal_uInt16
& ) const;
87 const sal_uInt8
* FindNextStmnt( const sal_uInt8
*, sal_uInt16
&, sal_uInt16
&,
88 bool bFollowJumps
, const SbiImage
* pImg
=nullptr ) const;
89 virtual bool LoadData( SvStream
&, sal_uInt16
) override
;
90 virtual bool StoreData( SvStream
& ) const override
;
91 virtual bool LoadCompleted() override
;
92 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
93 void handleProcedureProperties( SfxBroadcaster
& rBC
, const SfxHint
& rHint
);
94 virtual ~SbModule() override
;
96 SBX_DECL_PERSIST_NODATA(SBXID_BASICMOD
,2);
97 SbModule( const OUString
&, bool bCompat
= false );
98 virtual void SetParent( SbxObject
* ) override
;
99 virtual void Clear() override
;
101 virtual SbxVariable
* Find( const OUString
&, SbxClassType
) override
;
103 const OUString
& GetSource32() const { return aOUSource
;}
104 void SetSource32( const OUString
& r
);
107 bool IsCompiled() const;
108 const SbxObject
* FindType( const OUString
& aTypeName
) const;
110 bool IsBreakable( sal_uInt16 nLine
) const;
111 bool IsBP( sal_uInt16 nLine
) const;
112 bool SetBP( sal_uInt16 nLine
);
113 bool ClearBP( sal_uInt16 nLine
);
116 // Store only image, no source (needed for new password protection)
117 void StoreBinaryData( SvStream
& );
118 void LoadBinaryData( SvStream
& );
119 bool ExceedsLegacyModuleSize();
120 void fixUpMethodStart( bool bCvtToLegacy
, SbiImage
* pImg
= nullptr ) const;
122 bool IsVBACompat() const { return mbVBACompat
;}
123 void SetVBACompat( bool bCompat
);
124 sal_Int32
GetModuleType() const { return mnType
; }
125 void SetModuleType( sal_Int32 nType
) { mnType
= nType
; }
126 bool isProxyModule() const { return bIsProxyModule
; }
127 void AddVarName( const OUString
& aName
);
129 css::uno::Reference
< css::script::XInvocation
> const & GetUnoModule();
130 bool createCOMWrapperForIface( css::uno::Any
& o_rRetAny
, SbClassModuleObject
* pProxyClassModuleObject
);
131 void GetCodeCompleteDataFromParse(CodeCompleteDataCache
& aCache
);
132 const SbxArrayRef
& GetMethods() const { return pMethods
;}
133 SbMethod
* FindMethod( const OUString
&, SbxClassType
);
134 static OUString
GetKeywordCase( const OUString
& sKeyword
);
137 typedef tools::SvRef
<SbModule
> SbModuleRef
;
138 typedef std::vector
<SbModuleRef
> SbModules
;
140 // Object class for instances of class modules
141 class BASIC_DLLPUBLIC SbClassModuleObject
: public SbModule
143 SbModule
* mpClassModule
;
144 bool mbInitializeEventDone
;
147 SbClassModuleObject( SbModule
* pClassModule
);
148 virtual ~SbClassModuleObject() override
;
150 // Overridden to support NameAccess etc.
151 virtual SbxVariable
* Find( const OUString
&, SbxClassType
) override
;
153 virtual void Notify( SfxBroadcaster
&, const SfxHint
& rHint
) override
;
155 SbModule
* getClassModule()
156 { return mpClassModule
; }
158 void triggerInitializeEvent();
159 void triggerTerminateEvent();
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */