lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / codemaker / source / javamaker / classfile.hxx
blob6f536802b50c3bd1161072566f585ed22842cc22
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 INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX
21 #define INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX
23 #include <codemaker/unotype.hxx>
24 #include <sal/types.h>
26 #include <map>
27 #include <memory>
28 #include <utility>
29 #include <vector>
31 class FileStream;
33 namespace codemaker { namespace javamaker {
35 class ClassFile {
36 public:
37 enum AccessFlags {
38 ACC_PUBLIC = 0x0001,
39 ACC_PRIVATE = 0x0002,
40 ACC_STATIC = 0x0008,
41 ACC_FINAL = 0x0010,
42 ACC_SUPER = 0x0020,
43 ACC_VARARGS = 0x0080,
44 ACC_INTERFACE = 0x0200,
45 ACC_ABSTRACT = 0x0400,
46 ACC_SYNTHETIC = 0x1000
49 class Code {
50 public:
51 typedef std::vector< unsigned char >::size_type Branch;
52 typedef std::vector< unsigned char >::size_type Position;
54 ~Code();
56 void instrAastore();
57 void instrAconstNull();
58 void instrAnewarray(rtl::OString const & type);
59 void instrAreturn();
60 void instrAthrow();
61 void instrCheckcast(rtl::OString const & type);
62 void instrDup();
64 void instrGetstatic(
65 rtl::OString const & type, rtl::OString const & name,
66 rtl::OString const & descriptor);
68 Branch instrIfAcmpne();
69 Branch instrIfeq();
70 Branch instrIfnull();
72 void instrInstanceof(rtl::OString const & type);
74 void instrInvokeinterface(
75 rtl::OString const & type, rtl::OString const & name,
76 rtl::OString const & descriptor, sal_uInt8 args);
78 void instrInvokespecial(
79 rtl::OString const & type, rtl::OString const & name,
80 rtl::OString const & descriptor);
82 void instrInvokestatic(
83 rtl::OString const & type, rtl::OString const & name,
84 rtl::OString const & descriptor);
86 void instrInvokevirtual(
87 rtl::OString const & type, rtl::OString const & name,
88 rtl::OString const & descriptor);
90 void instrLookupswitch(
91 Code const * defaultBlock,
92 std::vector< std::pair< sal_Int32, Code * > > const & blocks);
94 void instrNew(rtl::OString const & type);
95 void instrNewarray(codemaker::UnoType::Sort sort);
96 void instrPop();
98 void instrPutfield(
99 rtl::OString const & type, rtl::OString const & name,
100 rtl::OString const & descriptor);
102 void instrPutstatic(
103 rtl::OString const & type, rtl::OString const & name,
104 rtl::OString const & descriptor);
106 void instrReturn();
107 void instrSwap();
109 void instrTableswitch(
110 Code const * defaultBlock, sal_Int32 low,
111 std::vector< std::unique_ptr<Code> > const & blocks);
113 void loadIntegerConstant(sal_Int32 value);
114 void loadStringConstant(rtl::OString const & value);
115 void loadLocalInteger(sal_uInt16 index);
116 void loadLocalLong(sal_uInt16 index);
117 void loadLocalFloat(sal_uInt16 index);
118 void loadLocalDouble(sal_uInt16 index);
119 void loadLocalReference(sal_uInt16 index);
120 void storeLocalReference(sal_uInt16 index);
121 void branchHere(Branch branch);
123 void addException(
124 Position start, Position end, Position handler,
125 rtl::OString const & type);
127 void setMaxStackAndLocals(sal_uInt16 maxStack, sal_uInt16 maxLocals)
128 { m_maxStack = maxStack; m_maxLocals = maxLocals; }
130 Position getPosition() const;
132 private:
133 Code(Code const &) = delete;
134 Code& operator =(const Code&) = delete;
136 explicit Code(ClassFile & classFile);
138 void ldc(sal_uInt16 index);
140 void accessLocal(
141 sal_uInt16 index, sal_uInt8 fastOp, sal_uInt8 normalOp);
143 ClassFile & m_classFile;
144 sal_uInt16 m_maxStack;
145 sal_uInt16 m_maxLocals;
146 std::vector< unsigned char > m_code;
147 sal_uInt16 m_exceptionTableLength;
148 std::vector< unsigned char > m_exceptionTable;
150 friend class ClassFile;
153 ClassFile(
154 AccessFlags accessFlags, rtl::OString const & thisClass,
155 rtl::OString const & superClass, rtl::OString const & signature);
157 ~ClassFile();
159 Code * newCode();
161 sal_uInt16 addIntegerInfo(sal_Int32 value);
162 sal_uInt16 addFloatInfo(float value);
163 sal_uInt16 addLongInfo(sal_Int64 value);
164 sal_uInt16 addDoubleInfo(double value);
166 void addInterface(rtl::OString const & interface);
168 void addField(
169 AccessFlags accessFlags, rtl::OString const & name,
170 rtl::OString const & descriptor, sal_uInt16 constantValueIndex,
171 rtl::OString const & signature);
173 void addMethod(
174 AccessFlags accessFlags, rtl::OString const & name,
175 rtl::OString const & descriptor, Code const * code,
176 std::vector< rtl::OString > const & exceptions,
177 rtl::OString const & signature);
179 void write(FileStream & file) const; //TODO
181 private:
182 typedef std::map< rtl::OString, sal_uInt16 > Map;
184 ClassFile(ClassFile const &) = delete;
185 ClassFile& operator =(const ClassFile&) = delete;
187 sal_uInt16 nextConstantPoolIndex(sal_uInt16 width);
188 sal_uInt16 addUtf8Info(rtl::OString const & value);
189 sal_uInt16 addClassInfo(rtl::OString const & type);
190 sal_uInt16 addStringInfo(rtl::OString const & value);
192 sal_uInt16 addFieldrefInfo(
193 rtl::OString const & type, rtl::OString const & name,
194 rtl::OString const & descriptor);
196 sal_uInt16 addMethodrefInfo(
197 rtl::OString const & type, rtl::OString const & name,
198 rtl::OString const & descriptor);
200 sal_uInt16 addInterfaceMethodrefInfo(
201 rtl::OString const & type, rtl::OString const & name,
202 rtl::OString const & descriptor);
204 sal_uInt16 addNameAndTypeInfo(
205 rtl::OString const & name, rtl::OString const & descriptor);
207 void appendSignatureAttribute(
208 std::vector< unsigned char > & stream, rtl::OString const & signature);
210 sal_uInt16 m_constantPoolCount;
211 std::vector< unsigned char > m_constantPool;
212 std::map< rtl::OString, sal_uInt16 > m_utf8Infos;
213 std::map< sal_Int32, sal_uInt16 > m_integerInfos;
214 std::map< sal_Int64, sal_uInt16 > m_longInfos;
215 std::map< float, sal_uInt16 > m_floatInfos;
216 std::map< double, sal_uInt16 > m_doubleInfos;
217 std::map< sal_uInt16, sal_uInt16 > m_classInfos;
218 std::map< sal_uInt16, sal_uInt16 > m_stringInfos;
219 std::map< sal_uInt32, sal_uInt16 > m_fieldrefInfos;
220 std::map< sal_uInt32, sal_uInt16 > m_methodrefInfos;
221 std::map< sal_uInt32, sal_uInt16 > m_interfaceMethodrefInfos;
222 std::map< sal_uInt32, sal_uInt16 > m_nameAndTypeInfos;
223 AccessFlags m_accessFlags;
224 sal_uInt16 m_thisClass;
225 sal_uInt16 m_superClass;
226 sal_uInt16 m_interfacesCount;
227 std::vector< unsigned char > m_interfaces;
228 sal_uInt16 m_fieldsCount;
229 std::vector< unsigned char > m_fields;
230 sal_uInt16 m_methodsCount;
231 std::vector< unsigned char > m_methods;
232 sal_uInt16 m_attributesCount;
233 std::vector< unsigned char > m_attributes;
235 friend class Code;
240 #endif // INCLUDED_CODEMAKER_SOURCE_JAVAMAKER_CLASSFILE_HXX
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */