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
10cdf0e10cSrcweir *
11*61dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
20*61dff127SAndrew Rist *************************************************************/
21*61dff127SAndrew Rist
22*61dff127SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_bridges.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <cstddef>
28cdf0e10cSrcweir #include <cstring>
29cdf0e10cSrcweir #include <map>
30cdf0e10cSrcweir #include <utility>
31cdf0e10cSrcweir #include <vector>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "bridges/cpp_uno/shared/arraypointer.hxx"
34cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
35cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
36cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
37cdf0e10cSrcweir #include "com/sun/star/uno/genfunc.hxx"
38cdf0e10cSrcweir #include "osl/diagnose.h"
39cdf0e10cSrcweir #include "osl/mutex.hxx"
40cdf0e10cSrcweir #include "rtl/strbuf.hxx"
41cdf0e10cSrcweir #include "rtl/string.hxx"
42cdf0e10cSrcweir #include "rtl/textenc.h"
43cdf0e10cSrcweir #include "rtl/ustring.h"
44cdf0e10cSrcweir #include "rtl/ustring.hxx"
45cdf0e10cSrcweir #include "sal/types.h"
46cdf0e10cSrcweir #include "typelib/typeclass.h"
47cdf0e10cSrcweir #include "typelib/typedescription.h"
48cdf0e10cSrcweir #include "uno/any2.h"
49cdf0e10cSrcweir #include "uno/data.h"
50cdf0e10cSrcweir #include "uno/mapping.h"
51cdf0e10cSrcweir
52cdf0e10cSrcweir #include "exceptions.hxx"
53cdf0e10cSrcweir #include "flushcode.hxx"
54cdf0e10cSrcweir
55cdf0e10cSrcweir namespace {
56cdf0e10cSrcweir
57cdf0e10cSrcweir namespace css = com::sun::star;
58cdf0e10cSrcweir
59cdf0e10cSrcweir typedef void (* Function)(void *);
60cdf0e10cSrcweir
toFunction(void * pointer)61cdf0e10cSrcweir Function toFunction(void * pointer) {
62cdf0e10cSrcweir #pragma disable_warn
63cdf0e10cSrcweir return reinterpret_cast< Function >(pointer);
64cdf0e10cSrcweir #pragma enable_warn
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
toUnoName(char const * rttiName,rtl::OUString * unoName)67cdf0e10cSrcweir bool toUnoName(char const * rttiName, rtl::OUString * unoName) {
68cdf0e10cSrcweir rtl::OStringBuffer buf;
69cdf0e10cSrcweir for (;;) {
70cdf0e10cSrcweir char const * p = std::strchr(rttiName, ':');
71cdf0e10cSrcweir if (p == NULL) {
72cdf0e10cSrcweir buf.append(rttiName);
73cdf0e10cSrcweir break;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir if (p - rttiName > SAL_MAX_INT32) {
76cdf0e10cSrcweir return false;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir buf.append(rttiName, sal::static_int_cast< sal_Int32 >(p - rttiName));
79cdf0e10cSrcweir buf.append(".");
80cdf0e10cSrcweir while (*p == ':') {
81cdf0e10cSrcweir ++p;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir rttiName = p;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir *unoName = rtl::OStringToOUString(
86cdf0e10cSrcweir buf.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
87cdf0e10cSrcweir //TODO: check conversion failure
88cdf0e10cSrcweir return true;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir class NistHash {
92cdf0e10cSrcweir public:
93cdf0e10cSrcweir NistHash(rtl::OString const & text);
94cdf0e10cSrcweir
95cdf0e10cSrcweir sal_uInt32 hashdata[5];
96cdf0e10cSrcweir
97cdf0e10cSrcweir private:
f1(sal_uInt32 x,sal_uInt32 y,sal_uInt32 z)98cdf0e10cSrcweir static sal_uInt32 f1(sal_uInt32 x, sal_uInt32 y, sal_uInt32 z)
99cdf0e10cSrcweir { return z ^ (x & (y ^ z)); }
100cdf0e10cSrcweir
f2(sal_uInt32 x,sal_uInt32 y,sal_uInt32 z)101cdf0e10cSrcweir static sal_uInt32 f2(sal_uInt32 x, sal_uInt32 y, sal_uInt32 z)
102cdf0e10cSrcweir { return x ^ y ^ z; }
103cdf0e10cSrcweir
f3(sal_uInt32 x,sal_uInt32 y,sal_uInt32 z)104cdf0e10cSrcweir static sal_uInt32 f3(sal_uInt32 x, sal_uInt32 y, sal_uInt32 z)
105cdf0e10cSrcweir { return (x & y) + (z & (x ^ y)); }
106cdf0e10cSrcweir
rotl(sal_uInt32 value,sal_uInt32 bits)107cdf0e10cSrcweir static sal_uInt32 rotl(sal_uInt32 value, sal_uInt32 bits)
108cdf0e10cSrcweir { return (value << bits) | (value >> (32 - bits)); }
109cdf0e10cSrcweir
expand_nostore(sal_uInt32 index)110cdf0e10cSrcweir sal_uInt32 expand_nostore(sal_uInt32 index) {
111cdf0e10cSrcweir return data[index & 15] ^ data[(index - 14) & 15] ^
112cdf0e10cSrcweir data[(index - 8) & 15] ^ data[(index - 3) & 15];
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
expand_store(sal_uInt32 index)115cdf0e10cSrcweir sal_uInt32 expand_store(sal_uInt32 index) {
116cdf0e10cSrcweir return data[index & 15] ^= data[(index - 14) & 15] ^
117cdf0e10cSrcweir data[(index - 8) & 15] ^ data[(index - 3) & 15];
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
subRound(sal_uInt32 a,sal_uInt32 & b,sal_uInt32 c,sal_uInt32 d,sal_uInt32 & e,sal_uInt32 constant,sal_uInt32 datum,sal_uInt32 function)120cdf0e10cSrcweir void subRound(
121cdf0e10cSrcweir sal_uInt32 a, sal_uInt32 & b, sal_uInt32 c, sal_uInt32 d,
122cdf0e10cSrcweir sal_uInt32 & e, sal_uInt32 constant, sal_uInt32 datum,
123cdf0e10cSrcweir sal_uInt32 function)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir e += rotl(a, 5);
126cdf0e10cSrcweir switch (function) {
127cdf0e10cSrcweir case 1:
128cdf0e10cSrcweir e += f1(b, c, d);
129cdf0e10cSrcweir break;
130cdf0e10cSrcweir case 2:
131cdf0e10cSrcweir case 4:
132cdf0e10cSrcweir e += f2(b, c, d);
133cdf0e10cSrcweir break;
134cdf0e10cSrcweir case 3:
135cdf0e10cSrcweir e += f3(b, c, d);
136cdf0e10cSrcweir break;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir e += constant + datum;
139cdf0e10cSrcweir b = rotl(b, 30);
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
142cdf0e10cSrcweir void transform();
143cdf0e10cSrcweir
144cdf0e10cSrcweir sal_uInt32 data[16];
145cdf0e10cSrcweir };
146cdf0e10cSrcweir
NistHash(rtl::OString const & text)147cdf0e10cSrcweir NistHash::NistHash(rtl::OString const & text) {
148cdf0e10cSrcweir hashdata[0] = 0x67452301;
149cdf0e10cSrcweir hashdata[1] = 0xefcdab89;
150cdf0e10cSrcweir hashdata[2] = 0x98badcfe;
151cdf0e10cSrcweir hashdata[3] = 0x10325476;
152cdf0e10cSrcweir hashdata[4] = 0xc3d2e1f0;
153cdf0e10cSrcweir char const * p = text.getStr();
154cdf0e10cSrcweir sal_Int32 n = text.getLength();
155cdf0e10cSrcweir while (n >= sizeof data) {
156cdf0e10cSrcweir std::memcpy(data, p, sizeof data);
157cdf0e10cSrcweir p += sizeof data;
158cdf0e10cSrcweir n -= sizeof data;
159cdf0e10cSrcweir transform();
160cdf0e10cSrcweir }
161cdf0e10cSrcweir std::memcpy(data, p, n);
162cdf0e10cSrcweir reinterpret_cast< unsigned char *>(data)[n++] = 0x80;
163cdf0e10cSrcweir if (n > sizeof data - 8) {
164cdf0e10cSrcweir std::memset(reinterpret_cast< char * >(data) + n, 0, sizeof data - n);
165cdf0e10cSrcweir transform();
166cdf0e10cSrcweir std::memset(data, 0, sizeof data - 8);
167cdf0e10cSrcweir } else {
168cdf0e10cSrcweir std::memset(
169cdf0e10cSrcweir reinterpret_cast< char * >(data) + n, 0, sizeof data - 8 - n);
170cdf0e10cSrcweir }
171cdf0e10cSrcweir data[14] = 0;
172cdf0e10cSrcweir data[15] = text.getLength() << 3;
173cdf0e10cSrcweir transform();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
transform()176cdf0e10cSrcweir void NistHash::transform() {
177cdf0e10cSrcweir sal_uInt32 const K2 = 0x5A827999;
178cdf0e10cSrcweir sal_uInt32 const K3 = 0x6ED9EBA1;
179cdf0e10cSrcweir sal_uInt32 const K5 = 0x8F1BBCDC;
180cdf0e10cSrcweir sal_uInt32 const K10 = 0xCA62C1D6;
181cdf0e10cSrcweir sal_uInt32 a = hashdata[0];
182cdf0e10cSrcweir sal_uInt32 b = hashdata[1];
183cdf0e10cSrcweir sal_uInt32 c = hashdata[2];
184cdf0e10cSrcweir sal_uInt32 d = hashdata[3];
185cdf0e10cSrcweir sal_uInt32 e = hashdata[4];
186cdf0e10cSrcweir subRound(a, b, c, d, e, K2, data[ 0], 1);
187cdf0e10cSrcweir subRound(e, a, b, c, d, K2, data[ 1], 1);
188cdf0e10cSrcweir subRound(d, e, a, b, c, K2, data[ 2], 1);
189cdf0e10cSrcweir subRound(c, d, e, a, b, K2, data[ 3], 1);
190cdf0e10cSrcweir subRound(b, c, d, e, a, K2, data[ 4], 1);
191cdf0e10cSrcweir subRound(a, b, c, d, e, K2, data[ 5], 1);
192cdf0e10cSrcweir subRound(e, a, b, c, d, K2, data[ 6], 1);
193cdf0e10cSrcweir subRound(d, e, a, b, c, K2, data[ 7], 1);
194cdf0e10cSrcweir subRound(c, d, e, a, b, K2, data[ 8], 1);
195cdf0e10cSrcweir subRound(b, c, d, e, a, K2, data[ 9], 1);
196cdf0e10cSrcweir subRound(a, b, c, d, e, K2, data[10], 1);
197cdf0e10cSrcweir subRound(e, a, b, c, d, K2, data[11], 1);
198cdf0e10cSrcweir subRound(d, e, a, b, c, K2, data[12], 1);
199cdf0e10cSrcweir subRound(c, d, e, a, b, K2, data[13], 1);
200cdf0e10cSrcweir subRound(b, c, d, e, a, K2, data[14], 1);
201cdf0e10cSrcweir subRound(a, b, c, d, e, K2, data[15], 1);
202cdf0e10cSrcweir subRound(e, a, b, c, d, K2, expand_store(16), 1);
203cdf0e10cSrcweir subRound(d, e, a, b, c, K2, expand_store(17), 1);
204cdf0e10cSrcweir subRound(c, d, e, a, b, K2, expand_store(18), 1);
205cdf0e10cSrcweir subRound(b, c, d, e, a, K2, expand_store(19), 1);
206cdf0e10cSrcweir subRound(a, b, c, d, e, K3, expand_store(20), 2);
207cdf0e10cSrcweir subRound(e, a, b, c, d, K3, expand_store(21), 2);
208cdf0e10cSrcweir subRound(d, e, a, b, c, K3, expand_store(22), 2);
209cdf0e10cSrcweir subRound(c, d, e, a, b, K3, expand_store(23), 2);
210cdf0e10cSrcweir subRound(b, c, d, e, a, K3, expand_store(24), 2);
211cdf0e10cSrcweir subRound(a, b, c, d, e, K3, expand_store(25), 2);
212cdf0e10cSrcweir subRound(e, a, b, c, d, K3, expand_store(26), 2);
213cdf0e10cSrcweir subRound(d, e, a, b, c, K3, expand_store(27), 2);
214cdf0e10cSrcweir subRound(c, d, e, a, b, K3, expand_store(28), 2);
215cdf0e10cSrcweir subRound(b, c, d, e, a, K3, expand_store(29), 2);
216cdf0e10cSrcweir subRound(a, b, c, d, e, K3, expand_store(30), 2);
217cdf0e10cSrcweir subRound(e, a, b, c, d, K3, expand_store(31), 2);
218cdf0e10cSrcweir subRound(d, e, a, b, c, K3, expand_store(32), 2);
219cdf0e10cSrcweir subRound(c, d, e, a, b, K3, expand_store(33), 2);
220cdf0e10cSrcweir subRound(b, c, d, e, a, K3, expand_store(34), 2);
221cdf0e10cSrcweir subRound(a, b, c, d, e, K3, expand_store(35), 2);
222cdf0e10cSrcweir subRound(e, a, b, c, d, K3, expand_store(36), 2);
223cdf0e10cSrcweir subRound(d, e, a, b, c, K3, expand_store(37), 2);
224cdf0e10cSrcweir subRound(c, d, e, a, b, K3, expand_store(38), 2);
225cdf0e10cSrcweir subRound(b, c, d, e, a, K3, expand_store(39), 2);
226cdf0e10cSrcweir subRound(a, b, c, d, e, K5, expand_store(40), 3);
227cdf0e10cSrcweir subRound(e, a, b, c, d, K5, expand_store(41), 3);
228cdf0e10cSrcweir subRound(d, e, a, b, c, K5, expand_store(42), 3);
229cdf0e10cSrcweir subRound(c, d, e, a, b, K5, expand_store(43), 3);
230cdf0e10cSrcweir subRound(b, c, d, e, a, K5, expand_store(44), 3);
231cdf0e10cSrcweir subRound(a, b, c, d, e, K5, expand_store(45), 3);
232cdf0e10cSrcweir subRound(e, a, b, c, d, K5, expand_store(46), 3);
233cdf0e10cSrcweir subRound(d, e, a, b, c, K5, expand_store(47), 3);
234cdf0e10cSrcweir subRound(c, d, e, a, b, K5, expand_store(48), 3);
235cdf0e10cSrcweir subRound(b, c, d, e, a, K5, expand_store(49), 3);
236cdf0e10cSrcweir subRound(a, b, c, d, e, K5, expand_store(50), 3);
237cdf0e10cSrcweir subRound(e, a, b, c, d, K5, expand_store(51), 3);
238cdf0e10cSrcweir subRound(d, e, a, b, c, K5, expand_store(52), 3);
239cdf0e10cSrcweir subRound(c, d, e, a, b, K5, expand_store(53), 3);
240cdf0e10cSrcweir subRound(b, c, d, e, a, K5, expand_store(54), 3);
241cdf0e10cSrcweir subRound(a, b, c, d, e, K5, expand_store(55), 3);
242cdf0e10cSrcweir subRound(e, a, b, c, d, K5, expand_store(56), 3);
243cdf0e10cSrcweir subRound(d, e, a, b, c, K5, expand_store(57), 3);
244cdf0e10cSrcweir subRound(c, d, e, a, b, K5, expand_store(58), 3);
245cdf0e10cSrcweir subRound(b, c, d, e, a, K5, expand_store(59), 3);
246cdf0e10cSrcweir subRound(a, b, c, d, e, K10, expand_store(60), 4);
247cdf0e10cSrcweir subRound(e, a, b, c, d, K10, expand_store(61), 4);
248cdf0e10cSrcweir subRound(d, e, a, b, c, K10, expand_store(62), 4);
249cdf0e10cSrcweir subRound(c, d, e, a, b, K10, expand_store(63), 4);
250cdf0e10cSrcweir subRound(b, c, d, e, a, K10, expand_store(64), 4);
251cdf0e10cSrcweir subRound(a, b, c, d, e, K10, expand_store(65), 4);
252cdf0e10cSrcweir subRound(e, a, b, c, d, K10, expand_store(66), 4);
253cdf0e10cSrcweir subRound(d, e, a, b, c, K10, expand_store(67), 4);
254cdf0e10cSrcweir subRound(c, d, e, a, b, K10, expand_store(68), 4);
255cdf0e10cSrcweir subRound(b, c, d, e, a, K10, expand_store(69), 4);
256cdf0e10cSrcweir subRound(a, b, c, d, e, K10, expand_store(70), 4);
257cdf0e10cSrcweir subRound(e, a, b, c, d, K10, expand_store(71), 4);
258cdf0e10cSrcweir subRound(d, e, a, b, c, K10, expand_store(72), 4);
259cdf0e10cSrcweir subRound(c, d, e, a, b, K10, expand_store(73), 4);
260cdf0e10cSrcweir subRound(b, c, d, e, a, K10, expand_store(74), 4);
261cdf0e10cSrcweir subRound(a, b, c, d, e, K10, expand_store(75), 4);
262cdf0e10cSrcweir subRound(e, a, b, c, d, K10, expand_store(76), 4);
263cdf0e10cSrcweir subRound(d, e, a, b, c, K10, expand_nostore(77), 4);
264cdf0e10cSrcweir subRound(c, d, e, a, b, K10, expand_nostore(78), 4);
265cdf0e10cSrcweir subRound(b, c, d, e, a, K10, expand_nostore(79), 4);
266cdf0e10cSrcweir hashdata[0] += a;
267cdf0e10cSrcweir hashdata[1] += b;
268cdf0e10cSrcweir hashdata[2] += c;
269cdf0e10cSrcweir hashdata[3] += d;
270cdf0e10cSrcweir hashdata[4] += e;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir class RttiMap {
274cdf0e10cSrcweir public:
275cdf0e10cSrcweir static __Crun::static_type_info const * get(
276cdf0e10cSrcweir typelib_CompoundTypeDescription const * type);
277cdf0e10cSrcweir
278cdf0e10cSrcweir private:
279cdf0e10cSrcweir RttiMap(); // not defined
280cdf0e10cSrcweir RttiMap(RttiMap &); // not defined
281cdf0e10cSrcweir ~RttiMap(); // not defined
282cdf0e10cSrcweir void operator =(RttiMap &); // not defined
283cdf0e10cSrcweir
284cdf0e10cSrcweir struct Data {
285cdf0e10cSrcweir __Crun::static_type_info * info;
286cdf0e10cSrcweir rtl::OString cppName;
287cdf0e10cSrcweir std::vector< __Crun::class_base_descr > bases;
288cdf0e10cSrcweir };
289cdf0e10cSrcweir typedef std::map< rtl::OUString, Data > Map;
290cdf0e10cSrcweir
291cdf0e10cSrcweir static void toCppNames(
292cdf0e10cSrcweir rtl::OUString const & unoName, rtl::OString * cppName,
293cdf0e10cSrcweir rtl::OString * rttiName);
294cdf0e10cSrcweir
295cdf0e10cSrcweir static Data const & get_(typelib_CompoundTypeDescription const * type);
296cdf0e10cSrcweir
297cdf0e10cSrcweir static osl::Mutex m_mutex;
298cdf0e10cSrcweir static Map * m_map;
299cdf0e10cSrcweir };
300cdf0e10cSrcweir
301cdf0e10cSrcweir osl::Mutex RttiMap::m_mutex;
302cdf0e10cSrcweir RttiMap::Map * RttiMap::m_map;
303cdf0e10cSrcweir
get(typelib_CompoundTypeDescription const * type)304cdf0e10cSrcweir __Crun::static_type_info const * RttiMap::get(
305cdf0e10cSrcweir typelib_CompoundTypeDescription const * type)
306cdf0e10cSrcweir {
307cdf0e10cSrcweir osl::MutexGuard g(m_mutex);
308cdf0e10cSrcweir if (m_map == NULL) {
309cdf0e10cSrcweir m_map = new Map; // leaked
310cdf0e10cSrcweir }
311cdf0e10cSrcweir return get_(type).info;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
toCppNames(rtl::OUString const & unoName,rtl::OString * cppName,rtl::OString * rttiName)314cdf0e10cSrcweir void RttiMap::toCppNames(
315cdf0e10cSrcweir rtl::OUString const & unoName, rtl::OString * cppName,
316cdf0e10cSrcweir rtl::OString * rttiName)
317cdf0e10cSrcweir {
318cdf0e10cSrcweir OSL_ASSERT(cppName != NULL && rttiName != NULL);
319cdf0e10cSrcweir rtl::OStringBuffer bc;
320cdf0e10cSrcweir rtl::OStringBuffer br;
321cdf0e10cSrcweir br.append("__1n");
322cdf0e10cSrcweir for (sal_Int32 i = 0; i != -1;) {
323cdf0e10cSrcweir rtl::OUString tok(unoName.getToken(0, '.', i));
324cdf0e10cSrcweir bc.append(rtl::OUStringToOString(tok, RTL_TEXTENCODING_UTF8));
325cdf0e10cSrcweir // conversion should never fail, as tok should be well-formed ASCII
326cdf0e10cSrcweir if (i != -1) {
327cdf0e10cSrcweir bc.append("::");
328cdf0e10cSrcweir }
329cdf0e10cSrcweir sal_Int32 len = tok.getLength();
330cdf0e10cSrcweir sal_Int32 pos = br.getLength();
331cdf0e10cSrcweir for (sal_Int32 n = len / 26; n > 0; n /= 26) {
332cdf0e10cSrcweir br.insert(pos, static_cast< char >('a' + (n % 26)));
333cdf0e10cSrcweir }
334cdf0e10cSrcweir br.append(static_cast< char >('A' + (len % 26)));
335cdf0e10cSrcweir for (sal_Int32 j = 0; j < len; ++j) {
336cdf0e10cSrcweir sal_Unicode c = tok[j];
337cdf0e10cSrcweir OSL_ASSERT(
338cdf0e10cSrcweir c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c == '_' ||
339cdf0e10cSrcweir c >= 'a' && c <= 'z');
340cdf0e10cSrcweir if (c == 'Q') {
341cdf0e10cSrcweir br.append("QdD");
342cdf0e10cSrcweir } else {
343cdf0e10cSrcweir br.append(static_cast< char >(c));
344cdf0e10cSrcweir }
345cdf0e10cSrcweir }
346cdf0e10cSrcweir }
347cdf0e10cSrcweir br.append('_');
348cdf0e10cSrcweir *cppName = bc.makeStringAndClear();
349cdf0e10cSrcweir *rttiName = br.makeStringAndClear();
350cdf0e10cSrcweir }
351cdf0e10cSrcweir
get_(typelib_CompoundTypeDescription const * type)352cdf0e10cSrcweir RttiMap::Data const & RttiMap::get_(
353cdf0e10cSrcweir typelib_CompoundTypeDescription const * type)
354cdf0e10cSrcweir {
355cdf0e10cSrcweir rtl::OUString name(type->aBase.pTypeName);
356cdf0e10cSrcweir Map::iterator it(m_map->find(name));
357cdf0e10cSrcweir if (it == m_map->end()) {
358cdf0e10cSrcweir it = m_map->insert(std::make_pair(name, Data())).first;
359cdf0e10cSrcweir Data & data = it->second;
360cdf0e10cSrcweir rtl::OString rttiName;
361cdf0e10cSrcweir toCppNames(name, &data.cppName, &rttiName);
362cdf0e10cSrcweir data.info = new __Crun::static_type_info;
363cdf0e10cSrcweir data.info->ty_name = data.cppName.getStr() -
364cdf0e10cSrcweir reinterpret_cast< char * >(&data.info->ty_name);
365cdf0e10cSrcweir data.info->reserved = 0;
366cdf0e10cSrcweir NistHash hash(rttiName);
367cdf0e10cSrcweir data.info->type_hash[0] = hash.hashdata[0];
368cdf0e10cSrcweir data.info->type_hash[1] = hash.hashdata[1];
369cdf0e10cSrcweir data.info->type_hash[2] = hash.hashdata[2];
370cdf0e10cSrcweir data.info->type_hash[3] = hash.hashdata[3];
371cdf0e10cSrcweir data.info->flags = 0;
372cdf0e10cSrcweir data.info->cv_qualifiers = 0;
373cdf0e10cSrcweir if (type->pBaseTypeDescription != NULL) {
374cdf0e10cSrcweir data.bases = get_(type->pBaseTypeDescription).bases;
375cdf0e10cSrcweir OSL_ASSERT(!data.bases.empty());
376cdf0e10cSrcweir data.bases.back().offset = 0;
377cdf0e10cSrcweir }
378cdf0e10cSrcweir __Crun::class_base_descr last;
379cdf0e10cSrcweir last.type_hash[0] = data.info->type_hash[0];
380cdf0e10cSrcweir last.type_hash[1] = data.info->type_hash[1];
381cdf0e10cSrcweir last.type_hash[2] = data.info->type_hash[2];
382cdf0e10cSrcweir last.type_hash[3] = data.info->type_hash[3];
383cdf0e10cSrcweir last.offset = 0x8000000000000000;
384cdf0e10cSrcweir data.bases.push_back(last);
385cdf0e10cSrcweir data.info->base_table = reinterpret_cast< char * >(&data.bases[0]) -
386cdf0e10cSrcweir reinterpret_cast< char * >(&data.info->base_table);
387cdf0e10cSrcweir }
388cdf0e10cSrcweir return it->second;
389cdf0e10cSrcweir }
390cdf0e10cSrcweir
deleteException(void * exception,unsigned int * thunk,typelib_TypeDescription * type)391cdf0e10cSrcweir void deleteException(
392cdf0e10cSrcweir void * exception, unsigned int * thunk, typelib_TypeDescription * type)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir uno_destructData(
395cdf0e10cSrcweir exception, type,
396cdf0e10cSrcweir reinterpret_cast< uno_ReleaseFunc >(css::uno::cpp_release));
397cdf0e10cSrcweir typelib_typedescription_release(type);
398cdf0e10cSrcweir delete[] thunk;
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
401cdf0e10cSrcweir }
402cdf0e10cSrcweir
403cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace cc5_solaris_sparc64 {
404cdf0e10cSrcweir
raiseException(uno_Any * exception,uno_Mapping * unoToCpp)405cdf0e10cSrcweir void raiseException(uno_Any * exception, uno_Mapping * unoToCpp) {
406cdf0e10cSrcweir bridges::cpp_uno::shared::ArrayPointer< unsigned long > thunkPtr(
407cdf0e10cSrcweir new unsigned long[4]);
408cdf0e10cSrcweir typelib_TypeDescription * type = NULL;
409cdf0e10cSrcweir typelib_typedescriptionreference_getDescription(&type, exception->pType);
410cdf0e10cSrcweir __Crun::static_type_info const * rtti = RttiMap::get(
411cdf0e10cSrcweir reinterpret_cast< typelib_CompoundTypeDescription * >(type));
412cdf0e10cSrcweir void * exc = __Crun::ex_alloc(type->nSize);
413cdf0e10cSrcweir uno_copyAndConvertData(exc, exception->pData, type, unoToCpp);
414cdf0e10cSrcweir uno_any_destruct(exception, NULL);
415cdf0e10cSrcweir unsigned long * thunk = thunkPtr.release();
416cdf0e10cSrcweir // 0*4: rd %pc, %o1:
417cdf0e10cSrcweir // 1*4: ldx %o1, (6-0)*4, %o3:
418cdf0e10cSrcweir thunk[0] = 0x93414000D65A6018;
419cdf0e10cSrcweir // 2*4: jmpl %o3, %g0, %g0:
420cdf0e10cSrcweir // 3*4: ldx %o1, (4-0)*4, %o2:
421cdf0e10cSrcweir thunk[1] = 0x81C2C000D45A6010;
422cdf0e10cSrcweir // 4*4: .xword type:
423cdf0e10cSrcweir thunk[2] = reinterpret_cast< unsigned long >(type);
424cdf0e10cSrcweir // 6*4: .xword deleteException:
425cdf0e10cSrcweir thunk[3] = reinterpret_cast< unsigned long >(deleteException);
426cdf0e10cSrcweir flushCode(thunk, thunk + 4);
427cdf0e10cSrcweir __Crun::ex_throw(exc, rtti, toFunction(thunk));
428cdf0e10cSrcweir }
429cdf0e10cSrcweir
fillUnoException(void * cppException,char const * cppName,uno_Any * unoException,uno_Mapping * cppToUno)430cdf0e10cSrcweir void fillUnoException(
431cdf0e10cSrcweir void * cppException, char const * cppName, uno_Any * unoException,
432cdf0e10cSrcweir uno_Mapping * cppToUno)
433cdf0e10cSrcweir {
434cdf0e10cSrcweir rtl::OUString name;
435cdf0e10cSrcweir typelib_TypeDescription * type = NULL;
436cdf0e10cSrcweir if (toUnoName(cppName, &name)) {
437cdf0e10cSrcweir typelib_typedescription_getByName(&type, name.pData);
438cdf0e10cSrcweir }
439cdf0e10cSrcweir if (type == NULL || type->eTypeClass != typelib_TypeClass_EXCEPTION) {
440cdf0e10cSrcweir css::uno::RuntimeException exc(
441cdf0e10cSrcweir (rtl::OUString(
442cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("Not a UNO exception type: ")) +
443cdf0e10cSrcweir name),
444cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >());
445cdf0e10cSrcweir uno_type_any_constructAndConvert(
446cdf0e10cSrcweir unoException, &exc, getCppuType(&exc).getTypeLibType(), cppToUno);
447cdf0e10cSrcweir } else {
448cdf0e10cSrcweir uno_any_constructAndConvert(unoException, cppException, type, cppToUno);
449cdf0e10cSrcweir }
450cdf0e10cSrcweir if (type != NULL) {
451cdf0e10cSrcweir typelib_typedescription_release(type);
452cdf0e10cSrcweir }
453cdf0e10cSrcweir }
454cdf0e10cSrcweir
455cdf0e10cSrcweir } } }
456