1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <codemaker/unotype.hxx>
23 #include <sal/types.h>
32 namespace codemaker::javamaker
{
43 ACC_INTERFACE
= 0x0200,
44 ACC_ABSTRACT
= 0x0400,
45 ACC_SYNTHETIC
= 0x1000
50 typedef std::vector
< unsigned char >::size_type Branch
;
51 typedef std::vector
< unsigned char >::size_type Position
;
56 void instrAconstNull();
57 void instrAnewarray(rtl::OString
const & type
);
60 void instrCheckcast(rtl::OString
const & type
);
64 rtl::OString
const & type
, rtl::OString
const & name
,
65 rtl::OString
const & descriptor
);
67 Branch
instrIfAcmpne();
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
);
98 rtl::OString
const & type
, rtl::OString
const & name
,
99 rtl::OString
const & descriptor
);
102 rtl::OString
const & type
, rtl::OString
const & name
,
103 rtl::OString
const & descriptor
);
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
);
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;
132 Code(Code
const &) = delete;
133 Code
& operator =(const Code
&) = delete;
135 explicit Code(ClassFile
& classFile
);
137 void ldc(sal_uInt16 index
);
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
;
153 AccessFlags accessFlags
, rtl::OString
const & thisClass
,
154 rtl::OString
const & superClass
, rtl::OString
const & signature
);
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
);
168 AccessFlags accessFlags
, rtl::OString
const & name
,
169 rtl::OString
const & descriptor
, sal_uInt16 constantValueIndex
,
170 rtl::OString
const & signature
);
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
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
;
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */