xref: /AOO41X/main/basic/source/inc/codegen.hxx (revision 234bd5c559aaf7abbd02d045859137b774cd8b34)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CODEGEN_HXX
25 #define _CODEGEN_HXX
26 
27 class SbiImage;
28 class SbiParser;
29 class SbModule;
30 #include "opcodes.hxx"
31 #include "buffer.hxx"
32 
33 class SbiCodeGen {              // Code-Erzeugung:
34     SbiParser* pParser;         // fuer Fehlermeldungen, Line, Column etc.
35     SbModule& rMod;             // aktuelles Modul
36     SbiBuffer aCode;                // Code-Puffer
37     short  nLine, nCol;         // Zeile, Spalte fuer Stmnt-Befehl
38     short  nForLevel;           // #29955 for-Schleifen-Ebene
39     sal_Bool bStmnt;                // sal_True: Statement-Opcode liegt an
40 public:
41     SbiCodeGen( SbModule&, SbiParser*, short );
GetParser()42     SbiParser* GetParser() { return pParser; }
GetModule()43     SbModule& GetModule() { return rMod; }
44     sal_uInt32 Gen( SbiOpcode );
45     sal_uInt32 Gen( SbiOpcode, sal_uInt32 );
46     sal_uInt32 Gen( SbiOpcode, sal_uInt32, sal_uInt32 );
Patch(sal_uInt32 o,sal_uInt32 v)47     void Patch( sal_uInt32 o, sal_uInt32 v ){ aCode.Patch( o, v ); }
BackChain(sal_uInt32 off)48     void BackChain( sal_uInt32 off )    { aCode.Chain( off );  }
49     void Statement();
50     void GenStmnt();            // evtl. Statement-Opcode erzeugen
51     sal_uInt32 GetPC();
GetOffset()52     sal_uInt32 GetOffset()              { return GetPC() + 1; }
53     void Save();
54 
55     // #29955 for-Schleifen-Ebene pflegen
IncForLevel(void)56     void IncForLevel( void ) { nForLevel++; }
DecForLevel(void)57     void DecForLevel( void ) { nForLevel--; }
58 
59     static sal_uInt32 calcNewOffSet( sal_uInt8* pCode, sal_uInt16 nOffset );
60     static sal_uInt16 calcLegacyOffSet( sal_uInt8* pCode, sal_uInt32 nOffset );
61 
62 };
63 
64 template < class T, class S >
65 class PCodeBuffConvertor
66 {
67     T m_nSize; //
68     sal_uInt8* m_pStart;
69     sal_uInt8* m_pCnvtdBuf;
70     S m_nCnvtdSize; //
71 
72     //  Disable usual copying symantics and bodgy default ctor
73     PCodeBuffConvertor();
74     PCodeBuffConvertor(const PCodeBuffConvertor& );
75     PCodeBuffConvertor& operator = ( const PCodeBuffConvertor& );
76 public:
PCodeBuffConvertor(sal_uInt8 * pCode,T nSize)77     PCodeBuffConvertor( sal_uInt8* pCode, T nSize ): m_nSize( nSize ),  m_pStart( pCode ), m_pCnvtdBuf( NULL ), m_nCnvtdSize( 0 ){ convert(); }
GetSize()78     S GetSize(){ return m_nCnvtdSize; }
79     void convert();
80     // Caller owns the buffer returned
GetBuffer()81     sal_uInt8* GetBuffer() { return m_pCnvtdBuf; }
82 };
83 
84 // #111897 PARAM_INFO flags start at 0x00010000 to not
85 // conflict with DefaultId in SbxParamInfo::nUserData
86 #define PARAM_INFO_PARAMARRAY       0x0010000
87 #define PARAM_INFO_WITHBRACKETS     0x0020000
88 
89 #endif
90