tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / basic / source / comp / sbcomp.cxx
blob1a6a52b228509295631a4fc76c66baac8f28db81
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 .
21 #include <basic/sbmeth.hxx>
22 #include <basic/sbstar.hxx>
23 #include <basic/sbx.hxx>
24 #include <parser.hxx>
25 #include <image.hxx>
26 #include <sbintern.hxx>
27 #include <sbobjmod.hxx>
28 #include <memory>
30 // This routine is defined here, so that the
31 // compiler can be loaded as a discrete segment.
33 bool SbModule::Compile()
35 if( pImage )
36 return true;
37 StarBASIC* pBasic = dynamic_cast<StarBASIC*>( GetParent() );
38 if( !pBasic )
39 return false;
40 SbxBase::ResetError();
42 SbModule* pOld = GetSbData()->pCompMod;
43 GetSbData()->pCompMod = this;
45 auto pParser = std::make_unique<SbiParser>( pBasic, this );
46 while( pParser->Parse() ) {}
47 if( !pParser->GetErrors() )
48 pParser->aGen.Save();
49 pParser.reset();
50 // for the disassembler
51 if( pImage )
52 pImage->aOUSource = aOUSource;
54 GetSbData()->pCompMod = pOld;
56 // compiling a module, the module-global
57 // variables of all modules become invalid
58 bool bRet = IsCompiled();
59 if( bRet )
61 if( dynamic_cast<const SbObjModule*>( this) == nullptr )
62 pBasic->ClearAllModuleVars();
63 RemoveVars(); // remove 'this' Modules variables
64 // clear all method statics
65 for (sal_uInt32 i = 0; i < pMethods->Count(); i++)
67 SbMethod* p = dynamic_cast<SbMethod*>(pMethods->Get(i));
68 if( p )
69 p->ClearStatics();
72 // #i31510 Init other libs only if Basic isn't running
73 if( GetSbData()->pInst == nullptr )
75 SbxObject* pParent_ = pBasic->GetParent();
76 if( pParent_ )
77 pBasic = dynamic_cast<StarBASIC*>( pParent_ );
78 if( pBasic )
79 pBasic->ClearAllModuleVars();
83 return bRet;
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */