LibreOffice Module basic (master) 1
codegen.hxx
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#pragma once
21
22#include "opcodes.hxx"
23#include "buffer.hxx"
24
25class SbiParser;
26class SbModule;
27
29 SbiParser* pParser; // for error messages, line, column etc.
32 short nLine, nCol; // for stmnt command
33 short nForLevel; // #29955
34 bool bStmnt; // true: statement-opcode is pending
35
36public:
39 SbModule& GetModule() { return rMod; }
40 sal_uInt32 Gen( SbiOpcode );
41 sal_uInt32 Gen( SbiOpcode, sal_uInt32 );
42 sal_uInt32 Gen( SbiOpcode, sal_uInt32, sal_uInt32 );
43 void Patch( sal_uInt32 o, sal_uInt32 v ){ aCode.Patch( o, v ); }
44 void BackChain( sal_uInt32 off ) { aCode.Chain( off ); }
45 void Statement();
46 void GenStmnt(); // create statement-opcode maybe
47 sal_uInt32 GetPC() const;
48 sal_uInt32 GetOffset() const { return GetPC() + 1; }
49 void Save();
50
51 // #29955 service for-loop-level
52 void IncForLevel() { nForLevel++; }
53 void DecForLevel() { nForLevel--; }
54
55 static sal_uInt32 calcNewOffSet( sal_uInt8 const * pCode, sal_uInt16 nOffset );
56 static sal_uInt16 calcLegacyOffSet( sal_uInt8 const * pCode, sal_uInt32 nOffset );
57
58};
59
60template < class T, class S >
62{
65 std::vector<sal_uInt8> m_aCnvtdBuf;
66
69public:
70 PCodeBuffConvertor(const sal_uInt8* pCode, T nSize)
71 : m_nSize(nSize)
72 , m_pStart(pCode)
73 {
74 convert();
75 }
76 void convert();
77 // pass ownership
78 std::vector<sal_uInt8>&& GetBuffer() { return std::move(m_aCnvtdBuf); }
79};
80
81// #111897 PARAM_INFO flags start at 0x00010000 to not
82// conflict with DefaultId in SbxParamInfo::nUserData
83#define PARAM_INFO_PARAMARRAY 0x0010000
84#define PARAM_INFO_WITHBRACKETS 0x0020000
85
86/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< sal_uInt8 > && GetBuffer()
Definition: codegen.hxx:78
std::vector< sal_uInt8 > m_aCnvtdBuf
Definition: codegen.hxx:65
PCodeBuffConvertor & operator=(const PCodeBuffConvertor &)=delete
const sal_uInt8 * m_pStart
Definition: codegen.hxx:64
PCodeBuffConvertor(const sal_uInt8 *pCode, T nSize)
Definition: codegen.hxx:70
PCodeBuffConvertor(const PCodeBuffConvertor &)=delete
void Chain(sal_uInt32)
Definition: buffer.cxx:76
void Patch(sal_uInt32, sal_uInt32)
Definition: buffer.cxx:64
SbiParser * GetParser()
Definition: codegen.hxx:38
sal_uInt32 GetOffset() const
Definition: codegen.hxx:48
SbiCodeGen(SbModule &, SbiParser *)
Definition: codegen.cxx:39
void Patch(sal_uInt32 o, sal_uInt32 v)
Definition: codegen.hxx:43
void Save()
Definition: codegen.cxx:137
void DecForLevel()
Definition: codegen.hxx:53
static sal_uInt32 calcNewOffSet(sal_uInt8 const *pCode, sal_uInt16 nOffset)
Definition: codegen.cxx:560
sal_uInt32 Gen(SbiOpcode)
Definition: codegen.cxx:88
bool bStmnt
Definition: codegen.hxx:34
short nCol
Definition: codegen.hxx:32
void BackChain(sal_uInt32 off)
Definition: codegen.hxx:44
static sal_uInt16 calcLegacyOffSet(sal_uInt8 const *pCode, sal_uInt32 nOffset)
Definition: codegen.cxx:566
SbiBuffer aCode
Definition: codegen.hxx:31
short nForLevel
Definition: codegen.hxx:33
void GenStmnt()
Definition: codegen.cxx:73
void IncForLevel()
Definition: codegen.hxx:52
SbModule & GetModule()
Definition: codegen.hxx:39
sal_uInt32 GetPC() const
Definition: codegen.cxx:49
short nLine
Definition: codegen.hxx:32
SbiParser * pParser
Definition: codegen.hxx:29
SbModule & rMod
Definition: codegen.hxx:30
void Statement()
Definition: codegen.cxx:56
float v
SbiOpcode
Definition: opcodes.hxx:25
unsigned char sal_uInt8