update dev300-m58
[ooovba.git] / codemaker / source / javamaker / classfile.hxx
blob56ece85547d41b6f753cf9c131b6d95aa05b74c8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: classfile.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX
32 #define INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX
34 #include "codemaker/unotype.hxx"
35 #include "sal/types.h"
37 #include <list>
38 #include <map>
39 #include <utility>
40 #include <vector>
42 class FileStream;
43 namespace rtl { class OString; }
45 namespace codemaker { namespace javamaker {
47 class ClassFile {
48 public:
49 enum AccessFlags {
50 ACC_PUBLIC = 0x0001,
51 ACC_PRIVATE = 0x0002,
52 ACC_STATIC = 0x0008,
53 ACC_FINAL = 0x0010,
54 ACC_SUPER = 0x0020,
55 ACC_VARARGS = 0x0080,
56 ACC_INTERFACE = 0x0200,
57 ACC_ABSTRACT = 0x0400,
58 ACC_SYNTHETIC = 0x1000
61 class Code {
62 public:
63 typedef std::vector< unsigned char >::size_type Branch;
64 typedef std::vector< unsigned char >::size_type Position;
66 ~Code();
68 void instrAastore();
70 void instrAconstNull();
72 void instrAnewarray(rtl::OString const & type);
74 void instrAreturn();
76 void instrAthrow();
78 void instrCheckcast(rtl::OString const & type);
80 void instrDup();
82 void instrGetstatic(
83 rtl::OString const & type, rtl::OString const & name,
84 rtl::OString const & descriptor);
86 Branch instrIfAcmpne();
88 Branch instrIfeq();
90 Branch instrIfnull();
92 void instrInstanceof(rtl::OString const & type);
94 void instrInvokeinterface(
95 rtl::OString const & type, rtl::OString const & name,
96 rtl::OString const & descriptor, sal_uInt8 args);
98 void instrInvokespecial(
99 rtl::OString const & type, rtl::OString const & name,
100 rtl::OString const & descriptor);
102 void instrInvokestatic(
103 rtl::OString const & type, rtl::OString const & name,
104 rtl::OString const & descriptor);
106 void instrInvokevirtual(
107 rtl::OString const & type, rtl::OString const & name,
108 rtl::OString const & descriptor);
110 void instrLookupswitch(
111 Code const * defaultBlock,
112 std::list< std::pair< sal_Int32, Code * > > const & blocks);
114 void instrNew(rtl::OString const & type);
116 void instrNewarray(codemaker::UnoType::Sort sort);
118 void instrPop();
120 void instrPutfield(
121 rtl::OString const & type, rtl::OString const & name,
122 rtl::OString const & descriptor);
124 void instrPutstatic(
125 rtl::OString const & type, rtl::OString const & name,
126 rtl::OString const & descriptor);
128 void instrReturn();
130 void instrSwap();
132 void instrTableswitch(
133 Code const * defaultBlock, sal_Int32 low,
134 std::list< Code * > const & blocks);
136 void loadIntegerConstant(sal_Int32 value);
138 void loadStringConstant(rtl::OString const & value);
140 void loadLocalInteger(sal_uInt16 index);
142 void loadLocalLong(sal_uInt16 index);
144 void loadLocalFloat(sal_uInt16 index);
146 void loadLocalDouble(sal_uInt16 index);
148 void loadLocalReference(sal_uInt16 index);
150 void storeLocalReference(sal_uInt16 index);
152 void branchHere(Branch branch);
154 void addException(
155 Position start, Position end, Position handler,
156 rtl::OString const & type);
158 void setMaxStackAndLocals(sal_uInt16 maxStack, sal_uInt16 maxLocals)
159 { m_maxStack = maxStack; m_maxLocals = maxLocals; }
161 Position getPosition() const;
163 private:
164 Code(Code &); // not implemented
165 void operator =(Code); // not implemented
167 Code(ClassFile & classFile);
169 void ldc(sal_uInt16 index);
171 void accessLocal(
172 sal_uInt16 index, sal_uInt8 fastOp, sal_uInt8 normalOp);
174 ClassFile & m_classFile;
175 sal_uInt16 m_maxStack;
176 sal_uInt16 m_maxLocals;
177 std::vector< unsigned char > m_code;
178 sal_uInt16 m_exceptionTableLength;
179 std::vector< unsigned char > m_exceptionTable;
181 friend class ClassFile;
184 ClassFile(
185 AccessFlags accessFlags, rtl::OString const & thisClass,
186 rtl::OString const & superClass, rtl::OString const & signature);
188 ~ClassFile();
190 Code * newCode();
192 sal_uInt16 addIntegerInfo(sal_Int32 value);
194 sal_uInt16 addFloatInfo(float value);
196 sal_uInt16 addLongInfo(sal_Int64 value);
198 sal_uInt16 addDoubleInfo(double value);
200 void addInterface(rtl::OString const & interface);
202 void addField(
203 AccessFlags accessFlags, rtl::OString const & name,
204 rtl::OString const & descriptor, sal_uInt16 constantValueIndex,
205 rtl::OString const & signature);
207 void addMethod(
208 AccessFlags accessFlags, rtl::OString const & name,
209 rtl::OString const & descriptor, Code const * code,
210 std::vector< rtl::OString > const & exceptions,
211 rtl::OString const & signature);
213 void write(FileStream & file) const; //TODO
215 private:
216 typedef std::map< rtl::OString, sal_uInt16 > Map;
218 ClassFile(ClassFile &); // not implemented
219 void operator =(ClassFile); // not implemented
221 sal_uInt16 nextConstantPoolIndex(sal_uInt16 width);
223 sal_uInt16 addUtf8Info(rtl::OString const & value);
225 sal_uInt16 addClassInfo(rtl::OString const & type);
227 sal_uInt16 addStringInfo(rtl::OString const & value);
229 sal_uInt16 addFieldrefInfo(
230 rtl::OString const & type, rtl::OString const & name,
231 rtl::OString const & descriptor);
233 sal_uInt16 addMethodrefInfo(
234 rtl::OString const & type, rtl::OString const & name,
235 rtl::OString const & descriptor);
237 sal_uInt16 addInterfaceMethodrefInfo(
238 rtl::OString const & type, rtl::OString const & name,
239 rtl::OString const & descriptor);
241 sal_uInt16 addNameAndTypeInfo(
242 rtl::OString const & name, rtl::OString const & descriptor);
244 void appendSignatureAttribute(
245 std::vector< unsigned char > & stream, rtl::OString const & signature);
247 sal_uInt16 m_constantPoolCount;
248 std::vector< unsigned char > m_constantPool;
249 std::map< rtl::OString, sal_uInt16 > m_utf8Infos;
250 std::map< sal_Int32, sal_uInt16 > m_integerInfos;
251 std::map< sal_Int64, sal_uInt16 > m_longInfos;
252 std::map< float, sal_uInt16 > m_floatInfos;
253 std::map< double, sal_uInt16 > m_doubleInfos;
254 std::map< sal_uInt16, sal_uInt16 > m_classInfos;
255 std::map< sal_uInt16, sal_uInt16 > m_stringInfos;
256 std::map< sal_uInt32, sal_uInt16 > m_fieldrefInfos;
257 std::map< sal_uInt32, sal_uInt16 > m_methodrefInfos;
258 std::map< sal_uInt32, sal_uInt16 > m_interfaceMethodrefInfos;
259 std::map< sal_uInt32, sal_uInt16 > m_nameAndTypeInfos;
260 AccessFlags m_accessFlags;
261 sal_uInt16 m_thisClass;
262 sal_uInt16 m_superClass;
263 sal_uInt16 m_interfacesCount;
264 std::vector< unsigned char > m_interfaces;
265 sal_uInt16 m_fieldsCount;
266 std::vector< unsigned char > m_fields;
267 sal_uInt16 m_methodsCount;
268 std::vector< unsigned char > m_methods;
269 sal_uInt16 m_attributesCount;
270 std::vector< unsigned char > m_attributes;
272 friend class Code;
277 #endif // INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX