1*61dff127SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*61dff127SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*61dff127SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*61dff127SAndrew Rist  * distributed with this work for additional information
6*61dff127SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*61dff127SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*61dff127SAndrew Rist  * "License"); you may not use this file except in compliance
9*61dff127SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*61dff127SAndrew Rist  *
11*61dff127SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*61dff127SAndrew Rist  *
13*61dff127SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*61dff127SAndrew Rist  * software distributed under the License is distributed on an
15*61dff127SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*61dff127SAndrew Rist  * KIND, either express or implied.  See the License for the
17*61dff127SAndrew Rist  * specific language governing permissions and limitations
18*61dff127SAndrew Rist  * under the License.
19*61dff127SAndrew Rist  *
20*61dff127SAndrew Rist  *************************************************************/
21*61dff127SAndrew Rist 
22*61dff127SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_bridges.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
28cdf0e10cSrcweir #include <uno/data.h>
29cdf0e10cSrcweir #include <typelib/typedescription.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
32cdf0e10cSrcweir #include "bridges/cpp_uno/shared/cppinterfaceproxy.hxx"
33cdf0e10cSrcweir #include "bridges/cpp_uno/shared/types.hxx"
34cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtablefactory.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "share.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //==================================================================================================
cpp2uno_call(bridges::cpp_uno::shared::CppInterfaceProxy * pThis,const typelib_TypeDescription * pMemberTypeDescr,typelib_TypeDescriptionReference * pReturnTypeRef,sal_Int32 nParams,typelib_MethodParameter * pParams,void ** gpreg,void ** fpreg,void ** ovrflw,sal_Int64 * pRegisterReturn)44cdf0e10cSrcweir static typelib_TypeClass cpp2uno_call(
45cdf0e10cSrcweir 	bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
46cdf0e10cSrcweir 	const typelib_TypeDescription * pMemberTypeDescr,
47cdf0e10cSrcweir 	typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
48cdf0e10cSrcweir 	sal_Int32 nParams, typelib_MethodParameter * pParams,
49cdf0e10cSrcweir         void ** gpreg, void ** fpreg, void ** ovrflw,
50cdf0e10cSrcweir 	sal_Int64 * pRegisterReturn /* space for register return */ )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         // gpreg:  [ret *], this, [gpr params]
54cdf0e10cSrcweir         // fpreg:  [fpr params]
55cdf0e10cSrcweir         // ovrflw: [gpr or fpr params (space for entire parameter list in structure format properly aligned)]
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	// return
58cdf0e10cSrcweir 	typelib_TypeDescription * pReturnTypeDescr = 0;
59cdf0e10cSrcweir 	if (pReturnTypeRef)
60cdf0e10cSrcweir 		TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	void * pUnoReturn = 0;
63cdf0e10cSrcweir 	void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	sal_Int32 ngpreg = 0;
66cdf0e10cSrcweir 	sal_Int32 nfpreg = 0;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	if (pReturnTypeDescr)
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
72cdf0e10cSrcweir 			pUnoReturn = pRegisterReturn; // direct way for simple types
73cdf0e10cSrcweir 		else // complex return via ptr (pCppReturn)
74cdf0e10cSrcweir 		{
75cdf0e10cSrcweir 			pCppReturn = *gpreg;
76cdf0e10cSrcweir 			ngpreg++;
77cdf0e10cSrcweir 			++ovrflw;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 			pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
80cdf0e10cSrcweir 						  ? alloca( pReturnTypeDescr->nSize )
81cdf0e10cSrcweir 						  : pCppReturn); // direct way
82cdf0e10cSrcweir 		}
83cdf0e10cSrcweir 	}
84cdf0e10cSrcweir 	// pop this
85cdf0e10cSrcweir 	ngpreg++;
86cdf0e10cSrcweir 	++ovrflw;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         // after handling optional return pointer and "this"
89cdf0e10cSrcweir         // make use of the space that is allocated to store all parameters in the callers stack
90cdf0e10cSrcweir         // by comying the proper registers filled with parameters to that space
91cdf0e10cSrcweir 	char * pCppStack = (char *)ovrflw;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	sal_Int32 nPos;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	for ( nPos = 0; nPos < nParams; ++nPos )
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		const typelib_MethodParameter & rParam = pParams[nPos];
99cdf0e10cSrcweir 		if (rParam.bOut)
100cdf0e10cSrcweir 		{
101cdf0e10cSrcweir 			if (ngpreg < 8)
102cdf0e10cSrcweir 			{
103cdf0e10cSrcweir 				*(sal_Int32 *)pCppStack = ((sal_Int32 *)gpreg)[ngpreg++];
104cdf0e10cSrcweir 			}
105cdf0e10cSrcweir 			pCppStack += sizeof (sal_Int32);
106cdf0e10cSrcweir 		}
107cdf0e10cSrcweir 		else
108cdf0e10cSrcweir 		{
109cdf0e10cSrcweir 		switch (rParam.pTypeRef->eTypeClass)
110cdf0e10cSrcweir 		{
111cdf0e10cSrcweir 		case typelib_TypeClass_FLOAT:
112cdf0e10cSrcweir 			if (nfpreg < 13)
113cdf0e10cSrcweir 			{
114cdf0e10cSrcweir 				*(float *)pCppStack = ((double *)fpreg)[nfpreg++];
115cdf0e10cSrcweir 			}
116cdf0e10cSrcweir 			pCppStack += sizeof (float);
117cdf0e10cSrcweir 			ngpreg += 1;
118cdf0e10cSrcweir 			break;
119cdf0e10cSrcweir 		case typelib_TypeClass_DOUBLE:
120cdf0e10cSrcweir 			if (nfpreg < 13)
121cdf0e10cSrcweir 			{
122cdf0e10cSrcweir 				*(double *)pCppStack = ((double *)fpreg)[nfpreg++];
123cdf0e10cSrcweir 			}
124cdf0e10cSrcweir 			pCppStack += sizeof (double);
125cdf0e10cSrcweir 			ngpreg += 2;
126cdf0e10cSrcweir 			break;
127cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_HYPER:
128cdf0e10cSrcweir 		case typelib_TypeClass_HYPER:
129cdf0e10cSrcweir 			if (ngpreg < 8)
130cdf0e10cSrcweir 			{
131cdf0e10cSrcweir 				*(sal_Int32 *)pCppStack = ((sal_Int32 *)gpreg)[ngpreg++];
132cdf0e10cSrcweir 			}
133cdf0e10cSrcweir 			pCppStack += sizeof (sal_Int32);
134cdf0e10cSrcweir                         // fall through on purpose
135cdf0e10cSrcweir 		default:
136cdf0e10cSrcweir 			if (ngpreg < 8)
137cdf0e10cSrcweir 			{
138cdf0e10cSrcweir 				*(sal_Int32 *)pCppStack = ((sal_Int32 *)gpreg)[ngpreg++];
139cdf0e10cSrcweir 			}
140cdf0e10cSrcweir 			pCppStack += sizeof (sal_Int32);
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 		}
143cdf0e10cSrcweir 	}
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         // now the stack has all of the paramters stored in it ready to be processed
146cdf0e10cSrcweir         // so we are ready to build the uno call stack
147cdf0e10cSrcweir 	pCppStack = (char *)ovrflw;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	// stack space
150cdf0e10cSrcweir 	OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	// parameters
153cdf0e10cSrcweir 	void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
154cdf0e10cSrcweir 	void ** pCppArgs = pUnoArgs + nParams;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	// indizes of values this have to be converted (interface conversion cpp<=>uno)
157cdf0e10cSrcweir 	sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams));
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	// type descriptions for reconversions
160cdf0e10cSrcweir 	typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	sal_Int32 nTempIndizes   = 0;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	for ( nPos = 0; nPos < nParams; ++nPos )
165cdf0e10cSrcweir 	{
166cdf0e10cSrcweir 		const typelib_MethodParameter & rParam = pParams[nPos];
167cdf0e10cSrcweir 		typelib_TypeDescription * pParamTypeDescr = 0;
168cdf0e10cSrcweir 		TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 		if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
171cdf0e10cSrcweir                 // value
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			switch (pParamTypeDescr->eTypeClass)
174cdf0e10cSrcweir 			{
175cdf0e10cSrcweir 			case typelib_TypeClass_BOOLEAN:
176cdf0e10cSrcweir 			case typelib_TypeClass_BYTE:
177cdf0e10cSrcweir 				pCppArgs[nPos] = pCppStack +3;
178cdf0e10cSrcweir 				pUnoArgs[nPos] = pCppStack +3;
179cdf0e10cSrcweir 				break;
180cdf0e10cSrcweir 			case typelib_TypeClass_CHAR:
181cdf0e10cSrcweir 			case typelib_TypeClass_SHORT:
182cdf0e10cSrcweir 			case typelib_TypeClass_UNSIGNED_SHORT:
183cdf0e10cSrcweir 				pCppArgs[nPos] = pCppStack +2;
184cdf0e10cSrcweir 				pUnoArgs[nPos] = pCppStack +2;
185cdf0e10cSrcweir 				break;
186cdf0e10cSrcweir 			case typelib_TypeClass_HYPER:
187cdf0e10cSrcweir 			case typelib_TypeClass_UNSIGNED_HYPER:
188cdf0e10cSrcweir 			case typelib_TypeClass_DOUBLE:
189cdf0e10cSrcweir 				pCppArgs[nPos] = pCppStack;
190cdf0e10cSrcweir 				pUnoArgs[nPos] = pCppStack;
191cdf0e10cSrcweir 				pCppStack += sizeof(sal_Int32); // extra long (two regs)
192cdf0e10cSrcweir 				break;
193cdf0e10cSrcweir 			default:
194cdf0e10cSrcweir 				pCppArgs[nPos] = pCppStack;
195cdf0e10cSrcweir 				pUnoArgs[nPos] = pCppStack;
196cdf0e10cSrcweir 			}
197cdf0e10cSrcweir 			// no longer needed
198cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( pParamTypeDescr );
199cdf0e10cSrcweir 		}
200cdf0e10cSrcweir 		else // ptr to complex value | ref
201cdf0e10cSrcweir 		{
202cdf0e10cSrcweir 			pCppArgs[nPos] = *(void **)pCppStack;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 			if (! rParam.bIn) // is pure out
205cdf0e10cSrcweir 			{
206cdf0e10cSrcweir 				// uno out is unconstructed mem!
207cdf0e10cSrcweir 				pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
208cdf0e10cSrcweir 				pTempIndizes[nTempIndizes] = nPos;
209cdf0e10cSrcweir 				// will be released at reconversion
210cdf0e10cSrcweir 				ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
211cdf0e10cSrcweir 			}
212cdf0e10cSrcweir 			// is in/inout
213cdf0e10cSrcweir 			else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
214cdf0e10cSrcweir 			{
215cdf0e10cSrcweir 				uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
216cdf0e10cSrcweir 										*(void **)pCppStack, pParamTypeDescr,
217cdf0e10cSrcweir 										pThis->getBridge()->getCpp2Uno() );
218cdf0e10cSrcweir 				pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
219cdf0e10cSrcweir 				// will be released at reconversion
220cdf0e10cSrcweir 				ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
221cdf0e10cSrcweir 			}
222cdf0e10cSrcweir 			else // direct way
223cdf0e10cSrcweir 			{
224cdf0e10cSrcweir 				pUnoArgs[nPos] = *(void **)pCppStack;
225cdf0e10cSrcweir 				// no longer needed
226cdf0e10cSrcweir 				TYPELIB_DANGER_RELEASE( pParamTypeDescr );
227cdf0e10cSrcweir 			}
228cdf0e10cSrcweir 		}
229cdf0e10cSrcweir 		pCppStack += sizeof(sal_Int32); // standard parameter length
230cdf0e10cSrcweir 	}
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	// ExceptionHolder
234cdf0e10cSrcweir 	uno_Any aUnoExc; // Any will be constructed by callee
235cdf0e10cSrcweir 	uno_Any * pUnoExc = &aUnoExc;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	// invoke uno dispatch call
238cdf0e10cSrcweir 	(*pThis->getUnoI()->pDispatcher)(
239cdf0e10cSrcweir          pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 	// in case an exception occured...
242cdf0e10cSrcweir 	if (pUnoExc)
243cdf0e10cSrcweir 	{
244cdf0e10cSrcweir 		// destruct temporary in/inout params
245cdf0e10cSrcweir 		for ( ; nTempIndizes--; )
246cdf0e10cSrcweir 		{
247cdf0e10cSrcweir 			sal_Int32 nIndex = pTempIndizes[nTempIndizes];
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 			if (pParams[nIndex].bIn) // is in/inout => was constructed
250cdf0e10cSrcweir 				uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], 0 );
251cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
252cdf0e10cSrcweir 		}
253cdf0e10cSrcweir 		if (pReturnTypeDescr)
254cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 		CPPU_CURRENT_NAMESPACE::raiseException(
257cdf0e10cSrcweir                     &aUnoExc, pThis->getBridge()->getUno2Cpp() );
258cdf0e10cSrcweir                 // has to destruct the any
259cdf0e10cSrcweir 		// is here for dummy
260cdf0e10cSrcweir 		return typelib_TypeClass_VOID;
261cdf0e10cSrcweir 	}
262cdf0e10cSrcweir 	else // else no exception occured...
263cdf0e10cSrcweir 	{
264cdf0e10cSrcweir 		// temporary params
265cdf0e10cSrcweir 		for ( ; nTempIndizes--; )
266cdf0e10cSrcweir 		{
267cdf0e10cSrcweir 			sal_Int32 nIndex = pTempIndizes[nTempIndizes];
268cdf0e10cSrcweir 			typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 			if (pParams[nIndex].bOut) // inout/out
271cdf0e10cSrcweir 			{
272cdf0e10cSrcweir 				// convert and assign
273cdf0e10cSrcweir 				uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
274cdf0e10cSrcweir 				uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
275cdf0e10cSrcweir 										pThis->getBridge()->getUno2Cpp() );
276cdf0e10cSrcweir 			}
277cdf0e10cSrcweir 			// destroy temp uno param
278cdf0e10cSrcweir 			uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( pParamTypeDescr );
281cdf0e10cSrcweir 		}
282cdf0e10cSrcweir 		// return
283cdf0e10cSrcweir 		if (pCppReturn) // has complex return
284cdf0e10cSrcweir 		{
285cdf0e10cSrcweir 			if (pUnoReturn != pCppReturn) // needs reconversion
286cdf0e10cSrcweir 			{
287cdf0e10cSrcweir 				uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
288cdf0e10cSrcweir 										pThis->getBridge()->getUno2Cpp() );
289cdf0e10cSrcweir 				// destroy temp uno return
290cdf0e10cSrcweir 				uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
291cdf0e10cSrcweir 			}
292cdf0e10cSrcweir 			// complex return ptr is set to return reg
293cdf0e10cSrcweir 			*(void **)pRegisterReturn = pCppReturn;
294cdf0e10cSrcweir 		}
295cdf0e10cSrcweir 		if (pReturnTypeDescr)
296cdf0e10cSrcweir 		{
297cdf0e10cSrcweir 			typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
298cdf0e10cSrcweir 			TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
299cdf0e10cSrcweir 			return eRet;
300cdf0e10cSrcweir 		}
301cdf0e10cSrcweir 		else
302cdf0e10cSrcweir 			return typelib_TypeClass_VOID;
303cdf0e10cSrcweir 	}
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 
307cdf0e10cSrcweir //==================================================================================================
cpp_mediate(sal_Int32 nFunctionIndex,sal_Int32 nVtableOffset,void ** gpreg,void ** fpreg,void ** ovrflw,sal_Int64 * pRegisterReturn)308cdf0e10cSrcweir static typelib_TypeClass cpp_mediate(
309cdf0e10cSrcweir 	sal_Int32 nFunctionIndex,
310cdf0e10cSrcweir         sal_Int32 nVtableOffset,
311cdf0e10cSrcweir         void ** gpreg, void ** fpreg, void ** ovrflw,
312cdf0e10cSrcweir 	sal_Int64 * pRegisterReturn /* space for register return */ )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir 	OSL_ENSURE( sizeof(sal_Int32)==sizeof(void *), "### unexpected!" );
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 	// gpreg:  [ret *], this, [other gpr params]
317cdf0e10cSrcweir 	// fpreg:  [fpr params]
318cdf0e10cSrcweir 	// ovrflw: [gpr or fpr params (in space allocated for all params properly aligned)]
319cdf0e10cSrcweir 
320cdf0e10cSrcweir         void * pThis;
321cdf0e10cSrcweir 	if( nFunctionIndex & 0x80000000 )
322cdf0e10cSrcweir 	{
323cdf0e10cSrcweir 		nFunctionIndex &= 0x7fffffff;
324cdf0e10cSrcweir 		pThis = gpreg[1];
325cdf0e10cSrcweir 	}
326cdf0e10cSrcweir 	else
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir 		pThis = gpreg[0];
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir         pThis = static_cast< char * >(pThis) - nVtableOffset;
332cdf0e10cSrcweir         bridges::cpp_uno::shared::CppInterfaceProxy * pCppI
333cdf0e10cSrcweir 	= bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(pThis);
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 	OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
339cdf0e10cSrcweir 	if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
340cdf0e10cSrcweir 	{
341cdf0e10cSrcweir 		throw RuntimeException(
342cdf0e10cSrcweir             rtl::OUString::createFromAscii("illegal vtable index!"),
343cdf0e10cSrcweir             (XInterface *)pThis );
344cdf0e10cSrcweir 	}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 	// determine called method
347cdf0e10cSrcweir 	sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
348cdf0e10cSrcweir 	OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### illegal member index!" );
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 	TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 	typelib_TypeClass eRet;
353cdf0e10cSrcweir 	switch (aMemberDescr.get()->eTypeClass)
354cdf0e10cSrcweir 	{
355cdf0e10cSrcweir 	case typelib_TypeClass_INTERFACE_ATTRIBUTE:
356cdf0e10cSrcweir 	{
357cdf0e10cSrcweir 		if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
358cdf0e10cSrcweir 		{
359cdf0e10cSrcweir 			// is GET method
360cdf0e10cSrcweir 			eRet = cpp2uno_call(
361cdf0e10cSrcweir 				pCppI, aMemberDescr.get(),
362cdf0e10cSrcweir 				((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
363cdf0e10cSrcweir 				0, 0, // no params
364cdf0e10cSrcweir 				gpreg, fpreg, ovrflw, pRegisterReturn );
365cdf0e10cSrcweir 		}
366cdf0e10cSrcweir 		else
367cdf0e10cSrcweir 		{
368cdf0e10cSrcweir 			// is SET method
369cdf0e10cSrcweir 			typelib_MethodParameter aParam;
370cdf0e10cSrcweir 			aParam.pTypeRef =
371cdf0e10cSrcweir 				((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
372cdf0e10cSrcweir 			aParam.bIn		= sal_True;
373cdf0e10cSrcweir 			aParam.bOut		= sal_False;
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 			eRet = cpp2uno_call(
376cdf0e10cSrcweir 				pCppI, aMemberDescr.get(),
377cdf0e10cSrcweir 				0, // indicates void return
378cdf0e10cSrcweir 				1, &aParam,
379cdf0e10cSrcweir 				gpreg, fpreg, ovrflw, pRegisterReturn );
380cdf0e10cSrcweir 		}
381cdf0e10cSrcweir 		break;
382cdf0e10cSrcweir 	}
383cdf0e10cSrcweir 	case typelib_TypeClass_INTERFACE_METHOD:
384cdf0e10cSrcweir 	{
385cdf0e10cSrcweir 		// is METHOD
386cdf0e10cSrcweir 		switch (nFunctionIndex)
387cdf0e10cSrcweir 		{
388cdf0e10cSrcweir 		case 1: // acquire()
389cdf0e10cSrcweir 			pCppI->acquireProxy(); // non virtual call!
390cdf0e10cSrcweir 			eRet = typelib_TypeClass_VOID;
391cdf0e10cSrcweir 			break;
392cdf0e10cSrcweir 		case 2: // release()
393cdf0e10cSrcweir 			pCppI->releaseProxy(); // non virtual call!
394cdf0e10cSrcweir 			eRet = typelib_TypeClass_VOID;
395cdf0e10cSrcweir 			break;
396cdf0e10cSrcweir 		case 0: // queryInterface() opt
397cdf0e10cSrcweir 		{
398cdf0e10cSrcweir 			typelib_TypeDescription * pTD = 0;
399cdf0e10cSrcweir 			TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
400cdf0e10cSrcweir 			if (pTD)
401cdf0e10cSrcweir 			{
402cdf0e10cSrcweir                 XInterface * pInterface = 0;
403cdf0e10cSrcweir                 (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
404cdf0e10cSrcweir                     pCppI->getBridge()->getCppEnv(),
405cdf0e10cSrcweir                     (void **)&pInterface, pCppI->getOid().pData, (typelib_InterfaceTypeDescription *)pTD );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir                 if (pInterface)
408cdf0e10cSrcweir                 {
409cdf0e10cSrcweir                     ::uno_any_construct(
410cdf0e10cSrcweir                         reinterpret_cast< uno_Any * >( gpreg[0] ),
411cdf0e10cSrcweir                         &pInterface, pTD, cpp_acquire );
412cdf0e10cSrcweir                     pInterface->release();
413cdf0e10cSrcweir                     TYPELIB_DANGER_RELEASE( pTD );
414cdf0e10cSrcweir                     *(void **)pRegisterReturn = gpreg[0];
415cdf0e10cSrcweir                     eRet = typelib_TypeClass_ANY;
416cdf0e10cSrcweir                     break;
417cdf0e10cSrcweir                 }
418cdf0e10cSrcweir                 TYPELIB_DANGER_RELEASE( pTD );
419cdf0e10cSrcweir             }
420cdf0e10cSrcweir 		} // else perform queryInterface()
421cdf0e10cSrcweir 		default:
422cdf0e10cSrcweir 			eRet = cpp2uno_call(
423cdf0e10cSrcweir 				pCppI, aMemberDescr.get(),
424cdf0e10cSrcweir 				((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
425cdf0e10cSrcweir 				((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
426cdf0e10cSrcweir 				((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
427cdf0e10cSrcweir 				gpreg, fpreg, ovrflw, pRegisterReturn );
428cdf0e10cSrcweir 		}
429cdf0e10cSrcweir 		break;
430cdf0e10cSrcweir 	}
431cdf0e10cSrcweir 	default:
432cdf0e10cSrcweir 	{
433cdf0e10cSrcweir 		throw RuntimeException(
434cdf0e10cSrcweir             rtl::OUString::createFromAscii("no member description found!"),
435cdf0e10cSrcweir             (XInterface *)pThis );
436cdf0e10cSrcweir 		// is here for dummy
437cdf0e10cSrcweir 		eRet = typelib_TypeClass_VOID;
438cdf0e10cSrcweir 	}
439cdf0e10cSrcweir 	}
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 	return eRet;
442cdf0e10cSrcweir }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir //==================================================================================================
445cdf0e10cSrcweir /**
446cdf0e10cSrcweir  * is called on incoming vtable calls
447cdf0e10cSrcweir  * (called by asm snippets)
448cdf0e10cSrcweir  */
cpp_vtable_call(int nFunctionIndex,int nVtableOffset,void ** gpregptr,void ** fpregptr,void ** ovrflw)449cdf0e10cSrcweir static void cpp_vtable_call( int nFunctionIndex, int nVtableOffset, void** gpregptr, void** fpregptr, void** ovrflw)
450cdf0e10cSrcweir {
451cdf0e10cSrcweir         sal_Int32     gpreg[8];
452cdf0e10cSrcweir         double        fpreg[13];
453cdf0e10cSrcweir 
454cdf0e10cSrcweir         // FIXME: why are we restoring the volatile ctr register here
455cdf0e10cSrcweir 	sal_Int32   ctrsave = ((sal_Int32*)gpregptr)[-1];
456cdf0e10cSrcweir 
457cdf0e10cSrcweir         memcpy( gpreg, gpregptr, 32);
458cdf0e10cSrcweir         memcpy( fpreg, fpregptr, 104);
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 	volatile long nRegReturn[2];
461cdf0e10cSrcweir 
462cdf0e10cSrcweir         // sal_Bool bComplex = nFunctionIndex & 0x80000000 ? sal_True : sal_False;
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 	typelib_TypeClass aType =
465cdf0e10cSrcweir              cpp_mediate( nFunctionIndex, nVtableOffset, (void**)gpreg, (void**)fpreg, ovrflw, (sal_Int64*)nRegReturn );
466cdf0e10cSrcweir 
467cdf0e10cSrcweir         // FIXME: why are we restoring the volatile ctr register here
468cdf0e10cSrcweir         // FIXME: and why are we putting back the values for r4, r5, and r6 as well
469cdf0e10cSrcweir         // FIXME: this makes no sense to me, all of these registers are volatile!
470cdf0e10cSrcweir 	__asm__( "lwz r4, %0\n\t"
471cdf0e10cSrcweir 		"mtctr r4\n\t"
472cdf0e10cSrcweir 		"lwz r4, %1\n\t"
473cdf0e10cSrcweir 		"lwz r5, %2\n\t"
474cdf0e10cSrcweir 		"lwz r6, %3\n\t"
475cdf0e10cSrcweir 		 : : "m"(ctrsave), "m"(gpreg[1]), "m"(gpreg[2]), "m"(gpreg[3]) );
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 	switch( aType )
478cdf0e10cSrcweir 	{
479cdf0e10cSrcweir 
480cdf0e10cSrcweir                 // move return value into register space
481cdf0e10cSrcweir                 // (will be loaded by machine code snippet)
482cdf0e10cSrcweir 
483cdf0e10cSrcweir                 case typelib_TypeClass_BOOLEAN:
484cdf0e10cSrcweir                 case typelib_TypeClass_BYTE:
485cdf0e10cSrcweir                   __asm__( "lbz r3,%0\n\t" : :
486cdf0e10cSrcweir 			   "m"(nRegReturn[0]) );
487cdf0e10cSrcweir                   break;
488cdf0e10cSrcweir 
489cdf0e10cSrcweir                 case typelib_TypeClass_CHAR:
490cdf0e10cSrcweir                 case typelib_TypeClass_SHORT:
491cdf0e10cSrcweir                 case typelib_TypeClass_UNSIGNED_SHORT:
492cdf0e10cSrcweir                   __asm__( "lhz r3,%0\n\t" : :
493cdf0e10cSrcweir 			   "m"(nRegReturn[0]) );
494cdf0e10cSrcweir                   break;
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 		case typelib_TypeClass_FLOAT:
497cdf0e10cSrcweir                   __asm__( "lfs f1,%0\n\t" : :
498cdf0e10cSrcweir                            "m" (*((float*)nRegReturn)) );
499cdf0e10cSrcweir 		  break;
500cdf0e10cSrcweir 
501cdf0e10cSrcweir 		case typelib_TypeClass_DOUBLE:
502cdf0e10cSrcweir 		  __asm__( "lfd f1,%0\n\t" : :
503cdf0e10cSrcweir                            "m" (*((double*)nRegReturn)) );
504cdf0e10cSrcweir 		  break;
505cdf0e10cSrcweir 
506cdf0e10cSrcweir 		case typelib_TypeClass_HYPER:
507cdf0e10cSrcweir 		case typelib_TypeClass_UNSIGNED_HYPER:
508cdf0e10cSrcweir 		  __asm__( "lwz r4,%0\n\t" : :
509cdf0e10cSrcweir                            "m"(nRegReturn[1]) );  // fall through
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 		default:
512cdf0e10cSrcweir 		  __asm__( "lwz r3,%0\n\t" : :
513cdf0e10cSrcweir                            "m"(nRegReturn[0]) );
514cdf0e10cSrcweir 		  break;
515cdf0e10cSrcweir 	}
516cdf0e10cSrcweir }
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 
519cdf0e10cSrcweir int const codeSnippetSize = 136;
520cdf0e10cSrcweir 
codeSnippet(unsigned char * code,sal_Int32 functionIndex,sal_Int32 vtableOffset,bool simpleRetType)521cdf0e10cSrcweir unsigned char * codeSnippet( unsigned char * code, sal_Int32 functionIndex,
522cdf0e10cSrcweir                   sal_Int32 vtableOffset, bool simpleRetType )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir     if (! simpleRetType )
525cdf0e10cSrcweir         functionIndex |= 0x80000000;
526cdf0e10cSrcweir 
527cdf0e10cSrcweir     // OSL_ASSERT( sizeof (long) == 4 );
528cdf0e10cSrcweir 
529cdf0e10cSrcweir     // FIXME: why are we leaving an 8k gap in the stack here
530cdf0e10cSrcweir     // FIXME: is this to allow room for signal handling frames?
531cdf0e10cSrcweir     // FIXME: seems like overkill here but this is what was done for Mac OSX for gcc2
532cdf0e10cSrcweir     // FIXME: also why no saving of the non-volatile CR pieces here, to be safe
533cdf0e10cSrcweir     // FIXME: we probably should
534cdf0e10cSrcweir 
535cdf0e10cSrcweir     /* generate this code */
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     // # so first save gpr 3 to gpr 10 (aligned to 4)
538cdf0e10cSrcweir     //  stw   r3, -8000(r1)
539cdf0e10cSrcweir     //  stw   r4, -7996(r1)
540cdf0e10cSrcweir     //  stw   r5, -7992(r1)
541cdf0e10cSrcweir     //  stw   r6, -7988(r1)
542cdf0e10cSrcweir     //  stw   r7, -7984(r1)
543cdf0e10cSrcweir     //  stw   r8, -7980(r1)
544cdf0e10cSrcweir     //  stw   r9, -7976(r1)
545cdf0e10cSrcweir     //  stw   r10,-7972(r1)
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     // # next save fpr 1 to fpr 13 (aligned to 8)
548cdf0e10cSrcweir     //  stfd  f1, -7968(r1)
549cdf0e10cSrcweir     //  stfd  f2, -7960(r1)
550cdf0e10cSrcweir     //  stfd  f3, -7952(r1)
551cdf0e10cSrcweir     //  stfd  f4, -7944(r1)
552cdf0e10cSrcweir     //  stfd  f5, -7936(r1)
553cdf0e10cSrcweir     //  stfd  f6, -7928(r1)
554cdf0e10cSrcweir     //  stfd  f7, -7920(r1)
555cdf0e10cSrcweir     //  stfd  f8, -7912(r1)
556cdf0e10cSrcweir     //  stfd  f9, -7904(r1)
557cdf0e10cSrcweir     //  stfd  f10,-7896(r1)
558cdf0e10cSrcweir     //  stfd  f11,-7888(r1)
559cdf0e10cSrcweir     //  stfd  f12,-7880(r1)
560cdf0e10cSrcweir     //  stfd  f13,-7872(r1)
561cdf0e10cSrcweir 
562cdf0e10cSrcweir     // FIXME: ctr is volatile, while are we saving it and not CR?
563cdf0e10cSrcweir     // mfctr r3
564cdf0e10cSrcweir     // stw r3, -8004(r1)
565cdf0e10cSrcweir 
566cdf0e10cSrcweir     // # now here is where cpp_vtable_call must go
567cdf0e10cSrcweir     // lis r3,0xdead
568cdf0e10cSrcweir     // ori r3,r3,0xbeef
569cdf0e10cSrcweir     // mtctr r3
570cdf0e10cSrcweir 
571cdf0e10cSrcweir     // # now load up the functionIndex number
572cdf0e10cSrcweir     // lis r3, 0xdead
573cdf0e10cSrcweir     // ori r3,r3,0xbeef
574cdf0e10cSrcweir 
575cdf0e10cSrcweir     // # now load up the vtableOffset
576cdf0e10cSrcweir     // lis r4, 0xdead
577cdf0e10cSrcweir     // ori r4,r4,0xbeef
578cdf0e10cSrcweir 
579cdf0e10cSrcweir     // #now load up the pointer to the saved gpr registers
580cdf0e10cSrcweir     // addi r5,r1,-8000
581cdf0e10cSrcweir 
582cdf0e10cSrcweir     // #now load up the pointer to the saved fpr registers
583cdf0e10cSrcweir     // addi r6,r1,-7968
584cdf0e10cSrcweir 
585cdf0e10cSrcweir     // #now load up the pointer to the overflow call stack
586cdf0e10cSrcweir     // addi r7,r1,24 # frame pointer plus 24
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     // bctr
589cdf0e10cSrcweir 
590cdf0e10cSrcweir     unsigned long * p = (unsigned long *) code;
591cdf0e10cSrcweir 
592cdf0e10cSrcweir     * p++ = 0x9061e0c0;
593cdf0e10cSrcweir     * p++ = 0x9081e0c4;
594cdf0e10cSrcweir     * p++ = 0x90a1e0c8;
595cdf0e10cSrcweir     * p++ = 0x90c1e0cc;
596cdf0e10cSrcweir     * p++ = 0x90e1e0d0;
597cdf0e10cSrcweir     * p++ = 0x9101e0d4;
598cdf0e10cSrcweir     * p++ = 0x9121e0d8;
599cdf0e10cSrcweir     * p++ = 0x9141e0dc;
600cdf0e10cSrcweir     * p++ = 0xd821e0e0;
601cdf0e10cSrcweir     * p++ = 0xd841e0e8;
602cdf0e10cSrcweir     * p++ = 0xd861e0f0;
603cdf0e10cSrcweir     * p++ = 0xd881e0f8;
604cdf0e10cSrcweir     * p++ = 0xd8a1e100;
605cdf0e10cSrcweir     * p++ = 0xd8c1e108;
606cdf0e10cSrcweir     * p++ = 0xd8e1e110;
607cdf0e10cSrcweir     * p++ = 0xd901e118;
608cdf0e10cSrcweir     * p++ = 0xd921e120;
609cdf0e10cSrcweir     * p++ = 0xd941e128;
610cdf0e10cSrcweir     * p++ = 0xd961e130;
611cdf0e10cSrcweir     * p++ = 0xd981e138;
612cdf0e10cSrcweir     * p++ = 0xd9a1e140;
613cdf0e10cSrcweir     * p++ = 0x7c6902a6;
614cdf0e10cSrcweir     * p++ = 0x9061e0bc;
615cdf0e10cSrcweir     * p++ = 0x3c600000 | (((unsigned long)cpp_vtable_call) >> 16);
616cdf0e10cSrcweir     * p++ = 0x60630000 | (((unsigned long)cpp_vtable_call) & 0x0000FFFF);
617cdf0e10cSrcweir     * p++ = 0x7c6903a6;
618cdf0e10cSrcweir     * p++ = 0x3c600000 | (((unsigned long)functionIndex) >> 16);
619cdf0e10cSrcweir     * p++ = 0x60630000 | (((unsigned long)functionIndex) & 0x0000FFFF);
620cdf0e10cSrcweir     * p++ = 0x3c800000 | (((unsigned long)vtableOffset) >> 16);
621cdf0e10cSrcweir     * p++ = 0x60840000 | (((unsigned long)vtableOffset) & 0x0000FFFF);
622cdf0e10cSrcweir     * p++ = 0x38a1e0c0;
623cdf0e10cSrcweir     * p++ = 0x38c1e0e0;
624cdf0e10cSrcweir     * p++ = 0x38e10018;
625cdf0e10cSrcweir     * p++ = 0x4e800420;
626cdf0e10cSrcweir 
627cdf0e10cSrcweir     return (code + codeSnippetSize);
628cdf0e10cSrcweir 
629cdf0e10cSrcweir }
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
flushCode(unsigned char const * bptr,unsigned char const * eptr)634cdf0e10cSrcweir void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const * bptr, unsigned char const * eptr)
635cdf0e10cSrcweir {
636cdf0e10cSrcweir     int const lineSize = 32;
637cdf0e10cSrcweir     for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
638cdf0e10cSrcweir         __asm__ volatile ("dcbst 0, %0" : : "r"(p) : "memory");
639cdf0e10cSrcweir     }
640cdf0e10cSrcweir     __asm__ volatile ("sync" : : : "memory");
641cdf0e10cSrcweir     for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
642cdf0e10cSrcweir         __asm__ volatile ("icbi 0, %0" : : "r"(p) : "memory");
643cdf0e10cSrcweir     }
644cdf0e10cSrcweir     __asm__ volatile ("isync" : : : "memory");
645cdf0e10cSrcweir }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir struct bridges::cpp_uno::shared::VtableFactory::Slot { void * fn; };
648cdf0e10cSrcweir 
649cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot *
mapBlockToVtable(void * block)650cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
651cdf0e10cSrcweir {
652cdf0e10cSrcweir     return static_cast< Slot * >(block) + 2;
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
getBlockSize(sal_Int32 slotCount)655cdf0e10cSrcweir sal_Size bridges::cpp_uno::shared::VtableFactory::getBlockSize(
656cdf0e10cSrcweir     sal_Int32 slotCount)
657cdf0e10cSrcweir {
658cdf0e10cSrcweir     return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
659cdf0e10cSrcweir }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot *
initializeBlock(void * block,sal_Int32 slotCount)662cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::initializeBlock(
663cdf0e10cSrcweir     void * block, sal_Int32 slotCount)
664cdf0e10cSrcweir {
665cdf0e10cSrcweir     Slot * slots = mapBlockToVtable(block);
666cdf0e10cSrcweir     slots[-2].fn = 0;
667cdf0e10cSrcweir     slots[-1].fn = 0;
668cdf0e10cSrcweir     return slots + slotCount;
669cdf0e10cSrcweir }
670cdf0e10cSrcweir 
addLocalFunctions(Slot ** slots,unsigned char * code,typelib_InterfaceTypeDescription const * type,sal_Int32 functionOffset,sal_Int32 functionCount,sal_Int32 vtableOffset)671cdf0e10cSrcweir unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
672cdf0e10cSrcweir     Slot ** slots, unsigned char * code,
673cdf0e10cSrcweir     typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
674cdf0e10cSrcweir     sal_Int32 functionCount, sal_Int32 vtableOffset)
675cdf0e10cSrcweir {
676cdf0e10cSrcweir     (*slots) -= functionCount;
677cdf0e10cSrcweir     Slot * s = *slots;
678cdf0e10cSrcweir 
679cdf0e10cSrcweir   // fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
680cdf0e10cSrcweir   // fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
681cdf0e10cSrcweir   // fflush(stderr);
682cdf0e10cSrcweir 
683cdf0e10cSrcweir     for (sal_Int32 i = 0; i < type->nMembers; ++i) {
684cdf0e10cSrcweir         typelib_TypeDescription * member = 0;
685cdf0e10cSrcweir         TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
686cdf0e10cSrcweir         OSL_ASSERT(member != 0);
687cdf0e10cSrcweir         switch (member->eTypeClass) {
688cdf0e10cSrcweir         case typelib_TypeClass_INTERFACE_ATTRIBUTE:
689cdf0e10cSrcweir             // Getter:
690cdf0e10cSrcweir             (s++)->fn = code;
691cdf0e10cSrcweir             code = codeSnippet(
692cdf0e10cSrcweir                 code, functionOffset++, vtableOffset,
693cdf0e10cSrcweir                 bridges::cpp_uno::shared::isSimpleType(
694cdf0e10cSrcweir                     reinterpret_cast<
695cdf0e10cSrcweir                     typelib_InterfaceAttributeTypeDescription * >(
696cdf0e10cSrcweir                         member)->pAttributeTypeRef));
697cdf0e10cSrcweir 
698cdf0e10cSrcweir             // Setter:
699cdf0e10cSrcweir             if (!reinterpret_cast<
700cdf0e10cSrcweir                 typelib_InterfaceAttributeTypeDescription * >(
701cdf0e10cSrcweir                     member)->bReadOnly)
702cdf0e10cSrcweir             {
703cdf0e10cSrcweir                 (s++)->fn = code;
704cdf0e10cSrcweir                 code = codeSnippet(code, functionOffset++, vtableOffset, true);
705cdf0e10cSrcweir             }
706cdf0e10cSrcweir             break;
707cdf0e10cSrcweir 
708cdf0e10cSrcweir         case typelib_TypeClass_INTERFACE_METHOD:
709cdf0e10cSrcweir             (s++)->fn = code;
710cdf0e10cSrcweir             code = codeSnippet(
711cdf0e10cSrcweir                 code, functionOffset++, vtableOffset,
712cdf0e10cSrcweir                 bridges::cpp_uno::shared::isSimpleType(
713cdf0e10cSrcweir                     reinterpret_cast<
714cdf0e10cSrcweir                     typelib_InterfaceMethodTypeDescription * >(
715cdf0e10cSrcweir                         member)->pReturnTypeRef));
716cdf0e10cSrcweir             break;
717cdf0e10cSrcweir 
718cdf0e10cSrcweir         default:
719cdf0e10cSrcweir             OSL_ASSERT(false);
720cdf0e10cSrcweir             break;
721cdf0e10cSrcweir         }
722cdf0e10cSrcweir         TYPELIB_DANGER_RELEASE(member);
723cdf0e10cSrcweir     }
724cdf0e10cSrcweir     return code;
725cdf0e10cSrcweir }
726cdf0e10cSrcweir 
727