tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / bridges / source / cpp_uno / msvc_win32_arm64 / uno2cpp.cxx
blobb753509a8a6e28034e9854fcbf6a4a08d106f185
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 #include <sal/config.h>
22 #include <cassert>
23 #include <cstring>
24 #include <exception>
25 #include <typeinfo>
27 #include <bridge.hxx>
28 #include <types.hxx>
29 #include <unointerfaceproxy.hxx>
30 #include <vtables.hxx>
31 #include <com/sun/star/uno/Exception.hpp>
32 #include <com/sun/star/uno/RuntimeException.hpp>
33 #include <com/sun/star/uno/genfunc.hxx>
34 #include <rtl/textenc.h>
35 #include <rtl/ustring.hxx>
36 #include <sal/alloca.h>
37 #include <sal/types.h>
38 #include <typelib/typeclass.h>
39 #include <typelib/typedescription.h>
40 #include <uno/any2.h>
41 #include <uno/data.h>
43 #include "abi.hxx"
44 #include <msvc/arm64.hxx>
46 namespace
48 extern "C" void callVirtualFunction(sal_uInt64* regs, sal_uInt64* stack, sal_Int32 sp,
49 sal_uInt64 function);
51 void pushArgument(sal_uInt64 value, sal_uInt64* stack, sal_Int32& sp, sal_uInt64* regs,
52 sal_Int32& nregs)
54 (nregs != 8 ? regs[nregs++] : stack[sp++]) = value;
57 void call(bridges::cpp_uno::shared::UnoInterfaceProxy* pProxy,
58 bridges::cpp_uno::shared::VtableSlot slot, typelib_TypeDescriptionReference* returnType,
59 const sal_Int32 count, typelib_MethodParameter* parameters, void* returnValue,
60 void** arguments, uno_Any** exception)
62 static_assert(sizeof(sal_uInt64) == sizeof(void*));
63 typelib_TypeDescription* aReturnTD = nullptr;
64 TYPELIB_DANGER_GET(&aReturnTD, returnType);
65 const ReturnKind eRetKind = getReturnKind(aReturnTD);
66 const bool retConv = bridges::cpp_uno::shared::relatesToInterfaceType(aReturnTD);
67 void* ret = retConv ? alloca(aReturnTD->nSize) : returnValue;
69 sal_uInt64** thisPtr = reinterpret_cast<sal_uInt64**>(pProxy->getCppI()) + slot.offset;
71 void** cppArgs = static_cast<void**>(alloca(count * sizeof(void*)));
72 typelib_TypeDescription** ptds
73 = static_cast<typelib_TypeDescription**>(alloca(count * sizeof(typelib_TypeDescription*)));
75 sal_uInt64* gpr = static_cast<sal_uInt64*>(alloca(16 * sizeof(sal_uInt64)));
76 sal_uInt64* fpr = &gpr[8];
77 sal_uInt64* stack = static_cast<sal_uInt64*>(alloca(count * sizeof(sal_uInt64)));
79 sal_Int32 sp = 0;
80 sal_Int32 nGPR = 0;
81 sal_Int32 nFPR = 0;
82 gpr[nGPR++] = reinterpret_cast<sal_uInt64>(thisPtr);
83 if (eRetKind == RETURN_KIND_INDIRECT)
85 gpr[nGPR++] = reinterpret_cast<sal_uInt64>(ret);
88 for (sal_Int32 i = 0; i != count; ++i)
90 if (!parameters[i].bOut && bridges::cpp_uno::shared::isSimpleType(parameters[i].pTypeRef))
92 cppArgs[i] = 0;
93 switch (parameters[i].pTypeRef->eTypeClass)
95 case typelib_TypeClass_BOOLEAN:
96 pushArgument(*static_cast<sal_Bool*>(arguments[i]), stack, sp, gpr, nGPR);
97 break;
98 case typelib_TypeClass_BYTE:
99 pushArgument(*static_cast<sal_Int8*>(arguments[i]), stack, sp, gpr, nGPR);
100 break;
101 case typelib_TypeClass_SHORT:
102 pushArgument(*static_cast<sal_Int16*>(arguments[i]), stack, sp, gpr, nGPR);
103 break;
104 case typelib_TypeClass_UNSIGNED_SHORT:
105 pushArgument(*static_cast<sal_uInt16*>(arguments[i]), stack, sp, gpr, nGPR);
106 break;
107 case typelib_TypeClass_LONG:
108 case typelib_TypeClass_ENUM:
109 pushArgument(*static_cast<sal_Int32*>(arguments[i]), stack, sp, gpr, nGPR);
110 break;
111 case typelib_TypeClass_UNSIGNED_LONG:
112 pushArgument(*static_cast<sal_uInt32*>(arguments[i]), stack, sp, gpr, nGPR);
113 break;
114 case typelib_TypeClass_HYPER:
115 pushArgument(*static_cast<sal_Int64*>(arguments[i]), stack, sp, gpr, nGPR);
116 break;
117 case typelib_TypeClass_UNSIGNED_HYPER:
118 pushArgument(*static_cast<sal_uInt64*>(arguments[i]), stack, sp, gpr, nGPR);
119 break;
120 case typelib_TypeClass_FLOAT:
121 pushArgument(*static_cast<sal_uInt32*>(arguments[i]), stack, sp, fpr, nFPR);
122 break;
123 case typelib_TypeClass_DOUBLE:
124 pushArgument(*static_cast<sal_uInt64*>(arguments[i]), stack, sp, fpr, nFPR);
125 break;
126 case typelib_TypeClass_CHAR:
127 pushArgument(*static_cast<sal_Unicode*>(arguments[i]), stack, sp, gpr, nGPR);
128 break;
129 default:
130 assert(false);
133 else
135 typelib_TypeDescription* ptd = 0;
136 TYPELIB_DANGER_GET(&ptd, parameters[i].pTypeRef);
137 if (!parameters[i].bIn)
139 cppArgs[i] = alloca(ptd->nSize);
140 uno_constructData(cppArgs[i], ptd);
141 ptds[i] = ptd;
142 pushArgument(reinterpret_cast<sal_uInt64>(cppArgs[i]), stack, sp, gpr, nGPR);
144 else if (bridges::cpp_uno::shared::relatesToInterfaceType(ptd))
146 cppArgs[i] = alloca(ptd->nSize);
147 uno_copyAndConvertData(cppArgs[i], arguments[i], ptd,
148 pProxy->getBridge()->getUno2Cpp());
149 ptds[i] = ptd;
150 pushArgument(reinterpret_cast<sal_uInt64>(cppArgs[i]), stack, sp, gpr, nGPR);
152 else
154 cppArgs[i] = 0;
155 pushArgument(reinterpret_cast<sal_uInt64>(arguments[i]), stack, sp, gpr, nGPR);
156 TYPELIB_DANGER_RELEASE(ptd);
161 __try
163 callVirtualFunction(gpr, stack, sp, (*thisPtr)[slot.index]);
165 __except (msvc_filterCppException(GetExceptionInformation(), *exception,
166 pProxy->getBridge()->getCpp2Uno()))
168 for (sal_Int32 i = 0; i != count; ++i)
170 if (cppArgs[i] != 0)
172 uno_destructData(cppArgs[i], ptds[i],
173 reinterpret_cast<uno_ReleaseFunc>(css::uno::cpp_release));
174 TYPELIB_DANGER_RELEASE(ptds[i]);
177 TYPELIB_DANGER_RELEASE(aReturnTD);
178 return;
181 *exception = 0;
182 for (sal_Int32 i = 0; i != count; ++i)
184 if (cppArgs[i] != 0)
186 if (parameters[i].bOut)
188 if (parameters[i].bIn)
190 uno_destructData(arguments[i], ptds[i], 0);
192 uno_copyAndConvertData(arguments[i], cppArgs[i], ptds[i],
193 pProxy->getBridge()->getCpp2Uno());
195 uno_destructData(cppArgs[i], ptds[i],
196 reinterpret_cast<uno_ReleaseFunc>(css::uno::cpp_release));
197 TYPELIB_DANGER_RELEASE(ptds[i]);
201 switch (eRetKind)
203 case RETURN_KIND_REG:
204 switch (aReturnTD->eTypeClass)
206 case typelib_TypeClass_VOID:
207 break;
208 case typelib_TypeClass_BOOLEAN:
209 case typelib_TypeClass_BYTE:
210 case typelib_TypeClass_SHORT:
211 case typelib_TypeClass_UNSIGNED_SHORT:
212 case typelib_TypeClass_LONG:
213 case typelib_TypeClass_UNSIGNED_LONG:
214 case typelib_TypeClass_HYPER:
215 case typelib_TypeClass_UNSIGNED_HYPER:
216 case typelib_TypeClass_CHAR:
217 case typelib_TypeClass_ENUM:
218 case typelib_TypeClass_STRUCT:
219 std::memcpy(ret, gpr, aReturnTD->nSize);
220 break;
221 case typelib_TypeClass_FLOAT:
222 case typelib_TypeClass_DOUBLE:
223 std::memcpy(ret, fpr, aReturnTD->nSize);
224 break;
225 default:
226 assert(false);
228 break;
229 case RETURN_KIND_INDIRECT:
230 break;
233 if (retConv)
235 uno_copyAndConvertData(returnValue, ret, aReturnTD, pProxy->getBridge()->getCpp2Uno());
236 uno_destructData(ret, aReturnTD, reinterpret_cast<uno_ReleaseFunc>(css::uno::cpp_release));
238 TYPELIB_DANGER_RELEASE(aReturnTD);
242 namespace bridges::cpp_uno::shared
244 void unoInterfaceProxyDispatch(uno_Interface* pUnoI, typelib_TypeDescription const* pMemberDescr,
245 void* pReturn, void** pArgs, uno_Any** ppException)
247 UnoInterfaceProxy* pProxy = static_cast<UnoInterfaceProxy*>(pUnoI);
248 switch (pMemberDescr->eTypeClass)
250 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
252 typelib_InterfaceAttributeTypeDescription const* atd
253 = reinterpret_cast<typelib_InterfaceAttributeTypeDescription const*>(pMemberDescr);
254 VtableSlot slot(getVtableSlot(atd));
255 if (pReturn != 0)
256 { // getter
257 call(pProxy, slot, atd->pAttributeTypeRef, 0, 0, pReturn, pArgs, ppException);
259 else
260 { // setter
261 typelib_MethodParameter param = { 0, atd->pAttributeTypeRef, true, false };
262 typelib_TypeDescriptionReference* pReturnTD = nullptr;
263 typelib_typedescriptionreference_new(&pReturnTD, typelib_TypeClass_VOID,
264 OUString("void").pData);
265 slot.index += 1;
266 call(pProxy, slot, pReturnTD, 1, &param, pReturn, pArgs, ppException);
267 typelib_typedescriptionreference_release(pReturnTD);
269 break;
271 case typelib_TypeClass_INTERFACE_METHOD:
273 typelib_InterfaceMethodTypeDescription const* mtd
274 = reinterpret_cast<typelib_InterfaceMethodTypeDescription const*>(pMemberDescr);
275 VtableSlot slot(getVtableSlot(mtd));
276 switch (slot.index)
278 case 1:
279 pUnoI->acquire(pUnoI);
280 *ppException = 0;
281 break;
282 case 2:
283 pUnoI->release(pUnoI);
284 *ppException = 0;
285 break;
286 case 0:
288 typelib_TypeDescription* td = 0;
289 TYPELIB_DANGER_GET(
290 &td, (reinterpret_cast<css::uno::Type*>(pArgs[0])->getTypeLibType()));
291 if (td != 0)
293 uno_Interface* ifc = 0;
294 pProxy->pBridge->getUnoEnv()->getRegisteredInterface(
295 pProxy->pBridge->getUnoEnv(), reinterpret_cast<void**>(&ifc),
296 pProxy->oid.pData,
297 reinterpret_cast<typelib_InterfaceTypeDescription*>(td));
298 if (ifc != 0)
300 uno_any_construct(reinterpret_cast<uno_Any*>(pReturn), &ifc, td, 0);
301 ifc->release(ifc);
302 TYPELIB_DANGER_RELEASE(td);
303 *ppException = 0;
304 break;
306 TYPELIB_DANGER_RELEASE(td);
309 [[fallthrough]];
310 default:
311 call(pProxy, slot, mtd->pReturnTypeRef, mtd->nParams, mtd->pParams, pReturn,
312 pArgs, ppException);
313 break;
315 break;
317 default:
318 assert(false);
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */