tdf#124162: Crash when trying to accept changes
[LibreOffice.git] / include / basic / sbmod.hxx
blob8b9b78e9a07fa3a8b0a545c66ac94af6931045ac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
28 #include <vector>
29 #include <deque>
30 #include <memory>
31 #include <basic/basicdllapi.h>
32 #include <com/sun/star/uno/Reference.hxx>
34 namespace com::sun::star::script { class XInvocation; }
36 class SbMethod;
37 class SbProperty;
38 typedef std::deque< sal_uInt16 > SbiBreakpoints;
39 class SbiImage;
40 class SbClassModuleObject;
41 class CodeCompleteDataCache;
44 class ModuleInitDependencyMap;
45 struct ClassModuleRunInitItem;
46 struct SbClassData;
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;
62 protected:
63 css::uno::Reference< css::script::XInvocation > mxWrapper;
64 OUString aOUSource;
65 OUString aComment;
66 std::unique_ptr<SbiImage> pImage; // the Image
67 std::unique_ptr<SbiBreakpoints> pBreaks; // Breakpoints
68 std::unique_ptr<SbClassData> pClassData;
69 bool mbVBACompat;
70 sal_Int32 mnType;
71 SbxObjectRef pDocObject; // an impl object ( used by Document Modules )
72 bool bIsProxyModule;
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* );
82 void RunInit();
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;
96 public:
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 );
108 bool Compile();
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 );
116 void ClearAllBP();
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;
123 bool HasExeCode();
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 );
130 void RemoveVars();
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;
148 public:
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();
164 #endif
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */