2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-17 12:30:48 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2006-09-17 09:01:20 +00:00
|
|
|
|
2019-11-08 17:23:15 +01:00
|
|
|
#include <basic/sberrors.hxx>
|
2007-06-27 13:19:50 +00:00
|
|
|
#include <basic/sbx.hxx>
|
2019-11-08 17:23:15 +01:00
|
|
|
#include <basic/sbmeth.hxx>
|
|
|
|
#include <basic/sbmod.hxx>
|
2017-10-09 17:04:39 +03:00
|
|
|
#include <image.hxx>
|
|
|
|
#include <codegen.hxx>
|
|
|
|
#include <parser.hxx>
|
2019-11-08 17:23:15 +01:00
|
|
|
#include <sbintern.hxx>
|
2017-07-07 17:11:57 +02:00
|
|
|
#include <cstddef>
|
2006-11-01 15:13:40 +00:00
|
|
|
#include <limits>
|
2011-01-29 17:12:46 +00:00
|
|
|
#include <algorithm>
|
2019-01-11 11:21:46 +01:00
|
|
|
#include <string_view>
|
2014-11-14 22:52:35 +01:00
|
|
|
#include <osl/diagnose.h>
|
2019-02-28 04:42:42 +01:00
|
|
|
#include <rtl/ustrbuf.hxx>
|
2010-04-16 17:28:52 +02:00
|
|
|
#include <com/sun/star/script/ModuleType.hpp>
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2010-11-19 22:21:03 +01:00
|
|
|
// nInc is the increment size of the buffers
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2020-11-23 22:43:31 +03:00
|
|
|
SbiCodeGen::SbiCodeGen(SbModule& r, SbiParser* p)
|
2020-11-22 16:29:04 +01:00
|
|
|
: pParser(p)
|
|
|
|
, rMod(r)
|
|
|
|
, nLine(0)
|
|
|
|
, nCol(0)
|
|
|
|
, nForLevel(0)
|
|
|
|
, bStmnt(false)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-03 11:47:17 +02:00
|
|
|
sal_uInt32 SbiCodeGen::GetPC() const
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
return aCode.GetSize();
|
|
|
|
}
|
|
|
|
|
2010-11-19 22:21:03 +01:00
|
|
|
// memorize the statement
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
void SbiCodeGen::Statement()
|
|
|
|
{
|
2013-07-17 15:54:13 +02:00
|
|
|
if( pParser->IsCodeCompleting() )
|
2013-07-07 19:43:05 +02:00
|
|
|
return;
|
|
|
|
|
2012-08-03 10:28:32 +09:00
|
|
|
bStmnt = true;
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
nLine = pParser->GetLine();
|
|
|
|
nCol = pParser->GetCol1();
|
|
|
|
|
2010-11-19 22:21:03 +01:00
|
|
|
// #29955 Store the information of the for-loop-layer
|
2018-12-08 17:37:40 +01:00
|
|
|
// in the upper Byte of the column
|
2000-09-18 15:18:56 +00:00
|
|
|
nCol = (nCol & 0xff) + 0x100 * nForLevel;
|
|
|
|
}
|
|
|
|
|
2010-11-19 22:21:03 +01:00
|
|
|
// Mark the beginning of a statement
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
void SbiCodeGen::GenStmnt()
|
|
|
|
{
|
2013-07-17 15:54:13 +02:00
|
|
|
if( pParser->IsCodeCompleting() )
|
2013-07-07 19:43:05 +02:00
|
|
|
return;
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
if( bStmnt )
|
|
|
|
{
|
2012-08-03 10:28:32 +09:00
|
|
|
bStmnt = false;
|
2016-04-05 21:22:43 +02:00
|
|
|
Gen( SbiOpcode::STMNT_, nLine, nCol );
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-19 22:21:03 +01:00
|
|
|
// The Gen-Routines return the offset of the 1. operand,
|
|
|
|
// so that jumps can sink their backchain there.
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2013-07-17 15:54:13 +02:00
|
|
|
if( pParser->IsCodeCompleting() )
|
2013-07-07 19:43:05 +02:00
|
|
|
return 0;
|
|
|
|
|
2009-07-10 14:03:42 +02:00
|
|
|
#ifdef DBG_UTIL
|
2016-04-05 21:22:43 +02:00
|
|
|
if( eOpcode < SbiOpcode::SbOP0_START || eOpcode > SbiOpcode::SbOP0_END )
|
2015-07-27 13:04:00 +02:00
|
|
|
pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "OPCODE1" );
|
2000-09-18 15:18:56 +00:00
|
|
|
#endif
|
|
|
|
GenStmnt();
|
2018-01-15 09:07:14 +01:00
|
|
|
aCode += static_cast<sal_uInt8>(eOpcode);
|
2000-09-18 15:18:56 +00:00
|
|
|
return GetPC();
|
|
|
|
}
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode, sal_uInt32 nOpnd )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2013-07-17 15:54:13 +02:00
|
|
|
if( pParser->IsCodeCompleting() )
|
2013-07-07 19:43:05 +02:00
|
|
|
return 0;
|
|
|
|
|
2009-07-10 14:03:42 +02:00
|
|
|
#ifdef DBG_UTIL
|
2016-04-05 21:22:43 +02:00
|
|
|
if( eOpcode < SbiOpcode::SbOP1_START || eOpcode > SbiOpcode::SbOP1_END )
|
2015-07-27 13:04:00 +02:00
|
|
|
pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "OPCODE2" );
|
2000-09-18 15:18:56 +00:00
|
|
|
#endif
|
|
|
|
GenStmnt();
|
2018-01-15 09:07:14 +01:00
|
|
|
aCode += static_cast<sal_uInt8>(eOpcode);
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 n = GetPC();
|
2000-09-18 15:18:56 +00:00
|
|
|
aCode += nOpnd;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 SbiCodeGen::Gen( SbiOpcode eOpcode, sal_uInt32 nOpnd1, sal_uInt32 nOpnd2 )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2013-07-17 15:54:13 +02:00
|
|
|
if( pParser->IsCodeCompleting() )
|
2013-07-07 19:43:05 +02:00
|
|
|
return 0;
|
|
|
|
|
2009-07-10 14:03:42 +02:00
|
|
|
#ifdef DBG_UTIL
|
2016-04-05 21:22:43 +02:00
|
|
|
if( eOpcode < SbiOpcode::SbOP2_START || eOpcode > SbiOpcode::SbOP2_END )
|
2015-07-27 13:04:00 +02:00
|
|
|
pParser->Error( ERRCODE_BASIC_INTERNAL_ERROR, "OPCODE3" );
|
2000-09-18 15:18:56 +00:00
|
|
|
#endif
|
|
|
|
GenStmnt();
|
2018-01-15 09:07:14 +01:00
|
|
|
aCode += static_cast<sal_uInt8>(eOpcode);
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 n = GetPC();
|
2000-09-18 15:18:56 +00:00
|
|
|
aCode += nOpnd1;
|
|
|
|
aCode += nOpnd2;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2010-11-19 22:21:03 +01:00
|
|
|
// Storing of the created image in the module
|
2000-09-18 15:18:56 +00:00
|
|
|
|
|
|
|
void SbiCodeGen::Save()
|
|
|
|
{
|
2013-07-17 15:54:13 +02:00
|
|
|
if( pParser->IsCodeCompleting() )
|
2013-07-07 19:43:05 +02:00
|
|
|
return;
|
|
|
|
|
2021-05-10 14:14:49 +02:00
|
|
|
std::unique_ptr<SbiImage> p(new SbiImage);
|
2000-09-18 15:18:56 +00:00
|
|
|
rMod.StartDefinitions();
|
2010-11-19 22:21:03 +01:00
|
|
|
// OPTION BASE-Value:
|
2000-09-18 15:18:56 +00:00
|
|
|
p->nDimBase = pParser->nBase;
|
2010-11-19 22:21:03 +01:00
|
|
|
// OPTION take over the EXPLICIT-Flag
|
2000-09-18 15:18:56 +00:00
|
|
|
if( pParser->bExplicit )
|
2015-02-27 11:22:50 +02:00
|
|
|
p->SetFlag( SbiImageFlags::EXPLICIT );
|
2005-03-29 10:48:48 +00:00
|
|
|
|
|
|
|
int nIfaceCount = 0;
|
2015-07-20 09:21:24 +02:00
|
|
|
if( rMod.mnType == css::script::ModuleType::CLASS )
|
2004-11-02 10:53:16 +00:00
|
|
|
{
|
2010-03-02 12:39:31 +00:00
|
|
|
rMod.bIsProxyModule = true;
|
2015-02-27 11:22:50 +02:00
|
|
|
p->SetFlag( SbiImageFlags::CLASSMODULE );
|
2012-01-15 16:15:08 +01:00
|
|
|
GetSbData()->pClassFac->AddClassModule( &rMod );
|
2005-03-29 10:48:48 +00:00
|
|
|
|
|
|
|
nIfaceCount = pParser->aIfaceVector.size();
|
2010-08-05 11:52:07 +02:00
|
|
|
if( !rMod.pClassData )
|
2019-12-03 15:02:05 +02:00
|
|
|
rMod.pClassData.reset(new SbClassData);
|
2005-03-29 10:48:48 +00:00
|
|
|
if( nIfaceCount )
|
|
|
|
{
|
|
|
|
for( int i = 0 ; i < nIfaceCount ; i++ )
|
|
|
|
{
|
2012-11-06 23:34:23 -06:00
|
|
|
const OUString& rIfaceName = pParser->aIfaceVector[i];
|
2005-03-29 10:48:48 +00:00
|
|
|
SbxVariable* pIfaceVar = new SbxVariable( SbxVARIANT );
|
|
|
|
pIfaceVar->SetName( rIfaceName );
|
2016-10-05 22:00:51 +02:00
|
|
|
SbxArray* pIfaces = rMod.pClassData->mxIfaces.get();
|
2021-03-08 12:29:39 +03:00
|
|
|
pIfaces->Insert( pIfaceVar, pIfaces->Count() );
|
2005-03-29 10:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-05 11:52:07 +02:00
|
|
|
|
|
|
|
rMod.pClassData->maRequiredTypes = pParser->aRequiredTypes;
|
2004-11-02 10:53:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-15 16:15:08 +01:00
|
|
|
GetSbData()->pClassFac->RemoveClassModule( &rMod );
|
2010-03-02 12:39:31 +00:00
|
|
|
// Only a ClassModule can revert to Normal
|
2015-07-20 09:21:24 +02:00
|
|
|
if ( rMod.mnType == css::script::ModuleType::CLASS )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2015-07-20 09:21:24 +02:00
|
|
|
rMod.mnType = css::script::ModuleType::NORMAL;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2010-03-02 12:39:31 +00:00
|
|
|
rMod.bIsProxyModule = false;
|
2004-11-02 10:53:16 +00:00
|
|
|
}
|
2010-08-05 11:52:07 +02:00
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
// GlobalCode-Flag
|
|
|
|
if( pParser->HasGlobalCode() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2015-02-27 11:22:50 +02:00
|
|
|
p->SetFlag( SbiImageFlags::INITCODE );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2017-05-13 15:23:33 +02:00
|
|
|
// The entry points:
|
2000-09-18 15:18:56 +00:00
|
|
|
for( SbiSymDef* pDef = pParser->aPublics.First(); pDef;
|
2012-11-03 09:07:25 -05:00
|
|
|
pDef = pParser->aPublics.Next() )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
SbiProcDef* pProc = pDef->GetProcDef();
|
2004-03-17 12:32:41 +00:00
|
|
|
if( pProc && pProc->IsDefined() )
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2012-11-06 23:34:23 -06:00
|
|
|
OUString aProcName = pProc->GetName();
|
2018-07-26 17:16:16 +02:00
|
|
|
OUStringBuffer aIfaceProcName;
|
2012-11-06 23:34:23 -06:00
|
|
|
OUString aIfaceName;
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt16 nPassCount = 1;
|
2005-03-29 10:48:48 +00:00
|
|
|
if( nIfaceCount )
|
2004-11-02 10:53:16 +00:00
|
|
|
{
|
2015-06-25 12:35:50 +02:00
|
|
|
int nPropPrefixFound = aProcName.indexOf("Property ");
|
2012-11-06 23:34:23 -06:00
|
|
|
OUString aPureProcName = aProcName;
|
|
|
|
OUString aPropPrefix;
|
2005-03-29 10:48:48 +00:00
|
|
|
if( nPropPrefixFound == 0 )
|
|
|
|
{
|
2012-11-06 23:34:23 -06:00
|
|
|
aPropPrefix = aProcName.copy( 0, 13 ); // 13 == Len( "Property ?et " )
|
|
|
|
aPureProcName = aProcName.copy( 13 );
|
2005-03-29 10:48:48 +00:00
|
|
|
}
|
|
|
|
for( int i = 0 ; i < nIfaceCount ; i++ )
|
2004-11-02 10:53:16 +00:00
|
|
|
{
|
2012-11-06 23:34:23 -06:00
|
|
|
const OUString& rIfaceName = pParser->aIfaceVector[i];
|
|
|
|
int nFound = aPureProcName.indexOf( rIfaceName );
|
2017-05-19 11:25:32 +02:00
|
|
|
if( nFound == 0 && aPureProcName[rIfaceName.getLength()] == '_' )
|
2005-03-29 10:48:48 +00:00
|
|
|
{
|
|
|
|
if( nPropPrefixFound == 0 )
|
2012-11-06 23:34:23 -06:00
|
|
|
{
|
2018-07-26 17:16:16 +02:00
|
|
|
aIfaceProcName.append(aPropPrefix);
|
2012-11-06 23:34:23 -06:00
|
|
|
}
|
2021-01-28 12:38:01 +02:00
|
|
|
aIfaceProcName.append(aPureProcName.subView(rIfaceName.getLength() + 1) );
|
2005-03-29 10:48:48 +00:00
|
|
|
aIfaceName = rIfaceName;
|
|
|
|
nPassCount = 2;
|
2004-11-02 10:53:16 +00:00
|
|
|
break;
|
2005-03-29 10:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 10:10:36 +01:00
|
|
|
SbMethod* pMeth = nullptr;
|
2011-01-10 14:40:57 +01:00
|
|
|
for( sal_uInt16 nPass = 0 ; nPass < nPassCount ; nPass++ )
|
2005-03-29 10:48:48 +00:00
|
|
|
{
|
|
|
|
if( nPass == 1 )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2018-07-26 17:16:16 +02:00
|
|
|
aProcName = aIfaceProcName.toString();
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2005-03-29 10:48:48 +00:00
|
|
|
PropertyMode ePropMode = pProc->getPropertyMode();
|
2015-06-04 08:29:58 +02:00
|
|
|
if( ePropMode != PropertyMode::NONE )
|
2005-03-29 10:48:48 +00:00
|
|
|
{
|
2006-06-19 16:41:04 +00:00
|
|
|
SbxDataType ePropType = SbxEMPTY;
|
2005-03-29 10:48:48 +00:00
|
|
|
switch( ePropMode )
|
2004-11-02 10:53:16 +00:00
|
|
|
{
|
2015-06-04 08:29:58 +02:00
|
|
|
case PropertyMode::Get:
|
2012-11-06 23:34:23 -06:00
|
|
|
ePropType = pProc->GetType();
|
|
|
|
break;
|
2015-06-04 08:29:58 +02:00
|
|
|
case PropertyMode::Let:
|
2012-11-06 23:34:23 -06:00
|
|
|
{
|
|
|
|
// type == type of first parameter
|
|
|
|
ePropType = SbxVARIANT; // Default
|
|
|
|
SbiSymPool* pPool = &pProc->GetParams();
|
|
|
|
if( pPool->GetSize() > 1 )
|
2004-11-02 10:53:16 +00:00
|
|
|
{
|
2012-11-06 23:34:23 -06:00
|
|
|
SbiSymDef* pPar = pPool->Get( 1 );
|
|
|
|
if( pPar )
|
2005-03-29 10:48:48 +00:00
|
|
|
{
|
2012-11-06 23:34:23 -06:00
|
|
|
ePropType = pPar->GetType();
|
2005-03-29 10:48:48 +00:00
|
|
|
}
|
2004-11-02 10:53:16 +00:00
|
|
|
}
|
2012-11-06 23:34:23 -06:00
|
|
|
break;
|
2004-11-02 10:53:16 +00:00
|
|
|
}
|
2015-06-04 08:29:58 +02:00
|
|
|
case PropertyMode::Set:
|
2012-11-06 23:34:23 -06:00
|
|
|
ePropType = SbxOBJECT;
|
|
|
|
break;
|
2013-02-19 14:54:32 -06:00
|
|
|
default:
|
|
|
|
OSL_FAIL("Illegal PropertyMode");
|
2012-11-06 23:34:23 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
OUString aPropName = pProc->GetPropName();
|
2005-03-29 10:48:48 +00:00
|
|
|
if( nPass == 1 )
|
2012-11-06 23:34:23 -06:00
|
|
|
{
|
|
|
|
aPropName = aPropName.copy( aIfaceName.getLength() + 1 );
|
|
|
|
}
|
2011-03-21 09:32:19 +00:00
|
|
|
rMod.GetProcedureProperty( aPropName, ePropType );
|
2004-11-02 10:53:16 +00:00
|
|
|
}
|
2005-03-29 10:48:48 +00:00
|
|
|
if( nPass == 1 )
|
|
|
|
{
|
2011-03-21 09:32:19 +00:00
|
|
|
rMod.GetIfaceMapperMethod( aProcName, pMeth );
|
2005-03-29 10:48:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pMeth = rMod.GetMethod( aProcName, pProc->GetType() );
|
2004-03-17 12:32:41 +00:00
|
|
|
|
2005-03-29 10:48:48 +00:00
|
|
|
if( !pProc->IsPublic() )
|
2012-11-06 23:34:23 -06:00
|
|
|
{
|
2015-07-27 11:31:24 +02:00
|
|
|
pMeth->SetFlag( SbxFlagBits::Private );
|
2012-11-06 23:34:23 -06:00
|
|
|
}
|
2010-08-06 09:35:51 +02:00
|
|
|
// Declare? -> Hidden
|
2012-11-06 23:34:23 -06:00
|
|
|
if( !pProc->GetLib().isEmpty())
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2015-07-27 11:31:24 +02:00
|
|
|
pMeth->SetFlag( SbxFlagBits::Hidden );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2005-03-29 10:48:48 +00:00
|
|
|
pMeth->nStart = pProc->GetAddr();
|
|
|
|
pMeth->nLine1 = pProc->GetLine1();
|
|
|
|
pMeth->nLine2 = pProc->GetLine2();
|
2010-11-19 22:21:03 +01:00
|
|
|
// The parameter:
|
2005-03-29 10:48:48 +00:00
|
|
|
SbxInfo* pInfo = pMeth->GetInfo();
|
2012-11-06 23:34:23 -06:00
|
|
|
OUString aHelpFile, aComment;
|
2014-03-17 17:18:08 +01:00
|
|
|
sal_uInt32 nHelpId = 0;
|
2005-03-29 10:48:48 +00:00
|
|
|
if( pInfo )
|
|
|
|
{
|
2010-11-19 22:21:03 +01:00
|
|
|
// Rescue the additional data
|
2005-03-29 10:48:48 +00:00
|
|
|
aHelpFile = pInfo->GetHelpFile();
|
|
|
|
aComment = pInfo->GetComment();
|
|
|
|
nHelpId = pInfo->GetHelpId();
|
|
|
|
}
|
2010-11-19 22:21:03 +01:00
|
|
|
// And reestablish the parameter list
|
2005-03-29 10:48:48 +00:00
|
|
|
pInfo = new SbxInfo( aHelpFile, nHelpId );
|
|
|
|
pInfo->SetComment( aComment );
|
|
|
|
SbiSymPool* pPool = &pProc->GetParams();
|
2010-11-19 22:21:03 +01:00
|
|
|
// The first element is always the value of the function!
|
2011-01-10 14:40:57 +01:00
|
|
|
for( sal_uInt16 i = 1; i < pPool->GetSize(); i++ )
|
2005-03-29 10:48:48 +00:00
|
|
|
{
|
|
|
|
SbiSymDef* pPar = pPool->Get( i );
|
|
|
|
SbxDataType t = pPar->GetType();
|
|
|
|
if( !pPar->IsByVal() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2018-01-15 09:07:14 +01:00
|
|
|
t = static_cast<SbxDataType>( t | SbxBYREF );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2005-03-29 10:48:48 +00:00
|
|
|
if( pPar->GetDims() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2018-01-15 09:07:14 +01:00
|
|
|
t = static_cast<SbxDataType>( t | SbxARRAY );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2010-11-19 22:21:03 +01:00
|
|
|
// #33677 hand-over an Optional-Info
|
2015-07-27 11:31:24 +02:00
|
|
|
SbxFlagBits nFlags = SbxFlagBits::Read;
|
2005-03-29 10:48:48 +00:00
|
|
|
if( pPar->IsOptional() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2015-07-27 11:31:24 +02:00
|
|
|
nFlags |= SbxFlagBits::Optional;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2005-03-29 10:48:48 +00:00
|
|
|
pInfo->AddParam( pPar->GetName(), t, nFlags );
|
2005-01-28 15:05:45 +00:00
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32 nUserData = 0;
|
|
|
|
sal_uInt16 nDefaultId = pPar->GetDefaultId();
|
2005-03-29 10:48:48 +00:00
|
|
|
if( nDefaultId )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2005-03-29 10:48:48 +00:00
|
|
|
nUserData |= nDefaultId;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2005-03-29 10:48:48 +00:00
|
|
|
if( pPar->IsParamArray() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2005-03-29 10:48:48 +00:00
|
|
|
nUserData |= PARAM_INFO_PARAMARRAY;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2011-03-25 10:40:25 +01:00
|
|
|
if( pPar->IsWithBrackets() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2011-03-25 10:40:25 +01:00
|
|
|
nUserData |= PARAM_INFO_WITHBRACKETS;
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2015-11-10 10:10:36 +01:00
|
|
|
SbxParamInfo* pParam = nullptr;
|
2005-03-29 10:48:48 +00:00
|
|
|
if( nUserData )
|
|
|
|
{
|
2015-03-26 15:27:34 +01:00
|
|
|
pParam = const_cast<SbxParamInfo*>(pInfo->GetParam( i ));
|
2014-05-13 20:38:21 +01:00
|
|
|
}
|
|
|
|
if( pParam )
|
|
|
|
{
|
2005-03-29 10:48:48 +00:00
|
|
|
pParam->nUserData = nUserData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pMeth->SetInfo( pInfo );
|
2004-03-17 12:32:41 +00:00
|
|
|
}
|
2005-03-29 10:48:48 +00:00
|
|
|
} // for( iPass...
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 22:43:31 +03:00
|
|
|
if (aCode.GetErrCode())
|
|
|
|
{
|
|
|
|
pParser->Error(aCode.GetErrCode(), aCode.GetErrMessage());
|
|
|
|
}
|
2010-11-19 22:21:03 +01:00
|
|
|
// The code
|
2020-11-23 22:43:31 +03:00
|
|
|
p->AddCode(aCode.GetBuffer());
|
2000-09-18 15:18:56 +00:00
|
|
|
|
2010-11-19 22:21:03 +01:00
|
|
|
// The global StringPool. 0 is not occupied.
|
2000-09-18 15:18:56 +00:00
|
|
|
SbiStringPool* pPool = &pParser->aGblStrings;
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt16 nSize = pPool->GetSize();
|
2000-09-18 15:18:56 +00:00
|
|
|
p->MakeStrings( nSize );
|
2019-12-09 13:06:03 +03:00
|
|
|
sal_uInt32 i;
|
2000-09-18 15:18:56 +00:00
|
|
|
for( i = 1; i <= nSize; i++ )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2000-09-18 15:18:56 +00:00
|
|
|
p->AddString( pPool->Find( i ) );
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2010-11-19 22:21:03 +01:00
|
|
|
// Insert types
|
2021-03-08 12:29:39 +03:00
|
|
|
sal_uInt32 nCount = pParser->rTypeArray->Count();
|
2000-09-18 15:18:56 +00:00
|
|
|
for (i = 0; i < nCount; i++)
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2021-03-08 12:29:39 +03:00
|
|
|
p->AddType(static_cast<SbxObject *>(pParser->rTypeArray->Get(i)));
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2004-11-15 15:34:34 +00:00
|
|
|
// Insert enum objects
|
2021-03-08 12:29:39 +03:00
|
|
|
nCount = pParser->rEnumArray->Count();
|
2004-11-15 15:34:34 +00:00
|
|
|
for (i = 0; i < nCount; i++)
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2021-03-08 12:29:39 +03:00
|
|
|
p->AddEnum(static_cast<SbxObject *>(pParser->rEnumArray->Get(i)));
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
if( !p->IsError() )
|
2012-11-03 09:07:25 -05:00
|
|
|
{
|
2021-05-10 14:14:49 +02:00
|
|
|
rMod.pImage = std::move(p);
|
2012-11-03 09:07:25 -05:00
|
|
|
}
|
2000-09-18 15:18:56 +00:00
|
|
|
rMod.EndDefinitions();
|
|
|
|
}
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
namespace {
|
|
|
|
|
2006-11-01 15:13:40 +00:00
|
|
|
template < class T >
|
|
|
|
class PCodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
2006-11-03 14:11:10 +00:00
|
|
|
virtual ~PCodeVisitor();
|
|
|
|
|
2017-06-08 12:03:12 +02:00
|
|
|
virtual void start( const sal_uInt8* pStart ) = 0;
|
2006-11-03 14:11:10 +00:00
|
|
|
virtual void processOpCode0( SbiOpcode eOp ) = 0;
|
|
|
|
virtual void processOpCode1( SbiOpcode eOp, T nOp1 ) = 0;
|
|
|
|
virtual void processOpCode2( SbiOpcode eOp, T nOp1, T nOp2 ) = 0;
|
|
|
|
virtual bool processParams() = 0;
|
2006-11-01 15:13:40 +00:00
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
|
|
|
|
2006-11-03 14:11:10 +00:00
|
|
|
template <class T> PCodeVisitor< T >::~PCodeVisitor()
|
|
|
|
{}
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
namespace {
|
|
|
|
|
2006-11-01 15:13:40 +00:00
|
|
|
template <class T>
|
|
|
|
class PCodeBufferWalker
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
T m_nBytes;
|
2017-06-08 12:03:12 +02:00
|
|
|
const sal_uInt8* m_pCode;
|
|
|
|
static T readParam( sal_uInt8 const *& pCode )
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
|
|
|
T nOp1=0;
|
2017-07-07 17:11:57 +02:00
|
|
|
for ( std::size_t i=0; i<sizeof( T ); ++i )
|
2006-11-01 15:13:40 +00:00
|
|
|
nOp1 |= *pCode++ << ( i * 8);
|
|
|
|
return nOp1;
|
|
|
|
}
|
|
|
|
public:
|
2017-06-08 12:03:12 +02:00
|
|
|
PCodeBufferWalker( const sal_uInt8* pCode, T nBytes ): m_nBytes( nBytes ), m_pCode( pCode )
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
void visitBuffer( PCodeVisitor< T >& visitor )
|
|
|
|
{
|
2017-06-08 12:03:12 +02:00
|
|
|
const sal_uInt8* pCode = m_pCode;
|
2006-11-01 15:13:40 +00:00
|
|
|
if ( !pCode )
|
|
|
|
return;
|
2017-06-08 12:03:12 +02:00
|
|
|
const sal_uInt8* pEnd = pCode + m_nBytes;
|
2006-11-01 15:13:40 +00:00
|
|
|
visitor.start( m_pCode );
|
|
|
|
T nOp1 = 0, nOp2 = 0;
|
|
|
|
for( ; pCode < pEnd; )
|
|
|
|
{
|
2018-01-15 09:07:14 +01:00
|
|
|
SbiOpcode eOp = static_cast<SbiOpcode>(*pCode++);
|
2006-11-01 15:13:40 +00:00
|
|
|
|
2016-04-05 21:22:43 +02:00
|
|
|
if ( eOp <= SbiOpcode::SbOP0_END )
|
2006-11-01 15:13:40 +00:00
|
|
|
visitor.processOpCode0( eOp );
|
2016-04-05 21:22:43 +02:00
|
|
|
else if( eOp >= SbiOpcode::SbOP1_START && eOp <= SbiOpcode::SbOP1_END )
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
|
|
|
if ( visitor.processParams() )
|
|
|
|
nOp1 = readParam( pCode );
|
|
|
|
else
|
|
|
|
pCode += sizeof( T );
|
|
|
|
visitor.processOpCode1( eOp, nOp1 );
|
|
|
|
}
|
2016-04-05 21:22:43 +02:00
|
|
|
else if( eOp >= SbiOpcode::SbOP2_START && eOp <= SbiOpcode::SbOP2_END )
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
|
|
|
if ( visitor.processParams() )
|
|
|
|
{
|
|
|
|
nOp1 = readParam( pCode );
|
|
|
|
nOp2 = readParam( pCode );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pCode += ( sizeof( T ) * 2 );
|
|
|
|
visitor.processOpCode2( eOp, nOp1, nOp2 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template < class T, class S >
|
|
|
|
class OffSetAccumulator : public PCodeVisitor< T >
|
|
|
|
{
|
|
|
|
T m_nNumOp0;
|
|
|
|
T m_nNumSingleParams;
|
|
|
|
T m_nNumDoubleParams;
|
|
|
|
public:
|
|
|
|
|
|
|
|
OffSetAccumulator() : m_nNumOp0(0), m_nNumSingleParams(0), m_nNumDoubleParams(0){}
|
2017-06-08 12:03:12 +02:00
|
|
|
virtual void start( const sal_uInt8* /*pStart*/ ) override {}
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void processOpCode0( SbiOpcode /*eOp*/ ) override { ++m_nNumOp0; }
|
|
|
|
virtual void processOpCode1( SbiOpcode /*eOp*/, T /*nOp1*/ ) override { ++m_nNumSingleParams; }
|
|
|
|
virtual void processOpCode2( SbiOpcode /*eOp*/, T /*nOp1*/, T /*nOp2*/ ) override { ++m_nNumDoubleParams; }
|
2006-11-01 15:13:40 +00:00
|
|
|
S offset()
|
|
|
|
{
|
2018-01-31 10:05:57 +03:00
|
|
|
typedef decltype(T(1) + S(1)) larger_t; // type capable to hold both value ranges of T and S
|
2006-11-01 15:13:40 +00:00
|
|
|
T result = 0 ;
|
|
|
|
static const S max = std::numeric_limits< S >::max();
|
|
|
|
result = m_nNumOp0 + ( ( sizeof(S) + 1 ) * m_nNumSingleParams ) + ( (( sizeof(S) * 2 )+ 1 ) * m_nNumDoubleParams );
|
2018-01-31 10:05:57 +03:00
|
|
|
return std::min<larger_t>(max, result);
|
2006-11-01 15:13:40 +00:00
|
|
|
}
|
2018-01-31 10:05:57 +03:00
|
|
|
virtual bool processParams() override { return false; }
|
2006-11-01 15:13:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template < class T, class S >
|
|
|
|
class BufferTransformer : public PCodeVisitor< T >
|
|
|
|
{
|
2017-06-08 12:03:12 +02:00
|
|
|
const sal_uInt8* m_pStart;
|
2006-11-01 15:13:40 +00:00
|
|
|
SbiBuffer m_ConvertedBuf;
|
|
|
|
public:
|
2020-11-23 22:43:31 +03:00
|
|
|
BufferTransformer():m_pStart(nullptr) {}
|
2017-06-08 12:03:12 +02:00
|
|
|
virtual void start( const sal_uInt8* pStart ) override { m_pStart = pStart; }
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void processOpCode0( SbiOpcode eOp ) override
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
2018-01-15 09:07:14 +01:00
|
|
|
m_ConvertedBuf += static_cast<sal_uInt8>(eOp);
|
2006-11-01 15:13:40 +00:00
|
|
|
}
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void processOpCode1( SbiOpcode eOp, T nOp1 ) override
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
2018-01-15 09:07:14 +01:00
|
|
|
m_ConvertedBuf += static_cast<sal_uInt8>(eOp);
|
2006-11-01 15:13:40 +00:00
|
|
|
switch( eOp )
|
|
|
|
{
|
2016-04-05 21:22:43 +02:00
|
|
|
case SbiOpcode::JUMP_:
|
|
|
|
case SbiOpcode::JUMPT_:
|
|
|
|
case SbiOpcode::JUMPF_:
|
|
|
|
case SbiOpcode::GOSUB_:
|
|
|
|
case SbiOpcode::CASEIS_:
|
|
|
|
case SbiOpcode::RETURN_:
|
|
|
|
case SbiOpcode::ERRHDL_:
|
|
|
|
case SbiOpcode::TESTFOR_:
|
2006-11-03 14:11:10 +00:00
|
|
|
nOp1 = static_cast<T>( convertBufferOffSet(m_pStart, nOp1) );
|
2006-11-01 15:13:40 +00:00
|
|
|
break;
|
2016-04-05 21:22:43 +02:00
|
|
|
case SbiOpcode::RESUME_:
|
2006-11-01 15:13:40 +00:00
|
|
|
if ( nOp1 > 1 )
|
2006-11-03 14:11:10 +00:00
|
|
|
nOp1 = static_cast<T>( convertBufferOffSet(m_pStart, nOp1) );
|
2006-11-01 15:13:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-02-25 17:41:32 +01:00
|
|
|
break;
|
2006-11-01 15:13:40 +00:00
|
|
|
|
|
|
|
}
|
2015-03-29 15:13:23 +02:00
|
|
|
m_ConvertedBuf += static_cast<S>(nOp1);
|
2006-11-01 15:13:40 +00:00
|
|
|
}
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void processOpCode2( SbiOpcode eOp, T nOp1, T nOp2 ) override
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
2018-01-15 09:07:14 +01:00
|
|
|
m_ConvertedBuf += static_cast<sal_uInt8>(eOp);
|
2018-11-06 10:16:38 +02:00
|
|
|
if ( eOp == SbiOpcode::CASEIS_ && nOp1 )
|
|
|
|
nOp1 = static_cast<T>( convertBufferOffSet(m_pStart, nOp1) );
|
2015-03-29 15:13:23 +02:00
|
|
|
m_ConvertedBuf += static_cast<S>(nOp1);
|
|
|
|
m_ConvertedBuf += static_cast<S>(nOp2);
|
2006-11-01 15:13:40 +00:00
|
|
|
|
|
|
|
}
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual bool processParams() override { return true; }
|
2006-11-01 15:13:40 +00:00
|
|
|
// yeuch, careful here, you can only call
|
|
|
|
// GetBuffer on the returned SbiBuffer once, also
|
|
|
|
// you (as the caller) get to own the memory
|
|
|
|
SbiBuffer& buffer()
|
|
|
|
{
|
|
|
|
return m_ConvertedBuf;
|
|
|
|
}
|
2017-06-08 12:03:12 +02:00
|
|
|
static S convertBufferOffSet( const sal_uInt8* pStart, T nOp1 )
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
|
|
|
PCodeBufferWalker< T > aBuff( pStart, nOp1);
|
|
|
|
OffSetAccumulator< T, S > aVisitor;
|
|
|
|
aBuff.visitBuffer( aVisitor );
|
|
|
|
return aVisitor.offset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt32
|
2017-07-20 10:08:03 +02:00
|
|
|
SbiCodeGen::calcNewOffSet( sal_uInt8 const * pCode, sal_uInt16 nOffset )
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
return BufferTransformer< sal_uInt16, sal_uInt32 >::convertBufferOffSet( pCode, nOffset );
|
2006-11-01 15:13:40 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
sal_uInt16
|
2017-07-20 10:08:03 +02:00
|
|
|
SbiCodeGen::calcLegacyOffSet( sal_uInt8 const * pCode, sal_uInt32 nOffset )
|
2006-11-01 15:13:40 +00:00
|
|
|
{
|
2011-01-10 14:40:57 +01:00
|
|
|
return BufferTransformer< sal_uInt32, sal_uInt16 >::convertBufferOffSet( pCode, nOffset );
|
2006-11-01 15:13:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class S>
|
|
|
|
void
|
|
|
|
PCodeBuffConvertor<T,S>::convert()
|
|
|
|
{
|
|
|
|
PCodeBufferWalker< T > aBuf( m_pStart, m_nSize );
|
|
|
|
BufferTransformer< T, S > aTrnsfrmer;
|
|
|
|
aBuf.visitBuffer( aTrnsfrmer );
|
2020-11-23 22:43:31 +03:00
|
|
|
// TODO: handle buffer errors
|
|
|
|
m_aCnvtdBuf = aTrnsfrmer.buffer().GetBuffer();
|
2006-11-01 15:13:40 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 14:40:57 +01:00
|
|
|
template class PCodeBuffConvertor< sal_uInt16, sal_uInt32 >;
|
|
|
|
template class PCodeBuffConvertor< sal_uInt32, sal_uInt16 >;
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|