41#include <rtl/strbuf.hxx>
42#include <rtl/string.hxx>
43#include <rtl/ustrbuf.hxx>
44#include <rtl/ustring.hxx>
59 sal_Int32 rank, std::vector< OUString >
const & arguments,
60 OUStringBuffer * buffer)
64 assert(buffer !=
nullptr);
65 for (sal_Int32 i = 0;
i != rank; ++
i) {
68 buffer->append(nucleus);
69 if (arguments.empty())
73 for (std::vector< OUString >::const_iterator
i(arguments.begin());
74 i != arguments.end(); ++i)
76 if (i != arguments.begin()) {
81 std::vector< OUString >
args;
82 manager->decompose(*i,
false, &n, &k, &args,
nullptr);
83 appendUnoName(manager, n, k, args, buffer);
91OUString createUnoName(
93 sal_Int32 rank, std::vector< OUString >
const & arguments)
95 OUStringBuffer buf(256);
96 appendUnoName(manager, nucleus, rank, arguments, &buf);
97 return buf.makeStringAndClear();
103 SPECIAL_TYPE_UNSIGNED,
104 SPECIAL_TYPE_INTERFACE
107bool isSpecialType(SpecialType special) {
108 return special >= SPECIAL_TYPE_UNSIGNED;
111OString translateUnoidlEntityNameToJavaFullyQualifiedName(
112 std::u16string_view name, std::string_view prefix)
115 assert(
name.find(
'<') == std::string_view::npos);
116 size_t i =
name.rfind(
'.');
117 if (i == std::string_view::npos)
126struct PolymorphicUnoType {
127 PolymorphicUnoType(): kind(KIND_NONE) {}
129 enum Kind { KIND_NONE, KIND_STRUCT, KIND_SEQUENCE };
134SpecialType translateUnoTypeToDescriptor(
136 bool array,
bool classType, std::set<OUString> * dependencies,
137 OStringBuffer * descriptor, OStringBuffer * signature,
138 bool * needsSignature, PolymorphicUnoType * polymorphicUnoType);
140SpecialType translateUnoTypeToDescriptor(
143 std::vector< OUString >
const & arguments,
bool array,
bool classType,
144 std::set<OUString> * dependencies, OStringBuffer * descriptor,
145 OStringBuffer * signature,
bool * needsSignature,
146 PolymorphicUnoType * polymorphicUnoType)
149 assert((signature ==
nullptr) == (needsSignature ==
nullptr));
154 if (rank > 0xFF - (array ? 1 : 0)) {
156 "Too many array dimensions for Java class file format");
161 for (sal_Int32 i = 0;
i != rank; ++
i) {
162 if (descriptor !=
nullptr) {
163 descriptor->append(
'[');
165 if (signature !=
nullptr) {
166 signature->append(
'[');
169 if (polymorphicUnoType !=
nullptr) {
173 polymorphicUnoType->kind = rank == 0
174 ? PolymorphicUnoType::KIND_STRUCT
175 : PolymorphicUnoType::KIND_SEQUENCE;
176 polymorphicUnoType->name = createUnoName(
177 manager, nucleus, rank, arguments);
179 polymorphicUnoType->kind = PolymorphicUnoType::KIND_NONE;
199 static char const *
const
201 {
"V",
"Ljava/lang/Void;" },
202 {
"Z",
"Ljava/lang/Boolean;" },
203 {
"B",
"Ljava/lang/Byte;" },
204 {
"S",
"Ljava/lang/Short;" },
205 {
"S",
"Ljava/lang/Short;" },
206 {
"I",
"Ljava/lang/Integer;" },
207 {
"I",
"Ljava/lang/Integer;" },
208 {
"J",
"Ljava/lang/Long;" },
209 {
"J",
"Ljava/lang/Long;" },
210 {
"F",
"Ljava/lang/Float;" },
211 {
"D",
"Ljava/lang/Double;" },
212 {
"C",
"Ljava/lang/Character;" },
213 {
"Ljava/lang/String;",
"Ljava/lang/String;" },
214 {
"Lcom/sun/star/uno/Type;",
"Lcom/sun/star/uno/Type;" },
215 {
"Ljava/lang/Object;",
"Ljava/lang/Object;" } };
217 = simpleTypeDescriptors[
static_cast<int>(sort)][rank == 0 && classType];
218 if (descriptor !=
nullptr) {
219 descriptor->append(s);
221 if (signature !=
nullptr) {
222 signature->append(s);
224 static SpecialType
const
226 SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE,
227 SPECIAL_TYPE_NONE, SPECIAL_TYPE_UNSIGNED, SPECIAL_TYPE_NONE,
228 SPECIAL_TYPE_UNSIGNED, SPECIAL_TYPE_NONE, SPECIAL_TYPE_UNSIGNED,
229 SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE,
230 SPECIAL_TYPE_NONE, SPECIAL_TYPE_NONE, SPECIAL_TYPE_ANY };
231 return simpleTypeSpecials[
static_cast<int>(sort)];
234 if (nucleus ==
"com.sun.star.uno.XInterface") {
235 if (descriptor !=
nullptr) {
236 descriptor->append(
"Ljava/lang/Object;");
238 if (signature !=
nullptr) {
239 signature->append(
"Ljava/lang/Object;");
241 return SPECIAL_TYPE_INTERFACE;
248 if (dependencies !=
nullptr) {
249 dependencies->insert(nucleus);
251 if (descriptor !=
nullptr) {
256 if (signature !=
nullptr) {
259 if (!arguments.empty()) {
260 signature->append(
'<');
261 for (
const OUString& arg : arguments)
263 translateUnoTypeToDescriptor(
264 manager, arg,
false,
true, dependencies,
nullptr, signature,
265 needsSignature,
nullptr);
267 signature->append(
'>');
268 *needsSignature =
true;
270 signature->append(
';');
272 return SPECIAL_TYPE_NONE;
275 "unexpected nucleus \"" + nucleus
276 +
"\" in call to translateUnoTypeToDescriptor");
280SpecialType translateUnoTypeToDescriptor(
282 bool array,
bool classType, std::set<OUString> * dependencies,
283 OStringBuffer * descriptor, OStringBuffer * signature,
284 bool * needsSignature, PolymorphicUnoType * polymorphicUnoType)
289 std::vector< OUString >
args;
291 type,
true, &nucleus, &rank, &args,
nullptr);
292 return translateUnoTypeToDescriptor(
293 manager, sort, nucleus, rank, args, array, classType, dependencies,
294 descriptor, signature, needsSignature, polymorphicUnoType);
297SpecialType getFieldDescriptor(
299 std::u16string_view type, OString * descriptor, OString * signature,
300 PolymorphicUnoType * polymorphicUnoType)
302 assert(descriptor !=
nullptr);
303 OStringBuffer desc(64);
304 OStringBuffer sig(64);
305 bool needsSig =
false;
306 SpecialType specialType = translateUnoTypeToDescriptor(
307 manager, type,
false,
false, dependencies, &desc, &sig, &needsSig,
309 *descriptor = desc.makeStringAndClear();
310 if (signature !=
nullptr) {
312 *signature = sig.makeStringAndClear();
320class MethodDescriptor {
324 std::set<OUString> * dependencies, std::u16string_view returnType,
325 SpecialType * specialReturnType,
326 PolymorphicUnoType * polymorphicUnoType);
328 SpecialType addParameter(
329 std::u16string_view type,
bool array,
bool dependency,
330 PolymorphicUnoType * polymorphicUnoType);
332 void addTypeParameter(OUString
const & name);
334 OString getDescriptor()
const;
336 OString getSignature()
const {
return m_needsSignature ? m_signatureStart + m_signatureEnd : OString();}
340 std::set<OUString> * m_dependencies;
341 OStringBuffer m_descriptorStart{16*1024};
342 OString m_descriptorEnd;
343 OStringBuffer m_signatureStart{16*1024};
344 OString m_signatureEnd;
345 bool m_needsSignature;
348MethodDescriptor::MethodDescriptor(
350 std::u16string_view returnType, SpecialType * specialReturnType,
351 PolymorphicUnoType * polymorphicUnoType):
352 m_manager(
std::move(
manager)), m_dependencies(dependencies), m_needsSignature(false)
354 assert(dependencies !=
nullptr);
355 m_descriptorStart.append(
'(');
356 m_signatureStart.append(
'(');
357 OStringBuffer descEnd(128);
359 OStringBuffer sigEnd(128);
361 SpecialType special = translateUnoTypeToDescriptor(
362 m_manager, returnType,
false,
false, m_dependencies, &descEnd, &sigEnd,
363 &m_needsSignature, polymorphicUnoType);
364 m_descriptorEnd = descEnd.makeStringAndClear();
365 m_signatureEnd = sigEnd.makeStringAndClear();
366 if (specialReturnType !=
nullptr) {
367 *specialReturnType = special;
371SpecialType MethodDescriptor::addParameter(
372 std::u16string_view type,
bool array,
bool dependency,
373 PolymorphicUnoType * polymorphicUnoType)
375 return translateUnoTypeToDescriptor(
376 m_manager, type, array,
false, dependency ? m_dependencies :
nullptr,
377 &m_descriptorStart, &m_signatureStart, &m_needsSignature,
381void MethodDescriptor::addTypeParameter(OUString
const & name) {
382 m_descriptorStart.append(
"Ljava/lang/Object;");
384 m_needsSignature =
true;
387OString MethodDescriptor::getDescriptor()
const {
388 return m_descriptorStart + m_descriptorEnd;
394 enum Kind { KIND_MEMBER, KIND_ATTRIBUTE, KIND_METHOD, KIND_PARAMETER };
403 OString name, SpecialType specialType, sal_Int32 index,
404 PolymorphicUnoType
const & polymorphicUnoType,
405 sal_Int32 typeParameterIndex);
409 Kind kind, OString name, SpecialType specialType, Flags flags,
410 sal_Int32 index, PolymorphicUnoType polymorphicUnoType);
414 OString parameterName, SpecialType specialType,
415 bool inParameter,
bool outParameter, OString methodName,
416 sal_Int32 index, PolymorphicUnoType polymorphicUnoType);
418 sal_uInt16 generateCode(ClassFile::Code & code, std::set<OUString> * dependencies)
421 void generatePolymorphicUnoTypeCode(
422 ClassFile::Code & code, std::set<OUString> * dependencies)
const;
429 OString m_methodName;
430 PolymorphicUnoType m_polymorphicUnoType;
431 sal_Int32 m_typeParameterIndex;
434sal_Int32 translateSpecialTypeFlags(
435 SpecialType specialType,
bool inParameter,
bool outParameter)
437 static sal_Int32
const specialTypeFlags[SPECIAL_TYPE_INTERFACE + 1] = {
438 0, 0x0040 , 0x0004 , 0x0080 };
439 sal_Int32 flags = specialTypeFlags[specialType];
450 OString name, SpecialType specialType, sal_Int32 index,
451 PolymorphicUnoType
const & polymorphicUnoType,
452 sal_Int32 typeParameterIndex):
454 m_flags(translateSpecialTypeFlags(specialType, false, false)),
455 m_index(
index), m_polymorphicUnoType(polymorphicUnoType),
456 m_typeParameterIndex(typeParameterIndex)
459 polymorphicUnoType.kind == PolymorphicUnoType::KIND_NONE
460 ? typeParameterIndex >= -1 : typeParameterIndex == -1);
464 Kind kind, OString name, SpecialType specialType, Flags flags,
465 sal_Int32 index, PolymorphicUnoType polymorphicUnoType):
467 m_flags(flags | translateSpecialTypeFlags(specialType, false, false)),
469 m_typeParameterIndex(0)
471 assert(kind == KIND_ATTRIBUTE || kind == KIND_METHOD);
475 OString parameterName, SpecialType specialType,
bool inParameter,
476 bool outParameter, OString methodName, sal_Int32 index,
477 PolymorphicUnoType polymorphicUnoType):
478 m_kind(KIND_PARAMETER),
m_name(
std::move(parameterName)),
479 m_flags(translateSpecialTypeFlags(specialType, inParameter, outParameter)),
481 m_polymorphicUnoType(
std::move(polymorphicUnoType)),
482 m_typeParameterIndex(0)
485sal_uInt16 TypeInfo::generateCode(
486 ClassFile::Code & code, std::set<OUString> * dependencies)
const
490 code.instrNew(
"com/sun/star/lib/uno/typeinfo/MemberTypeInfo");
492 code.loadStringConstant(m_name);
493 code.loadIntegerConstant(m_index);
494 code.loadIntegerConstant(m_flags);
495 if (m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE) {
496 generatePolymorphicUnoTypeCode(code, dependencies);
497 code.loadIntegerConstant(m_typeParameterIndex);
498 code.instrInvokespecial(
499 "com/sun/star/lib/uno/typeinfo/MemberTypeInfo",
"<init>",
500 "(Ljava/lang/String;IILcom/sun/star/uno/Type;I)V");
502 }
else if (m_typeParameterIndex >= 0) {
503 code.instrAconstNull();
504 code.loadIntegerConstant(m_typeParameterIndex);
505 code.instrInvokespecial(
506 "com/sun/star/lib/uno/typeinfo/MemberTypeInfo",
"<init>",
507 "(Ljava/lang/String;IILcom/sun/star/uno/Type;I)V");
510 code.instrInvokespecial(
511 "com/sun/star/lib/uno/typeinfo/MemberTypeInfo",
"<init>",
512 "(Ljava/lang/String;II)V");
516 code.instrNew(
"com/sun/star/lib/uno/typeinfo/AttributeTypeInfo");
518 code.loadStringConstant(m_name);
519 code.loadIntegerConstant(m_index);
520 code.loadIntegerConstant(m_flags);
521 if (m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE) {
522 generatePolymorphicUnoTypeCode(code, dependencies);
523 code.instrInvokespecial(
524 "com/sun/star/lib/uno/typeinfo/AttributeTypeInfo",
"<init>",
525 "(Ljava/lang/String;IILcom/sun/star/uno/Type;)V");
528 code.instrInvokespecial(
529 "com/sun/star/lib/uno/typeinfo/AttributeTypeInfo",
"<init>",
530 "(Ljava/lang/String;II)V");
534 code.instrNew(
"com/sun/star/lib/uno/typeinfo/MethodTypeInfo");
536 code.loadStringConstant(m_name);
537 code.loadIntegerConstant(m_index);
538 code.loadIntegerConstant(m_flags);
539 if (m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE) {
540 generatePolymorphicUnoTypeCode(code, dependencies);
541 code.instrInvokespecial(
542 "com/sun/star/lib/uno/typeinfo/MethodTypeInfo",
"<init>",
543 "(Ljava/lang/String;IILcom/sun/star/uno/Type;)V");
546 code.instrInvokespecial(
547 "com/sun/star/lib/uno/typeinfo/MethodTypeInfo",
"<init>",
548 "(Ljava/lang/String;II)V");
552 code.instrNew(
"com/sun/star/lib/uno/typeinfo/ParameterTypeInfo");
554 code.loadStringConstant(m_name);
555 code.loadStringConstant(m_methodName);
556 code.loadIntegerConstant(m_index);
557 code.loadIntegerConstant(m_flags);
558 if (m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE) {
559 generatePolymorphicUnoTypeCode(code, dependencies);
560 code.instrInvokespecial(
561 "com/sun/star/lib/uno/typeinfo/ParameterTypeInfo",
"<init>",
562 (
"(Ljava/lang/String;Ljava/lang/String;II"
563 "Lcom/sun/star/uno/Type;)V"));
566 code.instrInvokespecial(
567 "com/sun/star/lib/uno/typeinfo/ParameterTypeInfo",
"<init>",
568 "(Ljava/lang/String;Ljava/lang/String;II)V");
577void TypeInfo::generatePolymorphicUnoTypeCode(
578 ClassFile::Code & code, std::set<OUString> * dependencies)
const
580 assert(dependencies !=
nullptr);
581 assert(m_polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE);
582 code.instrNew(
"com/sun/star/uno/Type");
584 code.loadStringConstant(
586 if (m_polymorphicUnoType.kind == PolymorphicUnoType::KIND_STRUCT) {
588 "com/sun/star/uno/TypeClass",
"STRUCT",
589 "Lcom/sun/star/uno/TypeClass;");
592 "com/sun/star/uno/TypeClass",
"SEQUENCE",
593 "Lcom/sun/star/uno/TypeClass;");
595 dependencies->insert(
"com.sun.star.uno.TypeClass");
596 code.instrInvokespecial(
597 "com/sun/star/uno/Type",
"<init>",
598 "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V");
615 bCheck = options.
isValid(
"-Gc");
618 tempfile.createTempFile(
getTempDir(filename));
619 if (!tempfile.isValid()) {
621 "Cannot create temporary file for " +
b2u(filename));
623 OString tempname(tempfile.getName());
625 classFile.
write(tempfile);
638 "Cannot create " +
b2u(filename) +
" from temporary file "
644 OString
const & className, std::vector< TypeInfo >
const & typeInfo,
645 std::set<OUString> * dependencies,
ClassFile * classFile)
647 assert(classFile !=
nullptr);
648 std::vector< TypeInfo >::size_type typeInfos = typeInfo.size();
649 if (typeInfos > SAL_MAX_INT32) {
651 "UNOTYPEINFO array too big for Java class file format");
657 static_cast< ClassFile::AccessFlags
>(
658 ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC
659 | ClassFile::ACC_FINAL),
660 "UNOTYPEINFO",
"[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;",
662 std::unique_ptr< ClassFile::Code >
code(classFile->
newCode());
663 code->loadIntegerConstant(
static_cast< sal_Int32
>(typeInfos));
664 code->instrAnewarray(
"com/sun/star/lib/uno/typeinfo/TypeInfo");
666 sal_uInt16 stack = 0;
667 for (
const TypeInfo& ti : typeInfo)
670 code->loadIntegerConstant(index++);
671 stack = std::max(stack, ti.generateCode(*code, dependencies));
672 code->instrAastore();
674 code->instrPutstatic(
675 className,
"UNOTYPEINFO",
676 "[Lcom/sun/star/lib/uno/typeinfo/TypeInfo;");
678 if (stack > SAL_MAX_UINT16 - 4) {
680 "Stack too big for Java class file format");
682 code->setMaxStackAndLocals(
static_cast< sal_uInt16
>(stack + 4), 0);
684 static_cast< ClassFile::AccessFlags
>(
685 ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC),
686 "<clinit>",
"()V",
code.get(), std::vector< OString >(),
"");
695 std::unique_ptr< ClassFile > cf(
697 static_cast< ClassFile::AccessFlags
>(
698 ClassFile::ACC_PUBLIC | ClassFile::ACC_FINAL
699 | ClassFile::ACC_SUPER),
700 className,
"com/sun/star/uno/Enum",
""));
701 OString classDescriptor(
"L" + className +
";");
706 static_cast< ClassFile::AccessFlags
>(
707 ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC
708 | ClassFile::ACC_FINAL),
709 fieldName, classDescriptor, 0, OString());
711 static_cast< ClassFile::AccessFlags
>(
712 ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC
713 | ClassFile::ACC_FINAL),
714 fieldName +
"_value",
"I",
715 cf->addIntegerInfo(member.value),
"");
717 std::unique_ptr< ClassFile::Code >
code(cf->newCode());
718 code->loadLocalReference(0);
719 code->loadLocalInteger(1);
720 code->instrInvokespecial(
"com/sun/star/uno/Enum",
"<init>",
"(I)V");
722 code->setMaxStackAndLocals(2, 2);
724 ClassFile::ACC_PRIVATE,
725 "<init>",
"(I)V",
code.get(),
726 std::vector< OString >(),
"");
727 code = cf->newCode();
728 code->instrGetstatic(
732 code->instrAreturn();
733 code->setMaxStackAndLocals(1, 0);
735 static_cast< ClassFile::AccessFlags
>(
736 ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC),
737 "getDefault",
"()" + classDescriptor,
738 code.get(), std::vector< OString >(),
"");
739 code = cf->newCode();
740 code->loadLocalInteger(0);
741 std::map< sal_Int32, OString >
map;
746 min = std::min(min, member.value);
747 max = std::max(max, member.value);
750 sal_uInt64
size =
static_cast< sal_uInt64
>(
map.size());
751 if ((
static_cast< sal_uInt64
>(max) -
static_cast< sal_uInt64
>(min)
755 std::unique_ptr< ClassFile::Code > defCode(cf->newCode());
756 defCode->instrAconstNull();
757 defCode->instrAreturn();
758 std::vector< std::unique_ptr<ClassFile::Code> > blocks;
761 for (
const auto& pair : map)
763 sal_Int32
value = pair.first;
764 if (last != SAL_MAX_INT32) {
765 for (sal_Int32 j = last + 1; j <
value; ++j) {
766 blocks.push_back(
nullptr);
770 std::unique_ptr< ClassFile::Code > blockCode(cf->newCode());
771 blockCode->instrGetstatic(className, pair.second, classDescriptor);
772 blockCode->instrAreturn();
773 blocks.push_back(std::move(blockCode));
775 code->instrTableswitch(defCode.get(), min, blocks);
777 std::unique_ptr< ClassFile::Code > defCode(cf->newCode());
778 defCode->instrAconstNull();
779 defCode->instrAreturn();
780 std::vector< std::pair< sal_Int32, ClassFile::Code * > > blocks;
782 for (
const auto& pair : map )
784 std::unique_ptr< ClassFile::Code > blockCode(cf->newCode());
785 blockCode->instrGetstatic(className, pair.second, classDescriptor);
786 blockCode->instrAreturn();
787 blocks.emplace_back(pair.first, blockCode.release());
789 code->instrLookupswitch(defCode.get(), blocks);
790 for (
const std::pair< sal_Int32, ClassFile::Code * >& pair : blocks)
795 code->setMaxStackAndLocals(1, 1);
797 static_cast< ClassFile::AccessFlags
>(
798 ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC),
799 "fromInt",
"(I)" + classDescriptor,
code.get(),
800 std::vector< OString >(),
"");
801 code = cf->newCode();
804 code->instrNew(className);
806 code->loadIntegerConstant(member.value);
807 code->instrInvokespecial(className,
"<init>",
"(I)V");
808 code->instrPutstatic(
812 code->setMaxStackAndLocals(3, 0);
814 static_cast< ClassFile::AccessFlags
>(
815 ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC),
816 "<clinit>",
"()V",
code.get(), std::vector< OString >(),
"");
817 writeClassFile(options, className, *cf);
822 ClassFile * classFile, std::vector< TypeInfo > * typeInfo,
823 sal_Int32 typeParameterIndex, OUString
const & type, OUString
const & name,
826 assert(classFile !=
nullptr);
827 assert(typeInfo !=
nullptr);
830 SpecialType specialType;
831 PolymorphicUnoType polymorphicUnoType;
832 if (typeParameterIndex >= 0) {
833 descriptor =
"Ljava/lang/Object;";
836 specialType = SPECIAL_TYPE_NONE;
838 specialType = getFieldDescriptor(
839 manager, dependencies, type, &descriptor, &signature,
840 &polymorphicUnoType);
848 polymorphicUnoType, typeParameterIndex));
851sal_uInt16 addFieldInit(
853 OUString
const & fieldName,
bool typeParameter, std::u16string_view fieldType,
854 std::set<OUString> * dependencies, ClassFile::Code * code)
857 assert(code !=
nullptr);
864 std::vector< OUString >
args;
867 fieldType,
true, &nucleus, &rank, &args, &ent);
884 code->loadLocalReference(0);
885 code->loadStringConstant(OString());
886 code->instrPutfield(className, name,
"Ljava/lang/String;");
889 code->loadLocalReference(0);
890 code->instrGetstatic(
891 "com/sun/star/uno/Type",
"VOID",
"Lcom/sun/star/uno/Type;");
892 code->instrPutfield(className, name,
"Lcom/sun/star/uno/Type;");
895 code->loadLocalReference(0);
896 code->instrGetstatic(
897 "com/sun/star/uno/Any",
"VOID",
"Lcom/sun/star/uno/Any;");
898 code->instrPutfield(className, name,
"Ljava/lang/Object;");
905 code->loadLocalReference(0);
906 OStringBuffer descBuf(128);
907 translateUnoTypeToDescriptor(
908 manager, sort, nucleus, 0, std::vector< OUString >(),
false,
909 false, dependencies, &descBuf,
nullptr,
nullptr,
nullptr);
910 OString desc(descBuf.makeStringAndClear());
911 code->instrGetstatic(
914 code->instrPutfield(className, name, desc);
920 code->loadLocalReference(0);
924 code->instrInvokespecial(
927 OStringBuffer desc(128);
928 translateUnoTypeToDescriptor(
929 manager, sort, nucleus, 0, args,
false,
false, dependencies,
930 &desc,
nullptr,
nullptr,
nullptr);
931 code->instrPutfield(className, name, desc.makeStringAndClear());
936 for (;;) std::abort();
939 OUString::Concat(
"unexpected entity \"") + fieldType
940 +
"\" in call to addFieldInit");
943 code->loadLocalReference(0);
944 code->loadIntegerConstant(0);
949 code->instrNewarray(sort);
951 code->instrAnewarray(
957 OStringBuffer desc(128);
958 translateUnoTypeToDescriptor(
959 manager, sort, nucleus, rank - 1, std::vector< OUString >(),
false,
960 false, dependencies, &desc,
nullptr,
nullptr,
nullptr);
961 code->instrAnewarray(desc.makeStringAndClear());
963 OStringBuffer desc(128);
964 translateUnoTypeToDescriptor(
965 manager, sort, nucleus, rank, std::vector< OUString >(),
false,
false,
966 dependencies, &desc,
nullptr,
nullptr,
nullptr);
967 code->instrPutfield(className, name, desc.makeStringAndClear());
971sal_uInt16 addLoadLocal(
973 sal_uInt16 * index,
bool typeParameter, std::u16string_view type,
bool any,
974 std::set<OUString> * dependencies)
977 assert(code !=
nullptr);
978 assert(index !=
nullptr);
979 assert(!(typeParameter && any));
980 assert(dependencies !=
nullptr);
981 sal_uInt16 stack = 1;
984 code->loadLocalReference(*index);
989 std::vector< OUString >
args;
991 type,
true, &nucleus, &rank, &args,
nullptr);
996 code->instrNew(
"java/lang/Boolean");
998 code->loadLocalInteger(*index);
999 code->instrInvokespecial(
1000 "java/lang/Boolean",
"<init>",
"(Z)V");
1003 code->loadLocalInteger(*index);
1010 code->instrNew(
"java/lang/Byte");
1012 code->loadLocalInteger(*index);
1013 code->instrInvokespecial(
1014 "java/lang/Byte",
"<init>",
"(B)V");
1017 code->loadLocalInteger(*index);
1024 code->instrNew(
"java/lang/Short");
1026 code->loadLocalInteger(*index);
1027 code->instrInvokespecial(
1028 "java/lang/Short",
"<init>",
"(S)V");
1031 code->loadLocalInteger(*index);
1038 code->instrNew(
"com/sun/star/uno/Any");
1040 code->instrGetstatic(
1041 "com/sun/star/uno/Type",
"UNSIGNED_SHORT",
1042 "Lcom/sun/star/uno/Type;");
1043 code->instrNew(
"java/lang/Short");
1045 code->loadLocalInteger(*index);
1046 code->instrInvokespecial(
1047 "java/lang/Short",
"<init>",
"(S)V");
1048 code->instrInvokespecial(
1049 "com/sun/star/uno/Any",
"<init>",
1050 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V");
1053 code->loadLocalInteger(*index);
1060 code->instrNew(
"java/lang/Integer");
1062 code->loadLocalInteger(*index);
1063 code->instrInvokespecial(
1064 "java/lang/Integer",
"<init>",
"(I)V");
1067 code->loadLocalInteger(*index);
1074 code->instrNew(
"com/sun/star/uno/Any");
1076 code->instrGetstatic(
1077 "com/sun/star/uno/Type",
"UNSIGNED_LONG",
1078 "Lcom/sun/star/uno/Type;");
1079 code->instrNew(
"java/lang/Integer");
1081 code->loadLocalInteger(*index);
1082 code->instrInvokespecial(
1083 "java/lang/Integer",
"<init>",
"(I)V");
1084 code->instrInvokespecial(
1085 "com/sun/star/uno/Any",
"<init>",
1086 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V");
1089 code->loadLocalInteger(*index);
1096 code->instrNew(
"java/lang/Long");
1098 code->loadLocalLong(*index);
1099 code->instrInvokespecial(
1100 "java/lang/Long",
"<init>",
"(J)V");
1103 code->loadLocalLong(*index);
1110 code->instrNew(
"com/sun/star/uno/Any");
1112 code->instrGetstatic(
1113 "com/sun/star/uno/Type",
"UNSIGNED_HYPER",
1114 "Lcom/sun/star/uno/Type;");
1115 code->instrNew(
"java/lang/Long");
1117 code->loadLocalLong(*index);
1118 code->instrInvokespecial(
1119 "java/lang/Long",
"<init>",
"(J)V");
1120 code->instrInvokespecial(
1121 "com/sun/star/uno/Any",
"<init>",
1122 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V");
1125 code->loadLocalLong(*index);
1132 code->instrNew(
"java/lang/Float");
1134 code->loadLocalFloat(*index);
1135 code->instrInvokespecial(
1136 "java/lang/Float",
"<init>",
"(F)V");
1139 code->loadLocalFloat(*index);
1146 code->instrNew(
"java/lang/Double");
1148 code->loadLocalDouble(*index);
1149 code->instrInvokespecial(
1150 "java/lang/Double",
"<init>",
"(D)V");
1153 code->loadLocalDouble(*index);
1160 code->instrNew(
"java/lang/Character");
1162 code->loadLocalInteger(*index);
1163 code->instrInvokespecial(
1164 "java/lang/Character",
"<init>",
"(C)V");
1167 code->loadLocalInteger(*index);
1175 code->loadLocalReference(*index);
1181 code->loadLocalReference(*index);
1187 code->instrNew(
"com/sun/star/uno/Any");
1189 code->instrNew(
"com/sun/star/uno/Type");
1191 code->loadStringConstant(
1193 createUnoName(manager, nucleus, rank, args)));
1194 code->instrGetstatic(
1195 "com/sun/star/uno/TypeClass",
"STRUCT",
1196 "Lcom/sun/star/uno/TypeClass;");
1197 dependencies->insert(
"com.sun.star.uno.TypeClass");
1198 code->instrInvokespecial(
1199 "com/sun/star/uno/Type",
"<init>",
1200 "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V");
1201 code->loadLocalReference(*index);
1202 code->instrInvokespecial(
1203 "com/sun/star/uno/Any",
"<init>",
1204 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V");
1207 code->loadLocalReference(*index);
1213 if (any && nucleus !=
"com.sun.star.uno.XInterface") {
1214 code->instrNew(
"com/sun/star/uno/Any");
1216 code->instrNew(
"com/sun/star/uno/Type");
1219 code->instrGetstatic(
1220 "com/sun/star/uno/TypeClass",
"INTERFACE",
1221 "Lcom/sun/star/uno/TypeClass;");
1222 dependencies->insert(
"com.sun.star.uno.TypeClass");
1223 code->instrInvokespecial(
1224 "com/sun/star/uno/Type",
"<init>",
1225 "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V");
1226 code->loadLocalReference(*index);
1227 code->instrInvokespecial(
1228 "com/sun/star/uno/Any",
"<init>",
1229 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V");
1232 code->loadLocalReference(*index);
1239 for (;;) std::abort();
1242 OUString::Concat(
"unexpected entity \"") + type
1243 +
"\" in call to addLoadLocal");
1277 for (;;) std::abort();
1280 OUString::Concat(
"unexpected entity \"") + type
1281 +
"\" in call to addLoadLocal");
1285 code->instrNew(
"com/sun/star/uno/Any");
1287 code->instrNew(
"com/sun/star/uno/Type");
1289 code->loadStringConstant(
1291 createUnoName(manager, nucleus, rank, args)));
1292 code->instrInvokespecial(
1293 "com/sun/star/uno/Type",
"<init>",
"(Ljava/lang/String;)V");
1294 code->loadLocalReference(*index);
1295 code->instrInvokespecial(
1296 "com/sun/star/uno/Any",
"<init>",
1297 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)V");
1300 code->loadLocalReference(*index);
1306 if (*index > SAL_MAX_UINT16 - size) {
1308 "Too many local variables for Java class file format");
1314sal_uInt16 addDirectArgument(
1316 MethodDescriptor * methodDescriptor, ClassFile::Code * code,
1317 sal_uInt16 * index, OString
const & className, OString
const & fieldName,
1318 bool typeParameter, OUString
const & fieldType)
1320 assert(methodDescriptor !=
nullptr);
1321 assert(code !=
nullptr);
1323 if (typeParameter) {
1324 methodDescriptor->addTypeParameter(fieldType);
1325 desc =
"Ljava/lang/Object;";
1327 methodDescriptor->addParameter(fieldType,
false,
true,
nullptr);
1328 getFieldDescriptor(manager, dependencies, fieldType, &desc,
nullptr,
nullptr);
1330 code->loadLocalReference(0);
1331 sal_uInt16 stack = addLoadLocal(
1332 manager, code, index, typeParameter, fieldType,
false, dependencies);
1333 code->instrPutfield(className, fieldName, desc);
1337void addPlainStructBaseArguments(
1339 MethodDescriptor * methodDescriptor, ClassFile::Code * code,
1340 OUString
const & base, sal_uInt16 * index)
1343 assert(methodDescriptor !=
nullptr);
1345 if (
manager->getSort(base, &ent)
1349 "unexpected entity \"" + base
1350 +
"\" in call to addPlainStructBaseArguments");
1353 if (!ent2.getDirectBase().isEmpty()) {
1354 addPlainStructBaseArguments(
1355 manager, dependencies, methodDescriptor, code,
1356 ent2.getDirectBase(), index);
1360 methodDescriptor->addParameter(member.type,
false,
true,
nullptr);
1361 addLoadLocal(manager, code, index,
false, member.type,
false, dependencies);
1365void handlePlainStructType(
1366 const OUString& name,
1369 std::set<OUString> * dependencies)
1371 assert(entity.is());
1372 assert(dependencies !=
nullptr);
1375 if (entity->getDirectBase().isEmpty()) {
1376 superClass =
"java/lang/Object";
1380 dependencies->insert(entity->getDirectBase());
1382 std::unique_ptr< ClassFile > cf(
1384 static_cast< ClassFile::AccessFlags
>(
1385 ClassFile::ACC_PUBLIC | ClassFile::ACC_SUPER),
1386 className, superClass,
""));
1387 std::vector< TypeInfo > typeInfo;
1388 sal_Int32
index = 0;
1392 manager, dependencies, cf.get(), &typeInfo, -1, member.type, member.name,
1395 std::unique_ptr< ClassFile::Code >
code(cf->newCode());
1396 code->loadLocalReference(0);
1397 code->instrInvokespecial(superClass,
"<init>",
"()V");
1398 sal_uInt16 stack = 0;
1404 manager, className, member.name,
false, member.type, dependencies,
1407 code->instrReturn();
1408 code->setMaxStackAndLocals(stack + 1, 1);
1410 ClassFile::ACC_PUBLIC,
"<init>",
"()V",
code.get(),
1411 std::vector< OString >(),
"");
1412 MethodDescriptor desc(manager, dependencies, u
"void",
nullptr,
nullptr);
1413 code = cf->newCode();
1414 code->loadLocalReference(0);
1415 sal_uInt16 index2 = 1;
1416 if (!entity->getDirectBase().isEmpty()) {
1417 addPlainStructBaseArguments(
1418 manager, dependencies, &desc,
code.get(), entity->getDirectBase(),
1421 code->instrInvokespecial(superClass,
"<init>", desc.getDescriptor());
1422 sal_uInt16 maxSize = index2;
1428 manager, dependencies, &desc,
code.get(), &index2, className,
1431 code->instrReturn();
1432 code->setMaxStackAndLocals(maxSize, index2);
1434 ClassFile::ACC_PUBLIC,
"<init>", desc.getDescriptor(),
code.get(),
1435 std::vector< OString >(), desc.getSignature());
1436 addTypeInfo(className, typeInfo, dependencies, cf.get());
1437 writeClassFile(options, className, *cf);
1440void handlePolyStructType(
1441 const OUString& name,
1445 std::set<OUString> * dependencies)
1447 assert(entity.is());
1449 std::map< OUString, sal_Int32 > typeParameters;
1450 OStringBuffer sig(128);
1452 sal_Int32
index = 0;
1453 for (
const OUString& param : entity->getTypeParameters())
1456 if (!typeParameters.emplace(param, index++).second)
1461 sig.append(
">Ljava/lang/Object;");
1462 std::unique_ptr< ClassFile > cf(
1464 static_cast< ClassFile::AccessFlags
>(
1465 ClassFile::ACC_PUBLIC | ClassFile::ACC_SUPER),
1466 className,
"java/lang/Object", sig.makeStringAndClear()));
1467 std::vector< TypeInfo > typeInfo;
1471 sal_Int32 typeParameterIndex;
1472 if (member.parameterized) {
1473 std::map< OUString, sal_Int32 >::iterator it(
1474 typeParameters.find(member.type));
1475 if (it == typeParameters.end()) {
1478 typeParameterIndex = it->second;
1480 typeParameterIndex = -1;
1483 manager, dependencies, cf.get(), &typeInfo, typeParameterIndex,
1484 member.type, member.name, index++);
1486 std::unique_ptr< ClassFile::Code >
code(cf->newCode());
1487 code->loadLocalReference(0);
1488 code->instrInvokespecial(
"java/lang/Object",
"<init>",
"()V");
1489 sal_uInt16 stack = 0;
1495 manager, className, member.name, member.parameterized, member.type,
1496 dependencies,
code.get()));
1498 code->instrReturn();
1499 code->setMaxStackAndLocals(stack + 1, 1);
1501 ClassFile::ACC_PUBLIC,
"<init>",
"()V",
code.get(),
1502 std::vector< OString >(),
"");
1503 MethodDescriptor desc(manager, dependencies, u
"void",
nullptr,
nullptr);
1504 code = cf->newCode();
1505 code->loadLocalReference(0);
1506 sal_uInt16 index2 = 1;
1507 code->instrInvokespecial(
1508 "java/lang/Object",
"<init>", desc.getDescriptor());
1509 sal_uInt16 maxSize = index2;
1515 manager, dependencies, &desc,
code.get(), &index2, className,
1518 code->instrReturn();
1519 code->setMaxStackAndLocals(maxSize, index2);
1521 ClassFile::ACC_PUBLIC,
"<init>", desc.getDescriptor(),
code.get(),
1522 std::vector< OString >(), desc.getSignature());
1523 addTypeInfo(className, typeInfo, dependencies, cf.get());
1524 writeClassFile(options, className, *cf);
1527void addExceptionBaseArguments(
1529 MethodDescriptor * methodDescriptor, ClassFile::Code * code,
1530 OUString
const & base, sal_uInt16 * index)
1533 assert(methodDescriptor !=
nullptr);
1538 "unexpected entity \"" + base
1539 +
"\" in call to addExceptionBaseArguments");
1542 bool baseException =
base ==
"com.sun.star.uno.Exception";
1543 if (!baseException) {
1544 addExceptionBaseArguments(
1545 manager, dependencies, methodDescriptor, code,
1546 ent2.getDirectBase(), index);
1548 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(
1549 ent2.getDirectMembers().begin());
1550 i != ent2.getDirectMembers().end(); ++i)
1552 if (!baseException || i != ent2.getDirectMembers().begin()) {
1553 methodDescriptor->addParameter(
i->type,
false,
true,
nullptr);
1555 manager, code, index,
false,
i->type,
false, dependencies);
1560void handleExceptionType(
1563 std::set<OUString> * dependencies)
1565 assert(entity.is());
1566 assert(dependencies !=
nullptr);
1568 bool baseException =
false;
1569 bool baseRuntimeException =
false;
1571 if (className ==
"com/sun/star/uno/Exception") {
1572 baseException =
true;
1573 superClass =
"java/lang/Exception";
1574 }
else if (className ==
"com/sun/star/uno/RuntimeException") {
1575 baseRuntimeException =
true;
1576 superClass =
"java/lang/RuntimeException";
1578 if (entity->getDirectBase().isEmpty()) {
1580 "Exception type \"" + name +
"\" lacks base");
1584 dependencies->insert(entity->getDirectBase());
1586 std::unique_ptr< ClassFile > cf(
1588 static_cast< ClassFile::AccessFlags
>(
1589 ClassFile::ACC_PUBLIC | ClassFile::ACC_SUPER),
1590 className, superClass,
""));
1591 std::vector< TypeInfo > typeInfo;
1592 sal_Int32
index = 0;
1593 if (baseRuntimeException) {
1595 manager, dependencies, cf.get(), &typeInfo, -1,
1596 "com.sun.star.uno.XInterface",
"Context", index++);
1598 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(
1599 entity->getDirectMembers().begin());
1600 i != entity->getDirectMembers().end(); ++i)
1602 if (!baseException || i != entity->getDirectMembers().begin()) {
1604 manager, dependencies, cf.get(), &typeInfo, -1,
i->type,
1610 std::unique_ptr< ClassFile::Code >
code(cf->newCode());
1611 code->loadLocalReference(0);
1612 code->instrInvokespecial(superClass,
"<init>",
"()V");
1613 sal_uInt16 stack = 0;
1614 if (baseRuntimeException) {
1618 manager, className,
"Context",
false,
1619 u
"com.sun.star.uno.XInterface", dependencies,
code.get()));
1621 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(
1622 entity->getDirectMembers().begin());
1623 i != entity->getDirectMembers().end(); ++i)
1625 if (!baseException || i != entity->getDirectMembers().begin()) {
1629 manager, className,
i->name,
false,
i->type, dependencies,
1633 code->instrReturn();
1634 code->setMaxStackAndLocals(stack + 1, 1);
1636 ClassFile::ACC_PUBLIC,
"<init>",
"()V",
code.get(),
1637 std::vector< OString >(),
"");
1641 code = cf->newCode();
1642 code->loadLocalReference(0);
1643 code->loadLocalReference(1);
1644 code->instrInvokespecial(superClass,
"<init>",
"(Ljava/lang/Throwable;)V");
1646 if (baseRuntimeException) {
1650 manager, className,
"Context",
false,
1651 u
"com.sun.star.uno.XInterface", dependencies,
code.get()));
1653 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(
1654 entity->getDirectMembers().begin());
1655 i != entity->getDirectMembers().end(); ++i)
1657 if (!baseException || i != entity->getDirectMembers().begin()) {
1661 manager, className,
i->name,
false,
i->type, dependencies,
1665 code->instrReturn();
1666 code->setMaxStackAndLocals(stack + 2, 2);
1668 ClassFile::ACC_PUBLIC,
"<init>",
"(Ljava/lang/Throwable;)V",
code.get(),
1669 std::vector< OString >(),
"");
1672 code = cf->newCode();
1673 code->loadLocalReference(0);
1674 if (baseException || baseRuntimeException) {
1675 code->loadLocalReference(2);
1676 code->loadLocalReference(1);
1677 code->instrInvokespecial(superClass,
"<init>",
"(Ljava/lang/String;Ljava/lang/Throwable;)V");
1679 code->loadLocalReference(1);
1680 code->loadLocalReference(2);
1681 code->instrInvokespecial(superClass,
"<init>",
"(Ljava/lang/Throwable;Ljava/lang/String;)V");
1684 if (baseRuntimeException) {
1688 manager, className,
"Context",
false,
1689 u
"com.sun.star.uno.XInterface", dependencies,
code.get()));
1691 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(
1692 entity->getDirectMembers().begin());
1693 i != entity->getDirectMembers().end(); ++i)
1695 if (!baseException || i != entity->getDirectMembers().begin()) {
1699 manager, className,
i->name,
false,
i->type, dependencies,
1703 code->instrReturn();
1704 code->setMaxStackAndLocals(stack + 3, 3);
1706 ClassFile::ACC_PUBLIC,
"<init>",
"(Ljava/lang/Throwable;Ljava/lang/String;)V",
code.get(),
1707 std::vector< OString >(),
"");
1710 code = cf->newCode();
1711 code->loadLocalReference(0);
1712 code->loadLocalReference(1);
1713 code->instrInvokespecial(superClass,
"<init>",
"(Ljava/lang/String;)V");
1715 if (baseRuntimeException) {
1719 manager, className,
"Context",
false,
1720 u
"com.sun.star.uno.XInterface", dependencies,
code.get()));
1722 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(
1723 entity->getDirectMembers().begin());
1724 i != entity->getDirectMembers().end(); ++i)
1726 if (!baseException || i != entity->getDirectMembers().begin()) {
1730 manager, className,
i->name,
false,
i->type, dependencies,
1734 code->instrReturn();
1735 code->setMaxStackAndLocals(stack + 2, 2);
1737 ClassFile::ACC_PUBLIC,
"<init>",
"(Ljava/lang/String;)V",
code.get(),
1738 std::vector< OString >(),
"");
1742 MethodDescriptor desc1(manager, dependencies, u
"void",
nullptr,
nullptr);
1743 code = cf->newCode();
1744 code->loadLocalReference(0);
1745 sal_uInt16 index2 = 1;
1746 code->loadLocalReference(index2++);
1747 desc1.addParameter(u
"string",
false,
true,
nullptr);
1748 if (!(baseException || baseRuntimeException)) {
1749 addExceptionBaseArguments(
1750 manager, dependencies, &desc1,
code.get(), entity->getDirectBase(),
1753 code->instrInvokespecial(superClass,
"<init>", desc1.getDescriptor());
1754 sal_uInt16 maxSize = index2;
1755 if (baseRuntimeException) {
1759 manager, dependencies, &desc1,
code.get(), &index2, className,
1760 "Context",
false,
"com.sun.star.uno.XInterface"));
1762 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(
1763 entity->getDirectMembers().begin());
1764 i != entity->getDirectMembers().end(); ++i)
1766 if (!baseException || i != entity->getDirectMembers().begin()) {
1770 manager, dependencies, &desc1,
code.get(), &index2,
1775 code->instrReturn();
1776 code->setMaxStackAndLocals(maxSize, index2);
1778 ClassFile::ACC_PUBLIC,
"<init>", desc1.getDescriptor(),
code.get(),
1779 std::vector< OString >(), desc1.getSignature());
1782 MethodDescriptor desc2(manager, dependencies, u
"void",
nullptr,
nullptr);
1783 code = cf->newCode();
1784 code->loadLocalReference(0);
1785 sal_uInt16 index3 = 3;
1788 desc2.addParameter(u
"string",
false,
true,
nullptr);
1789 if (baseException || baseRuntimeException) {
1790 code->loadLocalReference(2);
1791 code->loadLocalReference(1);
1792 code->instrInvokespecial(superClass,
"<init>",
"(Ljava/lang/String;Ljava/lang/Throwable;)V");
1794 code->loadLocalReference(1);
1795 code->loadLocalReference(2);
1796 addExceptionBaseArguments(
1797 manager, dependencies, &desc2,
code.get(), entity->getDirectBase(),
1799 code->instrInvokespecial(superClass,
"<init>", OString::Concat(
"(Ljava/lang/Throwable;") + desc2.getDescriptor().subView(1));
1801 sal_uInt16 maxSize2 = index3;
1802 if (baseRuntimeException) {
1803 maxSize2 = std::max(
1806 manager, dependencies, &desc2,
code.get(), &index3, className,
1807 "Context",
false,
"com.sun.star.uno.XInterface"));
1809 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
i(
1810 entity->getDirectMembers().begin());
1811 i != entity->getDirectMembers().end(); ++i)
1813 if (!baseException || i != entity->getDirectMembers().begin()) {
1814 maxSize2 = std::max(
1817 manager, dependencies, &desc2,
code.get(), &index3,
1822 code->instrReturn();
1823 code->setMaxStackAndLocals(maxSize2, index3);
1825 ClassFile::ACC_PUBLIC,
"<init>", OString::Concat(
"(Ljava/lang/Throwable;") + desc2.getDescriptor().subView(1),
code.get(),
1826 std::vector< OString >(), desc2.getSignature());
1828 addTypeInfo(className, typeInfo, dependencies, cf.get());
1829 writeClassFile(options, className, *cf);
1832void createExceptionsAttribute(
1834 std::vector< OUString >
const & exceptionTypes,
1835 std::set<OUString> * dependencies, std::vector< OString > * exceptions,
1838 assert(dependencies !=
nullptr);
1839 assert(exceptions !=
nullptr);
1840 for (
const OUString& ex : exceptionTypes)
1842 dependencies->insert(ex);
1844 exceptions->push_back(type);
1845 if (tree !=
nullptr) {
1846 tree->
add(
type.replace(
'/',
'.'), manager);
1851void handleInterfaceType(
1854 std::set<OUString> * dependencies)
1856 assert(entity.is());
1857 assert(dependencies !=
nullptr);
1859 std::unique_ptr< ClassFile > cf(
1861 static_cast< ClassFile::AccessFlags
>(
1862 ClassFile::ACC_PUBLIC | ClassFile::ACC_INTERFACE
1863 | ClassFile::ACC_ABSTRACT),
1864 className,
"java/lang/Object",
""));
1867 dependencies->insert(ar.name);
1873 if (className ==
"com/sun/star/lang/XEventListener") {
1874 cf->addInterface(
"java/util/EventListener");
1876 std::vector< TypeInfo > typeInfo;
1877 if (className !=
"com/sun/star/uno/XInterface") {
1878 sal_Int32
index = 0;
1881 SpecialType specialType;
1882 PolymorphicUnoType polymorphicUnoType;
1883 MethodDescriptor gdesc(
1884 manager, dependencies, attr.type, &specialType,
1885 &polymorphicUnoType);
1886 std::vector< OString > exc;
1887 createExceptionsAttribute(
1888 manager, attr.getExceptions, dependencies, &exc,
nullptr);
1891 static_cast< ClassFile::AccessFlags
>(
1892 ClassFile::ACC_PUBLIC | ClassFile::ACC_ABSTRACT),
1893 "get" + attrName, gdesc.getDescriptor(),
nullptr, exc,
1894 gdesc.getSignature());
1895 if (!attr.readOnly) {
1896 MethodDescriptor sdesc(manager, dependencies, u
"void",
nullptr,
nullptr);
1897 sdesc.addParameter(attr.type,
false,
true,
nullptr);
1898 std::vector< OString > exc2;
1899 createExceptionsAttribute(
1900 manager, attr.setExceptions, dependencies, &exc2,
nullptr);
1902 static_cast< ClassFile::AccessFlags
>(
1903 ClassFile::ACC_PUBLIC | ClassFile::ACC_ABSTRACT),
1904 "set" + attrName, sdesc.getDescriptor(),
nullptr, exc2,
1905 sdesc.getSignature());
1907 typeInfo.emplace_back(
1908 TypeInfo::KIND_ATTRIBUTE, attrName, specialType,
1909 static_cast< TypeInfo::Flags
>(
1910 (attr.readOnly ? TypeInfo::FLAG_READONLY : 0)
1911 | (attr.bound ? TypeInfo::FLAG_BOUND : 0)),
1912 index, polymorphicUnoType);
1913 index += (attr.readOnly ? 1 : 2);
1918 SpecialType specialReturnType;
1919 PolymorphicUnoType polymorphicUnoReturnType;
1920 MethodDescriptor desc(
1921 manager, dependencies, method.returnType, &specialReturnType,
1922 &polymorphicUnoReturnType);
1923 typeInfo.emplace_back(
1924 TypeInfo::KIND_METHOD, methodName, specialReturnType,
1925 static_cast< TypeInfo::Flags
>(0), index++,
1926 polymorphicUnoReturnType);
1927 sal_Int32 paramIndex = 0;
1934 PolymorphicUnoType polymorphicUnoType;
1935 SpecialType specialType = desc.addParameter(
1936 param.
type, out,
true, &polymorphicUnoType);
1937 if (out || isSpecialType(specialType)
1938 || polymorphicUnoType.kind != PolymorphicUnoType::KIND_NONE)
1940 typeInfo.emplace_back(
1942 out, methodName, paramIndex, polymorphicUnoType);
1946 std::vector< OString > exc2;
1947 createExceptionsAttribute(
1948 manager, method.exceptions, dependencies, &exc2,
nullptr);
1950 static_cast< ClassFile::AccessFlags
>(
1951 ClassFile::ACC_PUBLIC | ClassFile::ACC_ABSTRACT),
1952 methodName, desc.getDescriptor(),
nullptr, exc2, desc.getSignature());
1955 addTypeInfo(className, typeInfo, dependencies, cf.get());
1956 writeClassFile(options, className, *cf);
1963 assert(entity.is());
1965 assert(dependencies !=
nullptr);
1967 switch (
manager->decompose(entity->getType(),
false, &nucleus,
nullptr,
nullptr,
nullptr))
1988 dependencies->insert(nucleus);
1995void handleConstantGroup(
1998 std::set<OUString> * dependencies)
2000 assert(entity.is());
2002 std::unique_ptr< ClassFile > cf(
2004 static_cast< ClassFile::AccessFlags
>(
2005 ClassFile::ACC_PUBLIC | ClassFile::ACC_INTERFACE
2006 | ClassFile::ACC_ABSTRACT),
2007 className,
"java/lang/Object",
""));
2011 sal_uInt16 valueIndex = sal_uInt16();
2012 switch (member.value.type) {
2015 valueIndex = cf->addIntegerInfo(sal_Int32(member.value.booleanValue));
2019 valueIndex = cf->addIntegerInfo(member.value.byteValue);
2023 valueIndex = cf->addIntegerInfo(member.value.shortValue);
2026 type =
"unsigned short";
2027 valueIndex = cf->addIntegerInfo(member.value.unsignedShortValue);
2031 valueIndex = cf->addIntegerInfo(member.value.longValue);
2034 type =
"unsigned long";
2035 valueIndex = cf->addIntegerInfo(
2036 static_cast< sal_Int32
>(member.value.unsignedLongValue));
2040 valueIndex = cf->addLongInfo(member.value.hyperValue);
2043 type =
"unsigned hyper";
2044 valueIndex = cf->addLongInfo(
2045 static_cast< sal_Int64
>(member.value.unsignedHyperValue));
2049 valueIndex = cf->addFloatInfo(member.value.floatValue);
2053 valueIndex = cf->addDoubleInfo(member.value.doubleValue);
2058 getFieldDescriptor(manager, dependencies, type, &desc, &sig,
nullptr);
2060 static_cast< ClassFile::AccessFlags
>(
2061 ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC
2062 | ClassFile::ACC_FINAL),
2065 writeClassFile(options, className, *cf);
2068void addExceptionHandlers(
2070 ClassFile::Code::Position start, ClassFile::Code::Position end,
2071 ClassFile::Code::Position handler, ClassFile::Code * code)
2073 assert(node !=
nullptr);
2074 assert(code !=
nullptr);
2076 code->addException(start, end, handler, node->
name.replace(
'.',
'/'));
2078 for (std::unique_ptr<codemaker::ExceptionTreeNode>
const & p : node->
children)
2080 addExceptionHandlers(
p.get(), start, end, handler, code);
2087 std::string_view realJavaBaseName, OString
const & unoName,
2088 OString
const & className,
2090 OUString
const & returnType, std::set<OUString> * dependencies,
2093 assert(dependencies !=
nullptr);
2094 assert(classFile !=
nullptr);
2095 MethodDescriptor desc(manager, dependencies, returnType,
nullptr,
nullptr);
2096 desc.addParameter(u
"com.sun.star.uno.XComponentContext",
false,
false,
nullptr);
2097 std::unique_ptr< ClassFile::Code >
code(classFile->
newCode());
2098 code->loadLocalReference(0);
2100 code->instrInvokeinterface(
2101 "com/sun/star/uno/XComponentContext",
"getServiceManager",
2102 "()Lcom/sun/star/lang/XMultiComponentFactory;", 1);
2104 code->loadStringConstant(unoName);
2107 ClassFile::Code::Position tryStart;
2108 ClassFile::Code::Position tryEnd;
2109 std::vector< OString > exc;
2111 sal_uInt16 localIndex = 1;
2112 ClassFile::AccessFlags access =
static_cast< ClassFile::AccessFlags
>(
2113 ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC);
2115 code->loadLocalReference(0);
2117 tryStart =
code->getPosition();
2118 code->instrInvokeinterface(
2119 "com/sun/star/lang/XMultiComponentFactory",
2120 "createInstanceWithContext",
2121 (
"(Ljava/lang/String;Lcom/sun/star/uno/XComponentContext;)"
2122 "Ljava/lang/Object;"),
2124 tryEnd =
code->getPosition();
2131 desc.addParameter(u
"any",
true,
true,
nullptr);
2132 code->loadLocalReference(localIndex++);
2135 access =
static_cast< ClassFile::AccessFlags
>(
2136 access | ClassFile::ACC_VARARGS);
2140 code->instrAnewarray(
"java/lang/Object");
2147 desc.addParameter(param.
type,
false,
true,
nullptr);
2150 code->loadIntegerConstant(n++);
2155 manager,
code.get(), &localIndex,
false, param.
type,
true,
2158 code->instrAastore();
2163 code->loadLocalReference(0);
2165 tryStart =
code->getPosition();
2166 code->instrInvokeinterface(
2167 "com/sun/star/lang/XMultiComponentFactory",
2168 "createInstanceWithArgumentsAndContext",
2169 (
"(Ljava/lang/String;[Ljava/lang/Object;"
2170 "Lcom/sun/star/uno/XComponentContext;)Ljava/lang/Object;"),
2172 tryEnd =
code->getPosition();
2174 createExceptionsAttribute(
2175 manager, constructor.
exceptions, dependencies, &exc, &tree);
2177 code->loadLocalReference(0);
2179 code->instrInvokestatic(
2180 className,
"$castInstance",
2181 (
"(Ljava/lang/Object;Lcom/sun/star/uno/XComponentContext;)"
2182 "Ljava/lang/Object;"));
2184 code->instrCheckcast(
2187 code->instrAreturn();
2189 ClassFile::Code::Position pos1 =
code->getPosition();
2191 code->instrInvokevirtual(
2192 "java/lang/Throwable",
"toString",
"()Ljava/lang/String;");
2194 localIndex = std::max< sal_uInt16 >(localIndex, 2);
2195 code->storeLocalReference(1);
2197 code->instrNew(
"com/sun/star/uno/DeploymentException");
2201 code->loadStringConstant(
2202 "component context fails to supply service " + unoName +
" of type "
2203 + realJavaBaseName +
": ");
2205 code->loadLocalReference(1);
2207 code->instrInvokevirtual(
2208 "java/lang/String",
"concat",
2209 "(Ljava/lang/String;)Ljava/lang/String;");
2211 code->loadLocalReference(0);
2213 code->instrInvokespecial(
2214 "com/sun/star/uno/DeploymentException",
"<init>",
2215 "(Ljava/lang/String;Ljava/lang/Object;)V");
2217 ClassFile::Code::Position pos2 =
code->getPosition();
2218 code->instrAthrow();
2219 addExceptionHandlers(
2220 &tree.
getRoot(), tryStart, tryEnd, pos2,
code.get());
2222 tryStart, tryEnd, pos1,
"com/sun/star/uno/Exception");
2223 dependencies->insert(
"com.sun.star.uno.Exception");
2224 stack = std::max< sal_uInt16 >(stack, 4);
2226 code->setMaxStackAndLocals(stack, localIndex);
2233 desc.getDescriptor(),
code.get(), exc, desc.getSignature());
2237 const OUString& name,
2240 std::set<OUString> * dependencies)
2242 assert(entity.is());
2243 assert(dependencies !=
nullptr);
2246 translateUnoidlEntityNameToJavaFullyQualifiedName(name,
"service"));
2247 std::unique_ptr< ClassFile > cf(
2249 static_cast< ClassFile::AccessFlags
>(
2250 ClassFile::ACC_PUBLIC | ClassFile::ACC_FINAL
2251 | ClassFile::ACC_SUPER),
2252 className,
"java/lang/Object",
""));
2253 if (!entity->getConstructors().empty()) {
2254 OString realJavaBaseName(
2256 dependencies->insert(entity->getBase());
2257 dependencies->insert(
"com.sun.star.lang.XMultiComponentFactory");
2258 dependencies->insert(
"com.sun.star.uno.DeploymentException");
2259 dependencies->insert(
"com.sun.star.uno.TypeClass");
2260 dependencies->insert(
"com.sun.star.uno.XComponentContext");
2262 entity->getConstructors())
2265 manager, realJavaBaseName, unoName, className, cons,
2266 entity->getBase(), dependencies, cf.get());
2270 std::unique_ptr< ClassFile::Code >
code(cf->newCode());
2271 code->instrNew(
"com/sun/star/uno/Type");
2275 code->loadStringConstant(realJavaBaseName);
2277 code->instrGetstatic(
2278 "com/sun/star/uno/TypeClass",
"INTERFACE",
2279 "Lcom/sun/star/uno/TypeClass;");
2281 code->instrInvokespecial(
2282 "com/sun/star/uno/Type",
"<init>",
2283 "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V");
2285 code->loadLocalReference(0);
2287 code->instrInvokestatic(
2288 "com/sun/star/uno/UnoRuntime",
"queryInterface",
2289 (
"(Lcom/sun/star/uno/Type;Ljava/lang/Object;)"
2290 "Ljava/lang/Object;"));
2294 ClassFile::Code::Branch branch =
code->instrIfnull();
2296 code->instrAreturn();
2297 code->branchHere(branch);
2300 code->instrNew(
"com/sun/star/uno/DeploymentException");
2304 code->loadStringConstant(
2305 "component context fails to supply service " + unoName
2306 +
" of type " + realJavaBaseName);
2308 code->loadLocalReference(1);
2310 code->instrInvokespecial(
2311 "com/sun/star/uno/DeploymentException",
"<init>",
2312 "(Ljava/lang/String;Ljava/lang/Object;)V");
2314 code->instrAthrow();
2315 code->setMaxStackAndLocals(4, 2);
2317 static_cast< ClassFile::AccessFlags
>(
2318 ClassFile::ACC_PRIVATE | ClassFile::ACC_STATIC
2319 | ClassFile::ACC_SYNTHETIC),
2321 (
"(Ljava/lang/Object;Lcom/sun/star/uno/XComponentContext;)"
2322 "Ljava/lang/Object;"),
2323 code.get(), std::vector< OString >(),
"");
2326 writeClassFile(options, className, *cf);
2329void handleSingleton(
2330 const OUString& name,
2333 std::set<OUString> * dependencies)
2335 assert(entity.is());
2336 assert(dependencies !=
nullptr);
2338 OString
base(realJavaBaseName.replace(
'.',
'/'));
2339 dependencies->insert(entity->getBase());
2342 translateUnoidlEntityNameToJavaFullyQualifiedName(name,
"singleton"));
2343 dependencies->insert(
"com.sun.star.uno.DeploymentException");
2344 dependencies->insert(
"com.sun.star.uno.TypeClass");
2345 dependencies->insert(
"com.sun.star.uno.XComponentContext");
2346 std::unique_ptr< ClassFile > cf(
2348 static_cast< ClassFile::AccessFlags
>(
2349 ClassFile::ACC_PUBLIC | ClassFile::ACC_FINAL
2350 | ClassFile::ACC_SUPER),
2351 className,
"java/lang/Object",
""));
2352 MethodDescriptor desc(manager, dependencies, entity->getBase(),
nullptr,
nullptr);
2353 desc.addParameter(u
"com.sun.star.uno.XComponentContext",
false,
false,
nullptr);
2354 std::unique_ptr< ClassFile::Code >
code(cf->newCode());
2355 code->loadLocalReference(0);
2357 code->loadStringConstant(
"/singletons/" + unoName);
2359 code->instrInvokeinterface(
2360 "com/sun/star/uno/XComponentContext",
"getValueByName",
2361 "(Ljava/lang/String;)Ljava/lang/Object;", 2);
2365 code->instrInstanceof(
"com/sun/star/uno/Any");
2367 ClassFile::Code::Branch branch1 =
code->instrIfeq();
2369 code->instrCheckcast(
"com/sun/star/uno/Any");
2373 code->instrInvokevirtual(
2374 "com/sun/star/uno/Any",
"getType",
"()Lcom/sun/star/uno/Type;");
2376 code->instrInvokevirtual(
2377 "com/sun/star/uno/Type",
"getTypeClass",
2378 "()Lcom/sun/star/uno/TypeClass;");
2380 code->instrGetstatic(
2381 "com/sun/star/uno/TypeClass",
"INTERFACE",
2382 "Lcom/sun/star/uno/TypeClass;");
2384 ClassFile::Code::Branch branch2 =
code->instrIfAcmpne();
2386 code->instrInvokevirtual(
2387 "com/sun/star/uno/Any",
"getObject",
"()Ljava/lang/Object;");
2389 code->branchHere(branch1);
2390 code->instrNew(
"com/sun/star/uno/Type");
2394 code->loadStringConstant(realJavaBaseName);
2396 code->instrGetstatic(
2397 "com/sun/star/uno/TypeClass",
"INTERFACE",
2398 "Lcom/sun/star/uno/TypeClass;");
2400 code->instrInvokespecial(
2401 "com/sun/star/uno/Type",
"<init>",
2402 "(Ljava/lang/String;Lcom/sun/star/uno/TypeClass;)V");
2406 code->instrInvokestatic(
2407 "com/sun/star/uno/UnoRuntime",
"queryInterface",
2408 "(Lcom/sun/star/uno/Type;Ljava/lang/Object;)Ljava/lang/Object;");
2412 ClassFile::Code::Branch branch3 =
code->instrIfnull();
2414 code->instrCheckcast(base);
2416 code->instrAreturn();
2417 code->branchHere(branch2);
2418 code->branchHere(branch3);
2421 code->instrNew(
"com/sun/star/uno/DeploymentException");
2425 code->loadStringConstant(
2426 "component context fails to supply singleton " + unoName +
" of type "
2427 + realJavaBaseName);
2429 code->loadLocalReference(0);
2431 code->instrInvokespecial(
2432 "com/sun/star/uno/DeploymentException",
"<init>",
2433 "(Ljava/lang/String;Ljava/lang/Object;)V");
2435 code->instrAthrow();
2436 code->setMaxStackAndLocals(5, 1);
2438 static_cast< ClassFile::AccessFlags
>(
2439 ClassFile::ACC_PUBLIC | ClassFile::ACC_STATIC),
2440 "get", desc.getDescriptor(),
code.get(), std::vector< OString >(),
2441 desc.getSignature());
2442 writeClassFile(options, className, *cf);
2458 std::set<OUString> deps;
2465 if (!
name.isEmpty()) {
2470 if (!cur->getNext(&mem).is()) {
2482 handlePlainStructType(
2487 handlePolyStructType(
2494 handleExceptionType(
2499 handleInterfaceType(
2508 handleConstantGroup(
2530 "unexpected entity \"" +
name +
"\" in call to produce");
2532 if (!options.
isValid(
"-nD")) {
2533 for (
const OUString&
d : deps) {
bool isValid(const ::rtl::OString &option) const
const OString & getOption(const ::rtl::OString &option) const
Represents the hierarchy formed by a set of UNO exception types.
void add(rtl::OString const &name, rtl::Reference< TypeManager > const &manager)
Builds the exception hierarchy, by adding one exception type at a time.
ExceptionTreeNode const & getRoot() const
Gives access to the resultant exception hierarchy.
A simple class to track which types have already been processed by a code maker.
bool contains(OString const &type) const
Checks whether a given type has already been generated.
void add(OString const &type)
Add a type to the set of generated types.
void addField(AccessFlags accessFlags, rtl::OString const &name, rtl::OString const &descriptor, sal_uInt16 constantValueIndex, rtl::OString const &signature)
void addMethod(AccessFlags accessFlags, rtl::OString const &name, rtl::OString const &descriptor, Code const *code, std::vector< rtl::OString > const &exceptions, rtl::OString const &signature)
void write(FileStream &file) const
std::unique_ptr< Code > newCode()
rtl::Reference< ParseManager > manager
OString getTempDir(const OString &sFileName)
bool removeTypeFile(const OString &fileName)
OString createFileNameFromType(const OString &destination, const OString &typeName, const OString &postfix)
bool fileExists(const OString &fileName)
bool makeValidTypeFile(const OString &targetFileName, const OString &tmpFileName, bool bFileCheck)
void produce(OUString const &name, rtl::Reference< TypeManager > const &manager, codemaker::GeneratedTypeSet &generated, JavaOptions const &options)
Sort
An enumeration of all the sorts of relevant UNOIDL entities.
@ InstantiatedPolymorphicStruct
@ InterfaceBasedSingleton
@ SingleInterfaceBasedService
@ PolymorphicStructTemplate
@ AccumulationBasedService
OString translateUnoToJavaType(codemaker::UnoType::Sort sort, std::string_view nucleus, bool referenceType)
OString translateUnoToJavaIdentifier(OString const &identifier, std::string_view prefix)
OString convertString(OUString const &string)
constexpr OUStringLiteral last
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
std::map< OUString, rtl::Reference< Entity > > map
Represents a node of the hierarchy from the ExceptionTree class.
std::vector< Parameter > parameters
std::vector< OUString > exceptions
OUString b2u(std::string_view s)
OString u2b(std::u16string_view s)