workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / basic / sbstar.hxx
blob599f14aa4b1bc70be62f0a08dfb5f4b84e0854f0
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_SBSTAR_HXX
21 #define INCLUDED_BASIC_SBSTAR_HXX
23 #include <basic/sbx.hxx>
24 #include <basic/sbxobj.hxx>
25 #include <basic/sbmod.hxx>
26 #include <rtl/ustring.hxx>
27 #include <tools/link.hxx>
28 #include <comphelper/errcode.hxx>
30 #include <basic/sbdef.hxx>
31 #include <basic/basicdllapi.h>
33 namespace com::sun::star::frame { class XModel; }
34 namespace com::sun::star::script { struct ModuleInfo; }
36 class SbMethod;
38 class BASIC_DLLPUBLIC StarBASIC final : public SbxObject
40 friend class SbiScanner;
41 friend class SbiExpression; // Access to RTL
42 friend class SbiInstance; // runtime instance
43 friend class SbiRuntime; // currently running procedure
44 friend class DocBasicItem;
46 SbModules pModules; // List of all modules
47 SbxObjectRef pRtl; // Runtime Library
48 SbxArrayRef xUnoListeners; // Listener handled by CreateUnoListener
50 // Handler-Support:
51 Link<StarBASIC*,bool> aErrorHdl; // Error handler
52 Link<StarBASIC*,BasicDebugFlags> aBreakHdl; // Breakpoint handler
53 bool bNoRtl; // if true: do not search RTL
54 bool bBreak; // if true: Break, otherwise Step
55 bool bDocBasic;
56 bool bVBAEnabled;
57 bool bQuit;
59 SbxObjectRef pVBAGlobals;
61 BASIC_DLLPRIVATE void implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic );
62 bool CError( ErrCode, const OUString&, sal_Int32, sal_Int32, sal_Int32 );
63 BASIC_DLLPRIVATE bool RTError( ErrCode, const OUString& rMsg, sal_Int32, sal_Int32, sal_Int32 );
64 BASIC_DLLPRIVATE BasicDebugFlags BreakPoint( sal_Int32 nLine, sal_Int32 nCol1, sal_Int32 nCol2 );
65 BASIC_DLLPRIVATE BasicDebugFlags StepPoint( sal_Int32 nLine, sal_Int32 nCol1, sal_Int32 nCol2 );
66 virtual bool LoadData( SvStream&, sal_uInt16 ) override;
67 virtual std::pair<bool, sal_uInt32> StoreData( SvStream& ) const override;
68 bool ErrorHdl();
69 BasicDebugFlags BreakHdl();
70 virtual ~StarBASIC() override;
72 public:
74 SBX_DECL_PERSIST_NODATA(SBXID_BASIC,1);
76 StarBASIC( StarBASIC* pParent = nullptr, bool bIsDocBasic = false );
78 // #51727 SetModified overridden so that the Modified-State is
79 // not delivered to Parent.
80 virtual void SetModified( bool ) override;
82 virtual void Insert( SbxVariable* ) override;
83 using SbxObject::Remove;
84 virtual void Remove( SbxVariable* ) override;
85 virtual void Clear() override;
87 // Compiler-Interface
88 SbModule* MakeModule( const OUString& rName, const OUString& rSrc );
89 SbModule* MakeModule( const OUString& rName, const css::script::ModuleInfo& mInfo, const OUString& rSrc );
90 static void Stop();
91 static void Error( ErrCode, const OUString& rMsg = {} );
92 static void FatalError( ErrCode );
93 static void FatalError( ErrCode, const OUString& rMsg );
94 static bool IsRunning();
95 static ErrCode GetErrBasic();
96 // #66536 make additional message accessible by RTL function Error
97 static OUString GetErrorMsg();
98 static sal_Int32 GetErl();
100 virtual SbxVariable* Find( const OUString&, SbxClassType ) override;
101 virtual bool Call( const OUString&, SbxArray* = nullptr ) override;
103 SbModules& GetModules() { return pModules; }
104 SbxObject* GetRtl() { return pRtl.get(); }
105 SbModule* FindModule( std::u16string_view );
106 // Run init code of all modules (including the inserted Doc-Basics)
107 void InitAllModules( StarBASIC const * pBasicNotToInit = nullptr );
108 void DeInitAllModules();
109 void ClearAllModuleVars();
111 // Calls for error and break handler
112 static sal_uInt16 GetLine();
113 static sal_uInt16 GetCol1();
114 static sal_uInt16 GetCol2();
115 static void SetErrorData( const ErrCodeMsg& nCode, sal_uInt16 nLine,
116 sal_uInt16 nCol1, sal_uInt16 nCol2 );
118 // Specific to error handler
119 static void MakeErrorText( ErrCode, std::u16string_view aMsg );
120 static const OUString& GetErrorText();
121 static ErrCodeMsg const & GetErrorCode();
122 static sal_uInt16 GetVBErrorCode( ErrCode nError );
123 static ErrCode GetSfxFromVBError( sal_uInt16 nError );
124 bool IsBreak() const { return bBreak; }
126 static Link<StarBASIC*,bool> const & GetGlobalErrorHdl();
127 static void SetGlobalErrorHdl( const Link<StarBASIC*,bool>& rNewHdl );
129 static void SetGlobalBreakHdl( const Link<StarBASIC*,BasicDebugFlags>& rNewHdl );
131 SbxArrayRef const & getUnoListeners();
133 static SbxBase* FindSBXInCurrentScope( const OUString& rName );
134 static SbMethod* GetActiveMethod( sal_uInt16 nLevel = 0 );
135 static SbModule* GetActiveModule();
136 void SetVBAEnabled( bool bEnabled );
137 bool isVBAEnabled() const;
139 const SbxObjectRef& getRTL() const { return pRtl; }
140 bool IsDocBasic() const { return bDocBasic; }
141 SbxVariable* VBAFind( const OUString& rName, SbxClassType t );
142 bool GetUNOConstant( const OUString& rName, css::uno::Any& aOut );
143 void QuitAndExitApplication();
144 bool IsQuitApplication() const { return bQuit; };
146 SbxObject* getVBAGlobals( );
148 static css::uno::Reference< css::frame::XModel >
149 GetModelFromBasic( SbxObject* pBasic );
151 static void DetachAllDocBasicItems();
154 typedef tools::SvRef<StarBASIC> StarBASICRef;
156 #endif
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */