LibreOffice Module basic (master) 1
sbcomp.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
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>
29
30// This routine is defined here, so that the
31// compiler can be loaded as a discrete segment.
32
34{
35 if( pImage )
36 return true;
37 StarBASIC* pBasic = dynamic_cast<StarBASIC*>( GetParent() );
38 if( !pBasic )
39 return false;
41
42 SbModule* pOld = GetSbData()->pCompMod;
43 GetSbData()->pCompMod = this;
44
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;
53
54 GetSbData()->pCompMod = pOld;
55
56 // compiling a module, the module-global
57 // variables of all modules become invalid
58 bool bRet = IsCompiled();
59 if( bRet )
60 {
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++)
66 {
67 SbMethod* p = dynamic_cast<SbMethod*>(pMethods->Get(i));
68 if( p )
69 p->ClearStatics();
70 }
71
72 // #i31510 Init other libs only if Basic isn't running
73 if( GetSbData()->pInst == nullptr )
74 {
75 SbxObject* pParent_ = pBasic->GetParent();
76 if( pParent_ )
77 pBasic = dynamic_cast<StarBASIC*>( pParent_ );
78 if( pBasic )
79 pBasic->ClearAllModuleVars();
80 }
81 }
82
83 return bRet;
84}
85/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Compile()
Definition: sbcomp.cxx:33
std::unique_ptr< SbiImage > pImage
Definition: sbmod.hxx:66
bool IsCompiled() const
Definition: sbxmod.cxx:454
OUString aOUSource
Definition: sbmod.hxx:64
SAL_DLLPRIVATE void RemoveVars()
Definition: sbxmod.cxx:1279
static void ResetError()
Definition: sbxbase.cxx:128
SbxArrayRef pMethods
Definition: sbxobj.hxx:34
const SbxObject * GetParent() const
Definition: sbxvar.hxx:296
void ClearAllModuleVars()
Definition: sbxmod.cxx:1373
void * p
int i
SbiGlobals * GetSbData()
Definition: sbintern.cxx:26
SbiInstance * pInst
Definition: sbintern.hxx:108
SbModule * pCompMod
Definition: sbintern.hxx:123