Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / basic / source / inc / codegen.hxx
blob246ff167ce7934a188cb011db7525b596f95d07a
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 _CODEGEN_HXX
21 #define _CODEGEN_HXX
23 class SbiParser;
24 class SbModule;
25 #include "opcodes.hxx"
26 #include "buffer.hxx"
28 class SbiCodeGen {
29 SbiParser* pParser; // for error messages, line, column etc.
30 SbModule& rMod;
31 SbiBuffer aCode;
32 short nLine, nCol; // for stmnt command
33 short nForLevel; // #29955
34 bool bStmnt; // true: statement-opcode is pending
35 public:
36 SbiCodeGen( SbModule&, SbiParser*, short );
37 SbiParser* GetParser() { return pParser; }
38 SbModule& GetModule() { return rMod; }
39 sal_uInt32 Gen( SbiOpcode );
40 sal_uInt32 Gen( SbiOpcode, sal_uInt32 );
41 sal_uInt32 Gen( SbiOpcode, sal_uInt32, sal_uInt32 );
42 void Patch( sal_uInt32 o, sal_uInt32 v ){ aCode.Patch( o, v ); }
43 void BackChain( sal_uInt32 off ) { aCode.Chain( off ); }
44 void Statement();
45 void GenStmnt(); // create statement-opcode maybe
46 sal_uInt32 GetPC();
47 sal_uInt32 GetOffset() { return GetPC() + 1; }
48 void Save();
50 // #29955 service for-loop-level
51 void IncForLevel( void ) { nForLevel++; }
52 void DecForLevel( void ) { nForLevel--; }
54 static sal_uInt32 calcNewOffSet( sal_uInt8* pCode, sal_uInt16 nOffset );
55 static sal_uInt16 calcLegacyOffSet( sal_uInt8* pCode, sal_uInt32 nOffset );
59 template < class T, class S >
60 class PCodeBuffConvertor
62 T m_nSize; //
63 sal_uInt8* m_pStart;
64 sal_uInt8* m_pCnvtdBuf;
65 S m_nCnvtdSize; //
67 // Disable usual copying symantics and bodgy default ctor
68 PCodeBuffConvertor();
69 PCodeBuffConvertor(const PCodeBuffConvertor& );
70 PCodeBuffConvertor& operator = ( const PCodeBuffConvertor& );
71 public:
72 PCodeBuffConvertor( sal_uInt8* pCode, T nSize ): m_nSize( nSize ), m_pStart( pCode ), m_pCnvtdBuf( NULL ), m_nCnvtdSize( 0 ){ convert(); }
73 S GetSize(){ return m_nCnvtdSize; }
74 void convert();
75 // Caller owns the buffer returned
76 sal_uInt8* GetBuffer() { return m_pCnvtdBuf; }
79 // #111897 PARAM_INFO flags start at 0x00010000 to not
80 // conflict with DefaultId in SbxParamInfo::nUserData
81 #define PARAM_INFO_PARAMARRAY 0x0010000
82 #define PARAM_INFO_WITHBRACKETS 0x0020000
84 #endif
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */