Update ooo320-m1
[ooovba.git] / bridges / source / cpp_uno / gcc3_linux_powerpc / cpp2uno.cxx
blob238354b8e880d7ded7729c74f12071288b3eb639
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cpp2uno.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_bridges.hxx"
34 #include <string.h>
36 #include <com/sun/star/uno/genfunc.hxx>
37 #include <uno/data.h>
38 #include <typelib/typedescription.hxx>
40 #include "bridges/cpp_uno/shared/bridge.hxx"
41 #include "bridges/cpp_uno/shared/cppinterfaceproxy.hxx"
42 #include "bridges/cpp_uno/shared/types.hxx"
43 #include "bridges/cpp_uno/shared/vtablefactory.hxx"
45 #include "share.hxx"
46 // #include <stdio.h>
49 using namespace ::com::sun::star::uno;
51 namespace
54 //==================================================================================================
55 static typelib_TypeClass cpp2uno_call(
56 bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
57 const typelib_TypeDescription * pMemberTypeDescr,
58 typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
59 sal_Int32 nParams, typelib_MethodParameter * pParams,
60 void ** gpreg, void ** fpreg, void ** ovrflw,
61 sal_Int64 * pRegisterReturn /* space for register return */ )
63 int ng = 0; //number of gpr registers used
64 int nf = 0; //number of fpr regsiters used
65 void ** pCppStack; //temporary stack pointer
67 // gpreg: [ret *], this, [gpr params]
68 // fpreg: [fpr params]
69 // ovrflw: [gpr or fpr params (properly aligned)]
71 // return
72 typelib_TypeDescription * pReturnTypeDescr = 0;
73 if (pReturnTypeRef)
74 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
76 void * pUnoReturn = 0;
77 void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
79 if (pReturnTypeDescr)
81 if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
83 pUnoReturn = pRegisterReturn; // direct way for simple types
85 else // complex return via ptr (pCppReturn)
87 pCppReturn = *(void **)gpreg;
88 gpreg++;
89 ng++;
91 pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
92 ? alloca( pReturnTypeDescr->nSize )
93 : pCppReturn); // direct way
96 // pop this
97 gpreg++;
98 ng++;
100 // stack space
101 OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
102 // parameters
103 void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
104 void ** pCppArgs = pUnoArgs + nParams;
105 // indizes of values this have to be converted (interface conversion cpp<=>uno)
106 sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams));
107 // type descriptions for reconversions
108 typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
110 sal_Int32 nTempIndizes = 0;
112 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
114 const typelib_MethodParameter & rParam = pParams[nPos];
115 typelib_TypeDescription * pParamTypeDescr = 0;
116 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
118 if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
119 // value
122 switch (pParamTypeDescr->eTypeClass)
125 case typelib_TypeClass_DOUBLE:
126 if (nf < 8) {
127 pCppArgs[nPos] = fpreg;
128 pUnoArgs[nPos] = fpreg;
129 nf++;
130 fpreg += 2;
131 } else {
132 if (((long)ovrflw) & 4) ovrflw++;
133 pCppArgs[nPos] = ovrflw;
134 pUnoArgs[nPos] = ovrflw;
135 ovrflw += 2;
137 break;
139 case typelib_TypeClass_FLOAT:
140 // fpreg are all double values so need to
141 // modify fpreg to be a single word float value
142 if (nf < 8) {
143 float tmp = (float) (*((double *)fpreg));
144 (*((float *) fpreg)) = tmp;
145 pCppArgs[nPos] = fpreg;
146 pUnoArgs[nPos] = fpreg;
147 nf++;
148 fpreg += 2;
149 } else {
150 #if 0 /* abi is not being followed correctly */
151 if (((long)ovrflw) & 4) ovrflw++;
152 float tmp = (float) (*((double *)ovrflw));
153 (*((float *) ovrflw)) = tmp;
154 pCppArgs[nPos] = ovrflw;
155 pUnoArgs[nPos] = ovrflw;
156 ovrflw += 2;
157 #else
158 pCppArgs[nPos] = ovrflw;
159 pUnoArgs[nPos] = ovrflw;
160 ovrflw += 1;
161 #endif
163 break;
165 case typelib_TypeClass_HYPER:
166 case typelib_TypeClass_UNSIGNED_HYPER:
167 if (ng < 7) {
168 if (ng & 1) {
169 ng++;
170 gpreg++;
172 pCppArgs[nPos] = gpreg;
173 pUnoArgs[nPos] = gpreg;
174 ng += 2;
175 gpreg += 2;
176 } else {
177 if (((long)ovrflw) & 4) ovrflw++;
178 pCppArgs[nPos] = ovrflw;
179 pUnoArgs[nPos] = ovrflw;
180 ovrflw += 2;
182 break;
184 case typelib_TypeClass_BYTE:
185 case typelib_TypeClass_BOOLEAN:
186 if (ng < 8) {
187 pCppArgs[nPos] = (((char *)gpreg) + 3);
188 pUnoArgs[nPos] = (((char *)gpreg) + 3);
189 ng++;
190 gpreg++;
191 } else {
192 pCppArgs[nPos] = (((char *)ovrflw) + 3);
193 pUnoArgs[nPos] = (((char *)ovrflw) + 3);
194 ovrflw++;
196 break;
199 case typelib_TypeClass_CHAR:
200 case typelib_TypeClass_SHORT:
201 case typelib_TypeClass_UNSIGNED_SHORT:
202 if (ng < 8) {
203 pCppArgs[nPos] = (((char *)gpreg)+ 2);
204 pUnoArgs[nPos] = (((char *)gpreg)+ 2);
205 ng++;
206 gpreg++;
207 } else {
208 pCppArgs[nPos] = (((char *)ovrflw) + 2);
209 pUnoArgs[nPos] = (((char *)ovrflw) + 2);
210 ovrflw++;
212 break;
215 default:
216 if (ng < 8) {
217 pCppArgs[nPos] = gpreg;
218 pUnoArgs[nPos] = gpreg;
219 ng++;
220 gpreg++;
221 } else {
222 pCppArgs[nPos] = ovrflw;
223 pUnoArgs[nPos] = ovrflw;
224 ovrflw++;
226 break;
229 // no longer needed
230 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
232 else // ptr to complex value | ref
235 if (ng < 8) {
236 pCppArgs[nPos] = *(void **)gpreg;
237 pCppStack = gpreg;
238 ng++;
239 gpreg++;
240 } else {
241 pCppArgs[nPos] = *(void **)ovrflw;
242 pCppStack = ovrflw;
243 ovrflw++;
246 if (! rParam.bIn) // is pure out
248 // uno out is unconstructed mem!
249 pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
250 pTempIndizes[nTempIndizes] = nPos;
251 // will be released at reconversion
252 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
254 // is in/inout
255 else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
257 uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
258 *(void **)pCppStack, pParamTypeDescr,
259 pThis->getBridge()->getCpp2Uno() );
260 pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
261 // will be released at reconversion
262 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
264 else // direct way
266 pUnoArgs[nPos] = *(void **)pCppStack;
267 // no longer needed
268 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
273 // ExceptionHolder
274 uno_Any aUnoExc; // Any will be constructed by callee
275 uno_Any * pUnoExc = &aUnoExc;
277 // invoke uno dispatch call
278 (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
280 // in case an exception occured...
281 if (pUnoExc)
283 // destruct temporary in/inout params
284 for ( ; nTempIndizes--; )
286 sal_Int32 nIndex = pTempIndizes[nTempIndizes];
288 if (pParams[nIndex].bIn) // is in/inout => was constructed
289 uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], 0 );
290 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
292 if (pReturnTypeDescr)
293 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
295 CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc, pThis->getBridge()->getUno2Cpp() );
296 // has to destruct the any
297 // is here for dummy
298 return typelib_TypeClass_VOID;
300 else // else no exception occured...
302 // temporary params
303 for ( ; nTempIndizes--; )
305 sal_Int32 nIndex = pTempIndizes[nTempIndizes];
306 typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
308 if (pParams[nIndex].bOut) // inout/out
310 // convert and assign
311 uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
312 uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
313 pThis->getBridge()->getUno2Cpp() );
315 // destroy temp uno param
316 uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
318 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
320 // return
321 if (pCppReturn) // has complex return
323 if (pUnoReturn != pCppReturn) // needs reconversion
325 uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
326 pThis->getBridge()->getUno2Cpp() );
327 // destroy temp uno return
328 uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
330 // complex return ptr is set to return reg
331 *(void **)pRegisterReturn = pCppReturn;
333 if (pReturnTypeDescr)
335 typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
336 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
337 return eRet;
339 else
340 return typelib_TypeClass_VOID;
345 //==================================================================================================
346 static typelib_TypeClass cpp_mediate(
347 sal_Int32 nFunctionIndex,
348 sal_Int32 nVtableOffset,
349 void ** gpreg, void ** fpreg, void ** ovrflw,
350 sal_Int64 * pRegisterReturn /* space for register return */ )
352 OSL_ENSURE( sizeof(sal_Int32)==sizeof(void *), "### unexpected!" );
354 // gpreg: [ret *], this, [other gpr params]
355 // fpreg: [fpr params]
356 // ovrflw: [gpr or fpr params (properly aligned)]
358 void * pThis;
359 if (nFunctionIndex & 0x80000000 )
361 nFunctionIndex &= 0x7fffffff;
362 pThis = gpreg[1];
364 else
366 pThis = gpreg[0];
369 pThis = static_cast< char * >(pThis) - nVtableOffset;
370 bridges::cpp_uno::shared::CppInterfaceProxy * pCppI
371 = bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
372 pThis);
374 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
376 OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
377 if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
379 throw RuntimeException(
380 rtl::OUString::createFromAscii("illegal vtable index!"),
381 (XInterface *)pThis );
384 // determine called method
385 sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
386 OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### illegal member index!" );
388 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
390 typelib_TypeClass eRet;
391 switch (aMemberDescr.get()->eTypeClass)
393 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
395 if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
397 // is GET method
398 eRet = cpp2uno_call(
399 pCppI, aMemberDescr.get(),
400 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
401 0, 0, // no params
402 gpreg, fpreg, ovrflw, pRegisterReturn );
404 else
406 // is SET method
407 typelib_MethodParameter aParam;
408 aParam.pTypeRef =
409 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
410 aParam.bIn = sal_True;
411 aParam.bOut = sal_False;
413 eRet = cpp2uno_call(
414 pCppI, aMemberDescr.get(),
415 0, // indicates void return
416 1, &aParam,
417 gpreg, fpreg, ovrflw, pRegisterReturn );
419 break;
421 case typelib_TypeClass_INTERFACE_METHOD:
423 // is METHOD
424 switch (nFunctionIndex)
426 case 1: // acquire()
427 pCppI->acquireProxy(); // non virtual call!
428 eRet = typelib_TypeClass_VOID;
429 break;
430 case 2: // release()
431 pCppI->releaseProxy(); // non virtual call!
432 eRet = typelib_TypeClass_VOID;
433 break;
434 case 0: // queryInterface() opt
436 typelib_TypeDescription * pTD = 0;
437 TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
438 if (pTD)
440 XInterface * pInterface = 0;
441 (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
442 pCppI->getBridge()->getCppEnv(),
443 (void **)&pInterface, pCppI->getOid().pData,
444 (typelib_InterfaceTypeDescription *)pTD );
446 if (pInterface)
448 ::uno_any_construct(
449 reinterpret_cast< uno_Any * >( gpreg[0] ),
450 &pInterface, pTD, cpp_acquire );
451 pInterface->release();
452 TYPELIB_DANGER_RELEASE( pTD );
453 *(void **)pRegisterReturn = gpreg[0];
454 eRet = typelib_TypeClass_ANY;
455 break;
457 TYPELIB_DANGER_RELEASE( pTD );
459 } // else perform queryInterface()
460 default:
461 eRet = cpp2uno_call(
462 pCppI, aMemberDescr.get(),
463 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
464 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
465 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
466 gpreg, fpreg, ovrflw, pRegisterReturn );
468 break;
470 default:
472 throw RuntimeException(
473 rtl::OUString::createFromAscii("no member description found!"),
474 (XInterface *)pThis );
475 // is here for dummy
476 eRet = typelib_TypeClass_VOID;
480 return eRet;
483 //==================================================================================================
485 * is called on incoming vtable calls
486 * (called by asm snippets)
488 static void cpp_vtable_call( int nFunctionIndex, int nVtableOffset, void** gpregptr, void** fpregptr, void** ovrflw)
490 sal_Int32 gpreg[8];
491 double fpreg[8];
493 memcpy( gpreg, gpregptr, 32);
494 memcpy( fpreg, fpregptr, 64);
496 volatile long nRegReturn[2];
498 // fprintf(stderr,"in cpp_vtable_call nFunctionIndex is %x\n",nFunctionIndex);
499 // fprintf(stderr,"in cpp_vtable_call nVtableOffset is %x\n",nVtableOffset);
500 // fflush(stderr);
502 sal_Bool bComplex = nFunctionIndex & 0x80000000 ? sal_True : sal_False;
504 typelib_TypeClass aType =
505 cpp_mediate( nFunctionIndex, nVtableOffset, (void**)gpreg, (void**)fpreg, ovrflw, (sal_Int64*)nRegReturn );
507 switch( aType )
510 // move return value into register space
511 // (will be loaded by machine code snippet)
513 case typelib_TypeClass_BOOLEAN:
514 case typelib_TypeClass_BYTE:
515 __asm__( "lbz 3,%0\n\t" : :
516 "m"(nRegReturn[0]) );
517 break;
519 case typelib_TypeClass_CHAR:
520 case typelib_TypeClass_SHORT:
521 case typelib_TypeClass_UNSIGNED_SHORT:
522 __asm__( "lhz 3,%0\n\t" : :
523 "m"(nRegReturn[0]) );
524 break;
526 case typelib_TypeClass_FLOAT:
527 __asm__( "lfs 1,%0\n\t" : :
528 "m" (*((float*)nRegReturn)) );
529 break;
531 case typelib_TypeClass_DOUBLE:
532 __asm__( "lfd 1,%0\n\t" : :
533 "m" (*((double*)nRegReturn)) );
534 break;
536 case typelib_TypeClass_HYPER:
537 case typelib_TypeClass_UNSIGNED_HYPER:
538 __asm__( "lwz 4,%0\n\t" : :
539 "m"(nRegReturn[1]) ); // fall through
541 default:
542 __asm__( "lwz 3,%0\n\t" : :
543 "m"(nRegReturn[0]) );
544 break;
549 int const codeSnippetSize = 108;
551 unsigned char * codeSnippet( unsigned char * code, sal_Int32 functionIndex, sal_Int32 vtableOffset,
552 bool simpleRetType)
555 // fprintf(stderr,"in codeSnippet functionIndex is %x\n", functionIndex);
556 // fprintf(stderr,"in codeSnippet vtableOffset is %x\n", vtableOffset);
557 // fflush(stderr);
559 if (! simpleRetType )
560 functionIndex |= 0x80000000;
562 unsigned long * p = (unsigned long *) code;
564 // OSL_ASSERT( sizeof (long) == 4 );
565 OSL_ASSERT((((unsigned long)code) & 0x3) == 0 ); //aligned to 4 otherwise a mistake
567 /* generate this code */
568 // # so first save gpr 3 to gpr 10 (aligned to 4)
569 // stw r3,-2048(r1)
570 // stw r4,-2044(r1)
571 // stw r5,-2040(r1)
572 // stw r6,-2036(r1)
573 // stw r7,-2032(r1)
574 // stw r8,-2028(r1)
575 // stw r9,-2024(r1)
576 // stw r10,-2020(r1)
579 // # next save fpr 1 to fpr 8 (aligned to 8)
580 // stfd f1,-2016(r1)
581 // stfd f2,-2008(r1)
582 // stfd f3,-2000(r1)
583 // stfd f4,-1992(r1)
584 // stfd f5,-1984(r1)
585 // stfd f6,-1976(r1)
586 // stfd f7,-1968(r1)
587 // stfd f8,-1960(r1)
589 // # now here is where cpp_vtable_call must go
590 // lis r3,-8531
591 // ori r3,r3,48879
592 // mtctr r3
594 // # now load up the functionIndex
595 // lis r3,-8531
596 // ori r3,r3,48879
598 // # now load up the vtableOffset
599 // lis r4,-8531
600 // ori r4,r4,48879
602 // #now load up the pointer to the saved gpr registers
603 // addi r5,r1,-2048
605 // #now load up the pointer to the saved fpr registers
606 // addi r6,r1,-2016
608 // #now load up the pointer to the overflow call stack
609 // addi r7,r1,8
610 // bctr
612 * p++ = 0x9061f800;
613 * p++ = 0x9081f804;
614 * p++ = 0x90a1f808;
615 * p++ = 0x90c1f80c;
616 * p++ = 0x90e1f810;
617 * p++ = 0x9101f814;
618 * p++ = 0x9121f818;
619 * p++ = 0x9141f81c;
620 * p++ = 0xd821f820;
621 * p++ = 0xd841f828;
622 * p++ = 0xd861f830;
623 * p++ = 0xd881f838;
624 * p++ = 0xd8a1f840;
625 * p++ = 0xd8c1f848;
626 * p++ = 0xd8e1f850;
627 * p++ = 0xd901f858;
628 * p++ = 0x3c600000 | (((unsigned long)cpp_vtable_call) >> 16);
629 * p++ = 0x60630000 | (((unsigned long)cpp_vtable_call) & 0x0000FFFF);
630 * p++ = 0x7c6903a6;
631 * p++ = 0x3c600000 | (((unsigned long)functionIndex) >> 16);
632 * p++ = 0x60630000 | (((unsigned long)functionIndex) & 0x0000FFFF);
633 * p++ = 0x3c800000 | (((unsigned long)vtableOffset) >> 16);
634 * p++ = 0x60840000 | (((unsigned long)vtableOffset) & 0x0000FFFF);
635 * p++ = 0x38a1f800;
636 * p++ = 0x38c1f820;
637 * p++ = 0x38e10008;
638 * p++ = 0x4e800420;
639 return (code + codeSnippetSize);
646 void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const * bptr, unsigned char const * eptr)
648 int const lineSize = 32;
649 for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
650 __asm__ volatile ("dcbst 0, %0" : : "r"(p) : "memory");
652 __asm__ volatile ("sync" : : : "memory");
653 for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
654 __asm__ volatile ("icbi 0, %0" : : "r"(p) : "memory");
656 __asm__ volatile ("isync" : : : "memory");
659 struct bridges::cpp_uno::shared::VtableFactory::Slot { void * fn; };
661 bridges::cpp_uno::shared::VtableFactory::Slot *
662 bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
664 return static_cast< Slot * >(block) + 2;
667 sal_Size bridges::cpp_uno::shared::VtableFactory::getBlockSize(
668 sal_Int32 slotCount)
670 return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
673 bridges::cpp_uno::shared::VtableFactory::Slot *
674 bridges::cpp_uno::shared::VtableFactory::initializeBlock(
675 void * block, sal_Int32 slotCount)
677 Slot * slots = mapBlockToVtable(block);
678 slots[-2].fn = 0;
679 slots[-1].fn = 0;
680 return slots + slotCount;
683 unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
684 Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
685 typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
686 sal_Int32 functionCount, sal_Int32 vtableOffset)
688 (*slots) -= functionCount;
689 Slot * s = *slots;
690 // fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
691 // fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
692 // fflush(stderr);
694 for (sal_Int32 i = 0; i < type->nMembers; ++i) {
695 typelib_TypeDescription * member = 0;
696 TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
697 OSL_ASSERT(member != 0);
698 switch (member->eTypeClass) {
699 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
700 // Getter:
701 (s++)->fn = code + writetoexecdiff;
702 code = codeSnippet(
703 code, functionOffset++, vtableOffset,
704 bridges::cpp_uno::shared::isSimpleType(
705 reinterpret_cast<
706 typelib_InterfaceAttributeTypeDescription * >(
707 member)->pAttributeTypeRef));
709 // Setter:
710 if (!reinterpret_cast<
711 typelib_InterfaceAttributeTypeDescription * >(
712 member)->bReadOnly)
714 (s++)->fn = code + writetoexecdiff;
715 code = codeSnippet(code, functionOffset++, vtableOffset, true);
717 break;
719 case typelib_TypeClass_INTERFACE_METHOD:
720 (s++)->fn = code + writetoexecdiff;
721 code = codeSnippet(
722 code, functionOffset++, vtableOffset,
723 bridges::cpp_uno::shared::isSimpleType(
724 reinterpret_cast<
725 typelib_InterfaceMethodTypeDescription * >(
726 member)->pReturnTypeRef));
727 break;
729 default:
730 OSL_ASSERT(false);
731 break;
733 TYPELIB_DANGER_RELEASE(member);
735 return code;