Bump version to 24.04.3.4
[LibreOffice.git] / codemaker / source / javamaker / classfile.hxx
blobebfef07820eed22d298d2cf89305dc4aad3ddf6f
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 #pragma once
22 #include <codemaker/unotype.hxx>
23 #include <sal/types.h>
25 #include <map>
26 #include <memory>
27 #include <utility>
28 #include <vector>
30 class FileStream;
32 namespace codemaker::javamaker {
34 class ClassFile {
35 public:
36 enum AccessFlags {
37 ACC_PUBLIC = 0x0001,
38 ACC_PRIVATE = 0x0002,
39 ACC_STATIC = 0x0008,
40 ACC_FINAL = 0x0010,
41 ACC_SUPER = 0x0020,
42 ACC_VARARGS = 0x0080,
43 ACC_INTERFACE = 0x0200,
44 ACC_ABSTRACT = 0x0400,
45 ACC_SYNTHETIC = 0x1000
48 class Code {
49 public:
50 typedef std::vector< unsigned char >::size_type Branch;
51 typedef std::vector< unsigned char >::size_type Position;
53 ~Code();
55 void instrAastore();
56 void instrAconstNull();
57 void instrAnewarray(rtl::OString const & type);
58 void instrAreturn();
59 void instrAthrow();
60 void instrCheckcast(rtl::OString const & type);
61 void instrDup();
63 void instrGetstatic(
64 rtl::OString const & type, rtl::OString const & name,
65 rtl::OString const & descriptor);
67 Branch instrIfAcmpne();
68 Branch instrIfeq();
69 Branch instrIfnull();
71 void instrInstanceof(rtl::OString const & type);
73 void instrInvokeinterface(
74 rtl::OString const & type, rtl::OString const & name,
75 rtl::OString const & descriptor, sal_uInt8 args);
77 void instrInvokespecial(
78 rtl::OString const & type, rtl::OString const & name,
79 rtl::OString const & descriptor);
81 void instrInvokestatic(
82 rtl::OString const & type, rtl::OString const & name,
83 rtl::OString const & descriptor);
85 void instrInvokevirtual(
86 rtl::OString const & type, rtl::OString const & name,
87 rtl::OString const & descriptor);
89 void instrLookupswitch(
90 Code const * defaultBlock,
91 std::vector< std::pair< sal_Int32, Code * > > const & blocks);
93 void instrNew(rtl::OString const & type);
94 void instrNewarray(codemaker::UnoType::Sort sort);
95 void instrPop();
97 void instrPutfield(
98 rtl::OString const & type, rtl::OString const & name,
99 rtl::OString const & descriptor);
101 void instrPutstatic(
102 rtl::OString const & type, rtl::OString const & name,
103 rtl::OString const & descriptor);
105 void instrReturn();
106 void instrSwap();
108 void instrTableswitch(
109 Code const * defaultBlock, sal_Int32 low,
110 std::vector< std::unique_ptr<Code> > const & blocks);
112 void loadIntegerConstant(sal_Int32 value);
113 void loadStringConstant(rtl::OString const & value);
114 void loadLocalInteger(sal_uInt16 index);
115 void loadLocalLong(sal_uInt16 index);
116 void loadLocalFloat(sal_uInt16 index);
117 void loadLocalDouble(sal_uInt16 index);
118 void loadLocalReference(sal_uInt16 index);
119 void storeLocalReference(sal_uInt16 index);
120 void branchHere(Branch branch);
122 void addException(
123 Position start, Position end, Position handler,
124 rtl::OString const & type);
126 void setMaxStackAndLocals(sal_uInt16 maxStack, sal_uInt16 maxLocals)
127 { m_maxStack = maxStack; m_maxLocals = maxLocals; }
129 Position getPosition() const;
131 private:
132 Code(Code const &) = delete;
133 Code& operator =(const Code&) = delete;
135 explicit Code(ClassFile & classFile);
137 void ldc(sal_uInt16 index);
139 void accessLocal(
140 sal_uInt16 index, sal_uInt8 fastOp, sal_uInt8 normalOp);
142 ClassFile & m_classFile;
143 sal_uInt16 m_maxStack;
144 sal_uInt16 m_maxLocals;
145 std::vector< unsigned char > m_code;
146 sal_uInt16 m_exceptionTableLength;
147 std::vector< unsigned char > m_exceptionTable;
149 friend class ClassFile;
152 ClassFile(
153 AccessFlags accessFlags, rtl::OString const & thisClass,
154 rtl::OString const & superClass, rtl::OString const & signature);
156 ~ClassFile();
158 std::unique_ptr<Code> newCode();
160 sal_uInt16 addIntegerInfo(sal_Int32 value);
161 sal_uInt16 addFloatInfo(float value);
162 sal_uInt16 addLongInfo(sal_Int64 value);
163 sal_uInt16 addDoubleInfo(double value);
165 void addInterface(rtl::OString const & interface);
167 void addField(
168 AccessFlags accessFlags, rtl::OString const & name,
169 rtl::OString const & descriptor, sal_uInt16 constantValueIndex,
170 rtl::OString const & signature);
172 void addMethod(
173 AccessFlags accessFlags, rtl::OString const & name,
174 rtl::OString const & descriptor, Code const * code,
175 std::vector< rtl::OString > const & exceptions,
176 rtl::OString const & signature);
178 void write(FileStream & file) const; //TODO
180 private:
181 typedef std::map< rtl::OString, sal_uInt16 > Map;
183 ClassFile(ClassFile const &) = delete;
184 ClassFile& operator =(const ClassFile&) = delete;
186 sal_uInt16 nextConstantPoolIndex(sal_uInt16 width);
187 sal_uInt16 addUtf8Info(rtl::OString const & value);
188 sal_uInt16 addClassInfo(rtl::OString const & type);
189 sal_uInt16 addStringInfo(rtl::OString const & value);
191 sal_uInt16 addFieldrefInfo(
192 rtl::OString const & type, rtl::OString const & name,
193 rtl::OString const & descriptor);
195 sal_uInt16 addMethodrefInfo(
196 rtl::OString const & type, rtl::OString const & name,
197 rtl::OString const & descriptor);
199 sal_uInt16 addInterfaceMethodrefInfo(
200 rtl::OString const & type, rtl::OString const & name,
201 rtl::OString const & descriptor);
203 sal_uInt16 addNameAndTypeInfo(
204 rtl::OString const & name, rtl::OString const & descriptor);
206 void appendSignatureAttribute(
207 std::vector< unsigned char > & stream, rtl::OString const & signature);
209 sal_uInt16 m_constantPoolCount;
210 std::vector< unsigned char > m_constantPool;
211 std::map< rtl::OString, sal_uInt16 > m_utf8Infos;
212 std::map< sal_Int32, sal_uInt16 > m_integerInfos;
213 std::map< sal_Int64, sal_uInt16 > m_longInfos;
214 std::map< float, sal_uInt16 > m_floatInfos;
215 std::map< double, sal_uInt16 > m_doubleInfos;
216 std::map< sal_uInt16, sal_uInt16 > m_classInfos;
217 std::map< sal_uInt16, sal_uInt16 > m_stringInfos;
218 std::map< sal_uInt32, sal_uInt16 > m_fieldrefInfos;
219 std::map< sal_uInt32, sal_uInt16 > m_methodrefInfos;
220 std::map< sal_uInt32, sal_uInt16 > m_interfaceMethodrefInfos;
221 std::map< sal_uInt32, sal_uInt16 > m_nameAndTypeInfos;
222 AccessFlags m_accessFlags;
223 sal_uInt16 m_thisClass;
224 sal_uInt16 m_superClass;
225 sal_uInt16 m_interfacesCount;
226 std::vector< unsigned char > m_interfaces;
227 sal_uInt16 m_fieldsCount;
228 std::vector< unsigned char > m_fields;
229 sal_uInt16 m_methodsCount;
230 std::vector< unsigned char > m_methods;
231 sal_uInt16 m_attributesCount;
232 std::vector< unsigned char > m_attributes;
234 friend class Code;
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */