xref: /aoo42x/main/basic/source/inc/codegen.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CODEGEN_HXX
29 #define _CODEGEN_HXX
30 
31 class SbiImage;
32 class SbiParser;
33 class SbModule;
34 #include "opcodes.hxx"
35 #include "buffer.hxx"
36 
37 class SbiCodeGen { 				// Code-Erzeugung:
38 	SbiParser* pParser;			// fuer Fehlermeldungen, Line, Column etc.
39 	SbModule& rMod;				// aktuelles Modul
40 	SbiBuffer aCode;	  			// Code-Puffer
41 	short  nLine, nCol;			// Zeile, Spalte fuer Stmnt-Befehl
42 	short  nForLevel;			// #29955 for-Schleifen-Ebene
43 	sal_Bool bStmnt;				// sal_True: Statement-Opcode liegt an
44 public:
45 	SbiCodeGen( SbModule&, SbiParser*, short );
46 	SbiParser* GetParser() { return pParser; }
47 	SbModule& GetModule() { return rMod; }
48 	sal_uInt32 Gen( SbiOpcode );
49 	sal_uInt32 Gen( SbiOpcode, sal_uInt32 );
50 	sal_uInt32 Gen( SbiOpcode, sal_uInt32, sal_uInt32 );
51 	void Patch( sal_uInt32 o, sal_uInt32 v ){ aCode.Patch( o, v ); }
52 	void BackChain( sal_uInt32 off )	{ aCode.Chain( off );  }
53 	void Statement();
54 	void GenStmnt();			// evtl. Statement-Opcode erzeugen
55 	sal_uInt32 GetPC();
56 	sal_uInt32 GetOffset()				{ return GetPC() + 1; }
57 	void Save();
58 
59 	// #29955 for-Schleifen-Ebene pflegen
60 	void IncForLevel( void ) { nForLevel++; }
61 	void DecForLevel( void ) { nForLevel--; }
62 
63 	static sal_uInt32 calcNewOffSet( sal_uInt8* pCode, sal_uInt16 nOffset );
64 	static sal_uInt16 calcLegacyOffSet( sal_uInt8* pCode, sal_uInt32 nOffset );
65 
66 };
67 
68 template < class T, class S >
69 class PCodeBuffConvertor
70 {
71 	T m_nSize; //
72 	sal_uInt8* m_pStart;
73 	sal_uInt8* m_pCnvtdBuf;
74 	S m_nCnvtdSize; //
75 
76 	//  Disable usual copying symantics and bodgy default ctor
77 	PCodeBuffConvertor();
78 	PCodeBuffConvertor(const PCodeBuffConvertor& );
79 	PCodeBuffConvertor& operator = ( const PCodeBuffConvertor& );
80 public:
81 	PCodeBuffConvertor( sal_uInt8* pCode, T nSize ): m_nSize( nSize ),  m_pStart( pCode ), m_pCnvtdBuf( NULL ), m_nCnvtdSize( 0 ){ convert(); }
82 	S GetSize(){ return m_nCnvtdSize; }
83 	void convert();
84 	// Caller owns the buffer returned
85 	sal_uInt8* GetBuffer() { return m_pCnvtdBuf; }
86 };
87 
88 // #111897 PARAM_INFO flags start at 0x00010000 to not
89 // conflict with DefaultId in SbxParamInfo::nUserData
90 #define PARAM_INFO_PARAMARRAY		0x0010000
91 #define PARAM_INFO_WITHBRACKETS		0x0020000
92 
93 #endif
94