Branch data Line data Source code
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 "sal/config.h"
22 : :
23 : : #include "codemaker/codemaker.hxx"
24 : :
25 : : #include "codemaker/options.hxx"
26 : : #include "codemaker/typemanager.hxx"
27 : : #include "codemaker/unotype.hxx"
28 : :
29 : : #include "osl/diagnose.h"
30 : : #include "registry/reader.hxx"
31 : : #include "registry/types.h"
32 : : #include "rtl/strbuf.h"
33 : : #include "rtl/string.h"
34 : : #include "rtl/string.hxx"
35 : : #include "rtl/ustring.hxx"
36 : : #include "sal/types.h"
37 : :
38 : : #include <vector>
39 : :
40 : : namespace {
41 : :
42 : 59245 : void checkNoTypeArguments(std::vector< rtl::OString > const & arguments) {
43 [ - + ]: 59245 : if (!arguments.empty()) {
44 : : throw CannotDumpException(
45 : 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("Bad type information")));
46 : : //TODO
47 : : }
48 : 59245 : }
49 : :
50 : : }
51 : :
52 : : namespace codemaker {
53 : :
54 : 109239 : rtl::OString convertString(rtl::OUString const & string) {
55 : 109239 : rtl::OString s;
56 [ - + ]: 109239 : if (!string.convertToString(
57 : : &s, RTL_TEXTENCODING_UTF8,
58 : : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
59 : 109239 : | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
60 : : {
61 : : throw CannotDumpException(
62 : : rtl::OString(
63 : : RTL_CONSTASCII_STRINGPARAM(
64 : 0 : "Failure converting string from UTF-16 to UTF-8")));
65 : : }
66 : 109239 : return s;
67 : : }
68 : :
69 : 0 : rtl::OString errorMsg(rtl::OString const & desc, rtl::OString const & type) {
70 : 0 : rtl::OStringBuffer msg(128);
71 [ # # ]: 0 : msg.append(desc);
72 [ # # ]: 0 : msg.append(type);
73 : 0 : return msg.makeStringAndClear();
74 : : }
75 : :
76 : 63322 : codemaker::UnoType::Sort decomposeAndResolve(
77 : : TypeManager const & manager, rtl::OString const & type,
78 : : bool resolveTypedefs, bool allowVoid, bool allowExtraEntities,
79 : : RTTypeClass * typeClass, rtl::OString * name, sal_Int32 * rank,
80 : : std::vector< rtl::OString > * arguments)
81 : : {
82 : : OSL_ASSERT(typeClass != 0 && name != 0 && rank != 0 && arguments != 0);
83 : 63322 : *rank = 0;
84 : 127296 : for (rtl::OString t(type);;) {
85 : 63974 : sal_Int32 n = 0;
86 [ + - ]: 63974 : *name = codemaker::UnoType::decompose(t, &n, arguments);
87 [ - + ]: 63974 : if (n > SAL_MAX_INT32 - *rank) {
88 : : throw CannotDumpException(
89 : : errorMsg(rtl::OString(
90 : : RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
91 [ # # ]: 0 : type));
92 : : //TODO
93 : : }
94 : 63974 : *rank += n;
95 [ + + ]: 63974 : if (n > 0) {
96 : 3568 : allowVoid = false;
97 : 3568 : allowExtraEntities = false;
98 : : }
99 [ + - ]: 63974 : codemaker::UnoType::Sort sort = codemaker::UnoType::getSort(*name);
100 [ + + + ]: 63974 : switch (sort) {
101 : : case codemaker::UnoType::SORT_VOID:
102 [ - + ]: 6972 : if (!allowVoid) {
103 : : throw CannotDumpException(
104 : : errorMsg(rtl::OString(
105 : : RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
106 [ # # ]: 0 : type));
107 : : //TODO
108 : : }
109 : : default:
110 [ + - ]: 49232 : checkNoTypeArguments(*arguments);
111 : 49232 : *typeClass = RT_TYPE_INVALID;
112 : 49232 : return sort;
113 : :
114 : : case codemaker::UnoType::SORT_COMPLEX:
115 [ + - ]: 14742 : typereg::Reader reader(manager.getTypeReader(*name));
116 : 14742 : *typeClass = reader.getTypeClass();
117 [ + + - + : 14742 : switch (*typeClass) {
- ]
118 : : case RT_TYPE_ENUM:
119 : : case RT_TYPE_INTERFACE:
120 [ + - ]: 9361 : checkNoTypeArguments(*arguments);
121 : 9361 : return sort;
122 : :
123 : : case RT_TYPE_STRUCT:
124 [ - + ][ # # : 14187 : if (!(allowExtraEntities && arguments->empty())
+ - - + ]
[ - + ]
125 : 4729 : && (arguments->size() > SAL_MAX_UINT16
126 : 4729 : || (static_cast< sal_uInt16 >(arguments->size())
127 : 4729 : != reader.getReferenceCount())))
128 : : {
129 : : throw CannotDumpException(
130 : : errorMsg(rtl::OString(
131 : : RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
132 [ # # ]: 0 : type));
133 : : //TODO
134 : : }
135 : 4729 : return sort;
136 : :
137 : : case RT_TYPE_MODULE:
138 : : case RT_TYPE_EXCEPTION:
139 : : case RT_TYPE_SERVICE:
140 : : case RT_TYPE_SINGLETON:
141 : : case RT_TYPE_CONSTANTS:
142 [ # # ]: 0 : if (!allowExtraEntities) {
143 : : throw CannotDumpException(
144 : : errorMsg(rtl::OString(
145 : : RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
146 [ # # ]: 0 : type));
147 : : //TODO
148 : : }
149 [ # # ]: 0 : checkNoTypeArguments(*arguments);
150 : : //TODO: check reader for consistency
151 : 0 : return sort;
152 : :
153 : : case RT_TYPE_TYPEDEF:
154 [ + - ]: 652 : checkNoTypeArguments(*arguments);
155 [ + - + - : 2608 : if (reader.getSuperTypeCount() == 1
+ - + - ]
[ + - ]
156 : 652 : && reader.getFieldCount() == 0
157 : 652 : && reader.getMethodCount() == 0
158 : 652 : && reader.getReferenceCount() == 0)
159 : : {
160 [ + - ]: 652 : if (resolveTypedefs) {
161 [ + - ][ + - ]: 652 : t = convertString(reader.getSuperTypeName(0));
162 : 652 : continue;
163 : : } else {
164 : 0 : return sort;
165 : : }
166 : : }
167 : : default:
168 : : throw CannotDumpException(
169 : : errorMsg(rtl::OString(
170 : : RTL_CONSTASCII_STRINGPARAM("Bad type information: ")),
171 [ # # ][ + + ]: 14742 : type));
172 : : //TODO
173 : 14742 : }
174 : : }
175 : 63322 : }
176 : : }
177 : :
178 : : }
179 : :
180 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|