LibreOffice Module bridges (master) 1
vtables.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <vtables.hxx>
22
23#include <sal/types.h>
24#include <typelib/typedescription.h>
25
26#include <algorithm>
27#include <cassert>
28
29namespace
30{
31
40sal_Int32 getVtableCount(typelib_InterfaceTypeDescription const * type) {
41 sal_Int32 n = 0;
42 for (sal_Int32 i = 0; i < type->nBaseTypes; ++i) {
43 n += getVtableCount(type->ppBaseTypes[i]);
44 }
45 return std::max< sal_Int32 >(n, 1);
46}
47
61sal_Int32 mapLocalMemberToLocalFunction(
62 typelib_InterfaceTypeDescription * type, sal_Int32 localMember)
63{
65 reinterpret_cast< typelib_TypeDescription ** >(&type));
66 sal_Int32 localMemberOffset = type->nAllMembers - type->nMembers;
67 sal_Int32 localFunctionOffset = type->nMapFunctionIndexToMemberIndex
69 return type->pMapMemberIndexToFunctionIndex[localMemberOffset + localMember]
70 - localFunctionOffset;
71}
72
73// Since on Solaris we compile with --instances=static, getVtableSlot cannot be
74// a template function, with explicit instantiates for
75// T = typelib_InterfaceAttributeTypeDescription and
76// T = typelib_InterfaceMethodTypeDescription in this file; hence, there are two
77// overloaded versions of getVtableSlot that both delegate to this template
78// function:
79template< typename T > bridges::cpp_uno::shared::VtableSlot doGetVtableSlot(
80 T const * ifcMember)
81{
83 slot.offset = 0;
84 T * member = const_cast< T * >(ifcMember);
85 while (member->pBaseRef != nullptr) {
86 assert(member->nIndex < member->pInterface->nBaseTypes);
87 for (sal_Int32 i = 0; i < member->nIndex; ++i) {
88 slot.offset += getVtableCount(member->pInterface->ppBaseTypes[i]);
89 }
90 typelib_TypeDescription * desc = nullptr;
92 &desc, member->pBaseRef);
93 assert(
94 desc != nullptr && desc->eTypeClass == member->aBase.aBase.eTypeClass);
95 if (member != ifcMember) {
96 typelib_typedescription_release(&member->aBase.aBase);
97 }
98 member = reinterpret_cast< T * >(desc);
99 }
100 slot.index
102 member->pInterface->pBaseTypeDescription)
103 + mapLocalMemberToLocalFunction(member->pInterface, member->nIndex);
104 if (member != ifcMember) {
105 typelib_typedescription_release(&member->aBase.aBase);
106 }
107 return slot;
108}
109
110}
111
112namespace bridges::cpp_uno::shared {
113
114sal_Int32 getLocalFunctions(typelib_InterfaceTypeDescription const * type) {
115 return type->nMembers == 0
116 ? 0
117 : (type->nMapFunctionIndexToMemberIndex
118 - type->pMapMemberIndexToFunctionIndex[
119 type->nAllMembers - type->nMembers]);
120}
121
122sal_Int32 getPrimaryFunctions(typelib_InterfaceTypeDescription * type) {
123 sal_Int32 n = 0;
124 for (; type != nullptr; type = type->pBaseTypeDescription) {
126 reinterpret_cast< typelib_TypeDescription ** >(&type));
128 }
129 return n;
130}
131
133 typelib_InterfaceAttributeTypeDescription const * ifcMember)
134{
135 return doGetVtableSlot(ifcMember);
136}
137
139 typelib_InterfaceMethodTypeDescription const * ifcMember)
140{
141 return doGetVtableSlot(ifcMember);
142}
143
144}
145
146/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int64 n
struct _typelib_TypeDescription typelib_TypeDescription
Definition: msvc/except.hxx:53
sal_Int32 getLocalFunctions(typelib_InterfaceTypeDescription const *type)
Calculate the number of local functions of an interface type.
Definition: vtables.cxx:114
sal_Int32 getPrimaryFunctions(typelib_InterfaceTypeDescription *type)
Calculate the number of primary functions of an interface type.
Definition: vtables.cxx:122
VtableSlot getVtableSlot(typelib_InterfaceAttributeTypeDescription const *ifcMember)
Calculates the vtable slot associated with an interface attribute member.
Definition: vtables.cxx:132
int i
Represents a vtable slot of a C++ class.
Definition: vtables.hxx:60
sal_Int32 index
The index within the vtable.
Definition: vtables.hxx:76
sal_Int32 offset
The offset of the vtable.
Definition: vtables.hxx:68
void SAL_CALL typelib_typedescription_release(typelib_TypeDescription *pTD) SAL_THROW_EXTERN_C()
sal_Bool SAL_CALL typelib_typedescription_complete(typelib_TypeDescription **ppTypeDescr) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescriptionreference_getDescription(typelib_TypeDescription **ppRet, typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
ResultType type