Update ooo320-m1
[ooovba.git] / bridges / source / cpp_uno / gcc3_linux_powerpc64 / cpp2uno.cxx
blob7a878e5816b170c44a6deac43533c106fdd6cb77
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.5 $
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 <com/sun/star/uno/genfunc.hxx>
35 #include <uno/data.h>
36 #include <typelib/typedescription.hxx>
38 #include "bridges/cpp_uno/shared/bridge.hxx"
39 #include "bridges/cpp_uno/shared/cppinterfaceproxy.hxx"
40 #include "bridges/cpp_uno/shared/types.hxx"
41 #include "bridges/cpp_uno/shared/vtablefactory.hxx"
43 #include "share.hxx"
44 #include <stdio.h>
45 #include <string.h>
48 using namespace ::com::sun::star::uno;
50 namespace
53 //==================================================================================================
54 static typelib_TypeClass cpp2uno_call(
55 bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
56 const typelib_TypeDescription * pMemberTypeDescr,
57 typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
58 sal_Int32 nParams, typelib_MethodParameter * pParams,
59 void ** gpreg, void ** fpreg, void ** ovrflw,
60 sal_Int64 * pRegisterReturn /* space for register return */ )
62 #ifdef CMC_DEBUG
63 fprintf(stderr, "as far as cpp2uno_call\n");
64 #endif
66 int ng = 0; //number of gpr registers used
67 int nf = 0; //number of fpr regsiters used
69 // gpreg: [ret *], this, [gpr params]
70 // fpreg: [fpr params]
71 // ovrflw: [gpr or fpr params (properly aligned)]
73 // return
74 typelib_TypeDescription * pReturnTypeDescr = 0;
75 if (pReturnTypeRef)
76 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
78 void * pUnoReturn = 0;
79 void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
81 if (pReturnTypeDescr)
83 if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
85 pUnoReturn = pRegisterReturn; // direct way for simple types
87 else // complex return via ptr (pCppReturn)
89 pCppReturn = *(void **)gpreg;
90 gpreg++;
91 ng++;
93 pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
94 ? alloca( pReturnTypeDescr->nSize )
95 : pCppReturn); // direct way
98 // pop this
99 gpreg++;
100 ng++;
102 // stack space
103 OSL_ENSURE( sizeof(void *) == sizeof(sal_Int64), "### unexpected size!" );
104 // parameters
105 void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
106 void ** pCppArgs = pUnoArgs + nParams;
107 // indizes of values this have to be converted (interface conversion cpp<=>uno)
108 sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams));
109 // type descriptions for reconversions
110 typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
112 sal_Int32 nTempIndizes = 0;
113 bool bOverFlowUsed = false;
114 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
116 const typelib_MethodParameter & rParam = pParams[nPos];
117 typelib_TypeDescription * pParamTypeDescr = 0;
118 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
120 #ifdef CMC_DEBUG
121 fprintf(stderr, "arg %d of %d\n", nPos, nParams);
122 #endif
124 if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
126 #ifdef CMC_DEBUG
127 fprintf(stderr, "simple\n");
128 #endif
130 switch (pParamTypeDescr->eTypeClass)
132 case typelib_TypeClass_FLOAT:
133 case typelib_TypeClass_DOUBLE:
134 if (nf < ppc64::MAX_SSE_REGS)
136 if (pParamTypeDescr->eTypeClass == typelib_TypeClass_FLOAT)
138 float tmp = (float) (*((double *)fpreg));
139 (*((float *) fpreg)) = tmp;
141 pCppArgs[nPos] = pUnoArgs[nPos] = fpreg++;
142 nf++;
144 else
146 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
147 bOverFlowUsed = true;
149 if (bOverFlowUsed) ovrflw++;
150 break;
151 case typelib_TypeClass_BYTE:
152 case typelib_TypeClass_BOOLEAN:
153 if (ng < ppc64::MAX_GPR_REGS)
155 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + (sizeof(void*)-1));
156 ng++;
157 gpreg++;
159 else
161 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + (sizeof(void*)-1));
162 bOverFlowUsed = true;
164 if (bOverFlowUsed) ovrflw++;
165 break;
166 case typelib_TypeClass_CHAR:
167 case typelib_TypeClass_SHORT:
168 case typelib_TypeClass_UNSIGNED_SHORT:
169 if (ng < ppc64::MAX_GPR_REGS)
171 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + (sizeof(void*)-2));
172 ng++;
173 gpreg++;
175 else
177 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + (sizeof(void*)-2));
178 bOverFlowUsed = true;
180 if (bOverFlowUsed) ovrflw++;
181 break;
182 case typelib_TypeClass_ENUM:
183 case typelib_TypeClass_LONG:
184 case typelib_TypeClass_UNSIGNED_LONG:
185 if (ng < ppc64::MAX_GPR_REGS)
187 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + (sizeof(void*)-4));
188 ng++;
189 gpreg++;
191 else
193 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + (sizeof(void*)-4));
194 bOverFlowUsed = true;
196 if (bOverFlowUsed) ovrflw++;
197 break;
198 default:
199 if (ng < ppc64::MAX_GPR_REGS)
201 pCppArgs[nPos] = pUnoArgs[nPos] = gpreg++;
202 ng++;
204 else
206 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
207 bOverFlowUsed = true;
209 if (bOverFlowUsed) ovrflw++;
210 break;
213 // no longer needed
214 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
216 else // ptr to complex value | ref
218 #ifdef CMC_DEBUG
219 fprintf(stderr, "complex, ng is %d\n", ng);
220 #endif
221 void *pCppStack; //temporary stack pointer
223 if (ng < ppc64::MAX_GPR_REGS)
225 pCppArgs[nPos] = pCppStack = *gpreg++;
226 ng++;
228 else
230 pCppArgs[nPos] = pCppStack = *ovrflw;
231 bOverFlowUsed = true;
233 if (bOverFlowUsed) ovrflw++;
235 if (! rParam.bIn) // is pure out
237 // uno out is unconstructed mem!
238 pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
239 pTempIndizes[nTempIndizes] = nPos;
240 // will be released at reconversion
241 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
243 // is in/inout
244 else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
246 uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
247 pCppStack, pParamTypeDescr,
248 pThis->getBridge()->getCpp2Uno() );
249 pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
250 // will be released at reconversion
251 ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
253 else // direct way
255 pUnoArgs[nPos] = pCppStack;
256 // no longer needed
257 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
262 #ifdef CMC_DEBUG
263 fprintf(stderr, "end of params\n");
264 #endif
266 // ExceptionHolder
267 uno_Any aUnoExc; // Any will be constructed by callee
268 uno_Any * pUnoExc = &aUnoExc;
270 // invoke uno dispatch call
271 (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
273 // in case an exception occured...
274 if (pUnoExc)
276 // destruct temporary in/inout params
277 for ( ; nTempIndizes--; )
279 sal_Int32 nIndex = pTempIndizes[nTempIndizes];
281 if (pParams[nIndex].bIn) // is in/inout => was constructed
282 uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], 0 );
283 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
285 if (pReturnTypeDescr)
286 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
288 CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc, pThis->getBridge()->getUno2Cpp() );
289 // has to destruct the any
290 // is here for dummy
291 return typelib_TypeClass_VOID;
293 else // else no exception occured...
295 // temporary params
296 for ( ; nTempIndizes--; )
298 sal_Int32 nIndex = pTempIndizes[nTempIndizes];
299 typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
301 if (pParams[nIndex].bOut) // inout/out
303 // convert and assign
304 uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
305 uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
306 pThis->getBridge()->getUno2Cpp() );
308 // destroy temp uno param
309 uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
311 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
313 // return
314 if (pCppReturn) // has complex return
316 if (pUnoReturn != pCppReturn) // needs reconversion
318 uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
319 pThis->getBridge()->getUno2Cpp() );
320 // destroy temp uno return
321 uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
323 // complex return ptr is set to return reg
324 *(void **)pRegisterReturn = pCppReturn;
326 if (pReturnTypeDescr)
328 typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
329 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
330 return eRet;
332 else
333 return typelib_TypeClass_VOID;
338 //==================================================================================================
339 static typelib_TypeClass cpp_mediate(
340 sal_uInt64 nOffsetAndIndex,
341 void ** gpreg, void ** fpreg, long sp,
342 sal_Int64 * pRegisterReturn /* space for register return */ )
344 OSL_ENSURE( sizeof(sal_Int64)==sizeof(void *), "### unexpected!" );
346 sal_Int32 nVtableOffset = (nOffsetAndIndex >> 32);
347 sal_Int32 nFunctionIndex = (nOffsetAndIndex & 0xFFFFFFFF);
349 long sf = *(long*)sp;
350 void ** ovrflw = (void**)(sf + 112);
352 // gpreg: [ret *], this, [other gpr params]
353 // fpreg: [fpr params]
354 // ovrflw: [gpr or fpr params (properly aligned)]
356 void * pThis;
357 if (nFunctionIndex & 0x80000000 )
359 nFunctionIndex &= 0x7fffffff;
360 pThis = gpreg[1];
361 #ifdef CMC_DEBUG
362 fprintf(stderr, "pThis is gpreg[1]\n");
363 #endif
365 else
367 pThis = gpreg[0];
368 #ifdef CMC_DEBUG
369 fprintf(stderr, "pThis is gpreg[0]\n");
370 #endif
373 #ifdef CMC_DEBUG
374 fprintf(stderr, "pThis is %lx\n", pThis);
375 #endif
377 pThis = static_cast< char * >(pThis) - nVtableOffset;
379 #ifdef CMC_DEBUG
380 fprintf(stderr, "pThis is now %lx\n", pThis);
381 #endif
383 bridges::cpp_uno::shared::CppInterfaceProxy * pCppI
384 = bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
385 pThis);
387 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
389 #ifdef CMC_DEBUG
390 fprintf(stderr, "indexes are %d %d\n", nFunctionIndex, pTypeDescr->nMapFunctionIndexToMemberIndex);
391 #endif
393 OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
394 if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
396 throw RuntimeException(
397 rtl::OUString::createFromAscii("illegal vtable index!"),
398 (XInterface *)pThis );
401 // determine called method
402 sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
403 OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### illegal member index!" );
405 #ifdef CMC_DEBUG
406 fprintf(stderr, "members are %d %d\n", nMemberPos, pTypeDescr->nAllMembers);
407 #endif
409 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
411 typelib_TypeClass eRet;
412 switch (aMemberDescr.get()->eTypeClass)
414 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
416 if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
418 // is GET method
419 eRet = cpp2uno_call(
420 pCppI, aMemberDescr.get(),
421 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
422 0, 0, // no params
423 gpreg, fpreg, ovrflw, pRegisterReturn );
425 else
427 // is SET method
428 typelib_MethodParameter aParam;
429 aParam.pTypeRef =
430 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
431 aParam.bIn = sal_True;
432 aParam.bOut = sal_False;
434 eRet = cpp2uno_call(
435 pCppI, aMemberDescr.get(),
436 0, // indicates void return
437 1, &aParam,
438 gpreg, fpreg, ovrflw, pRegisterReturn );
440 break;
442 case typelib_TypeClass_INTERFACE_METHOD:
444 // is METHOD
445 switch (nFunctionIndex)
447 case 1: // acquire()
448 pCppI->acquireProxy(); // non virtual call!
449 eRet = typelib_TypeClass_VOID;
450 break;
451 case 2: // release()
452 pCppI->releaseProxy(); // non virtual call!
453 eRet = typelib_TypeClass_VOID;
454 break;
455 case 0: // queryInterface() opt
457 typelib_TypeDescription * pTD = 0;
458 TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
459 if (pTD)
461 XInterface * pInterface = 0;
462 (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
463 pCppI->getBridge()->getCppEnv(),
464 (void **)&pInterface, pCppI->getOid().pData,
465 (typelib_InterfaceTypeDescription *)pTD );
467 if (pInterface)
469 ::uno_any_construct(
470 reinterpret_cast< uno_Any * >( gpreg[0] ),
471 &pInterface, pTD, cpp_acquire );
472 pInterface->release();
473 TYPELIB_DANGER_RELEASE( pTD );
474 *(void **)pRegisterReturn = gpreg[0];
475 eRet = typelib_TypeClass_ANY;
476 break;
478 TYPELIB_DANGER_RELEASE( pTD );
480 } // else perform queryInterface()
481 default:
482 eRet = cpp2uno_call(
483 pCppI, aMemberDescr.get(),
484 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
485 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
486 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
487 gpreg, fpreg, ovrflw, pRegisterReturn );
489 break;
491 default:
493 #ifdef CMC_DEBUG
494 fprintf(stderr, "screwed\n");
495 #endif
497 throw RuntimeException(
498 rtl::OUString::createFromAscii("no member description found!"),
499 (XInterface *)pThis );
500 // is here for dummy
501 eRet = typelib_TypeClass_VOID;
505 #ifdef CMC_DEBUG
506 fprintf(stderr, "end of cpp_mediate\n");
507 #endif
508 return eRet;
511 extern "C" void privateSnippetExecutor( ... )
513 volatile long nOffsetAndIndex;
515 //mr %r3, %r11 # move into arg1 the 64bit value passed from OOo
516 __asm__ __volatile__ (
517 "mr %0, 11\n\t"
518 : "=r" (nOffsetAndIndex) : );
520 sal_uInt64 gpreg[ppc64::MAX_GPR_REGS];
521 double fpreg[ppc64::MAX_SSE_REGS];
523 __asm__ __volatile__ (
524 "std 3, 0(%0)\t\n"
525 "std 4, 8(%0)\t\n"
526 "std 5, 16(%0)\t\n"
527 "std 6, 24(%0)\t\n"
528 "std 7, 32(%0)\t\n"
529 "std 8, 40(%0)\t\n"
530 "std 9, 48(%0)\t\n"
531 "std 10, 56(%0)\t\n"
532 "stfd 1, 0(%1)\t\n"
533 "stfd 2, 8(%1)\t\n"
534 "stfd 3, 16(%1)\t\n"
535 "stfd 4, 24(%1)\t\n"
536 "stfd 5, 32(%1)\t\n"
537 "stfd 6, 40(%1)\t\n"
538 "stfd 7, 48(%1)\t\n"
539 "stfd 8, 56(%1)\t\n"
540 "stfd 9, 64(%1)\t\n"
541 "stfd 10, 72(%1)\t\n"
542 "stfd 11, 80(%1)\t\n"
543 "stfd 12, 88(%1)\t\n"
544 "stfd 13, 96(%1)\t\n"
545 : : "r" (gpreg), "r" (fpreg)
546 : "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10",
547 "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", "fr8", "fr9",
548 "fr10", "fr11", "fr12", "fr13"
551 volatile long sp;
553 //stack pointer
554 __asm__ __volatile__ (
555 "mr %0, 1\n\t"
556 : "=r" (sp) : );
558 volatile long nRegReturn[0];
560 typelib_TypeClass aType =
561 cpp_mediate( nOffsetAndIndex, (void**)gpreg, (void**)fpreg, sp, (sal_Int64*)nRegReturn);
563 switch( aType )
565 case typelib_TypeClass_VOID:
566 break;
567 case typelib_TypeClass_BOOLEAN:
568 case typelib_TypeClass_BYTE:
569 __asm__( "lbz 3,%0\n\t"
570 : : "m" (nRegReturn[0]) );
571 break;
572 case typelib_TypeClass_CHAR:
573 case typelib_TypeClass_UNSIGNED_SHORT:
574 __asm__( "lhz 3,%0\n\t"
575 : : "m" (nRegReturn[0]) );
576 break;
577 case typelib_TypeClass_SHORT:
578 __asm__( "lha 3,%0\n\t"
579 : : "m" (nRegReturn[0]) );
580 break;
581 case typelib_TypeClass_ENUM:
582 case typelib_TypeClass_UNSIGNED_LONG:
583 __asm__( "lwz 3,%0\n\t"
584 : : "m"(nRegReturn[0]) );
585 break;
586 case typelib_TypeClass_LONG:
587 __asm__( "lwa 3,%0\n\t"
588 : : "m"(nRegReturn[0]) );
589 break;
590 case typelib_TypeClass_FLOAT:
591 __asm__( "lfs 1,%0\n\t"
592 : : "m" (*((float*)nRegReturn)) );
593 break;
594 case typelib_TypeClass_DOUBLE:
595 __asm__( "lfd 1,%0\n\t"
596 : : "m" (*((double*)nRegReturn)) );
597 break;
598 default:
599 __asm__( "ld 3,%0\n\t"
600 : : "m" (nRegReturn[0]) );
601 break;
605 const int codeSnippetSize = 24;
607 unsigned char * codeSnippet( unsigned char * code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
608 bool simpleRetType)
610 #ifdef CMC_DEBUG
611 fprintf(stderr,"in codeSnippet functionIndex is %x\n", nFunctionIndex);
612 fprintf(stderr,"in codeSnippet vtableOffset is %x\n", nVtableOffset);
613 #endif
615 sal_uInt64 nOffsetAndIndex = ( ( (sal_uInt64) nVtableOffset ) << 32 ) | ( (sal_uInt64) nFunctionIndex );
617 if ( !simpleRetType )
618 nOffsetAndIndex |= 0x80000000;
620 void ** raw = (void **)&code[0];
621 memcpy(raw, (char*) privateSnippetExecutor, 16);
622 raw[2] = (void*) nOffsetAndIndex;
623 #ifdef CMC_DEBUG
624 fprintf(stderr, "in: offset/index is %x %x %d, %lx\n",
625 nFunctionIndex, nVtableOffset, !simpleRetType, raw[2]);
626 #endif
627 return (code + codeSnippetSize);
632 void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const * bptr, unsigned char const * eptr)
634 int const lineSize = 32;
635 for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
636 __asm__ volatile ("dcbst 0, %0" : : "r"(p) : "memory");
638 __asm__ volatile ("sync" : : : "memory");
639 for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
640 __asm__ volatile ("icbi 0, %0" : : "r"(p) : "memory");
642 __asm__ volatile ("isync" : : : "memory");
645 struct bridges::cpp_uno::shared::VtableFactory::Slot { void * fn; };
647 bridges::cpp_uno::shared::VtableFactory::Slot *
648 bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
650 return static_cast< Slot * >(block) + 2;
653 sal_Size bridges::cpp_uno::shared::VtableFactory::getBlockSize(
654 sal_Int32 slotCount)
656 return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
659 bridges::cpp_uno::shared::VtableFactory::Slot *
660 bridges::cpp_uno::shared::VtableFactory::initializeBlock(
661 void * block, sal_Int32 slotCount)
663 Slot * slots = mapBlockToVtable(block);
664 slots[-2].fn = 0;
665 slots[-1].fn = 0;
666 return slots + slotCount;
669 unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
670 Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
671 typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
672 sal_Int32 functionCount, sal_Int32 vtableOffset)
674 (*slots) -= functionCount;
675 Slot * s = *slots;
676 #ifdef CMC_DEBUG
677 fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
678 fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
679 #endif
681 for (sal_Int32 i = 0; i < type->nMembers; ++i) {
682 typelib_TypeDescription * member = 0;
683 TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
684 OSL_ASSERT(member != 0);
685 switch (member->eTypeClass) {
686 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
687 // Getter:
688 (s++)->fn = code + writetoexecdiff;
689 code = codeSnippet(
690 code, functionOffset++, vtableOffset,
691 bridges::cpp_uno::shared::isSimpleType(
692 reinterpret_cast<
693 typelib_InterfaceAttributeTypeDescription * >(
694 member)->pAttributeTypeRef));
696 // Setter:
697 if (!reinterpret_cast<
698 typelib_InterfaceAttributeTypeDescription * >(
699 member)->bReadOnly)
701 (s++)->fn = code + writetoexecdiff;
702 code = codeSnippet(code, functionOffset++, vtableOffset, true);
704 break;
706 case typelib_TypeClass_INTERFACE_METHOD:
707 (s++)->fn = code + writetoexecdiff;
708 code = codeSnippet(
709 code, functionOffset++, vtableOffset,
710 bridges::cpp_uno::shared::isSimpleType(
711 reinterpret_cast<
712 typelib_InterfaceMethodTypeDescription * >(
713 member)->pReturnTypeRef));
714 break;
716 default:
717 OSL_ASSERT(false);
718 break;
720 TYPELIB_DANGER_RELEASE(member);
722 return code;
725 /* vi:set tabstop=4 shiftwidth=4 expandtab: */