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 "codemaker/dependencies.hxx"
22 : :
23 : : #include "codemaker/typemanager.hxx"
24 : : #include "codemaker/unotype.hxx"
25 : :
26 : : #include "osl/diagnose.h"
27 : : #include "registry/reader.hxx"
28 : : #include "rtl/string.hxx"
29 : : #include "rtl/textcvt.h"
30 : : #include "rtl/textenc.h"
31 : : #include "rtl/ustring.hxx"
32 : : #include "sal/types.h"
33 : :
34 : : #include <vector>
35 : :
36 : : using codemaker::Dependencies;
37 : :
38 : : namespace {
39 : :
40 : : struct Bad {};
41 : :
42 : : }
43 : :
44 : 20754 : Dependencies::Dependencies(
45 : : TypeManager const & manager, rtl::OString const & type):
46 : : m_voidDependency(false), m_booleanDependency(false),
47 : : m_byteDependency(false), m_shortDependency(false),
48 : : m_unsignedShortDependency(false), m_longDependency(false),
49 : : m_unsignedLongDependency(false), m_hyperDependency(false),
50 : : m_unsignedHyperDependency(false), m_floatDependency(false),
51 : : m_doubleDependency(false), m_charDependency(false),
52 : : m_stringDependency(false), m_typeDependency(false), m_anyDependency(false),
53 [ + - ]: 20754 : m_sequenceDependency(false)
54 : : {
55 [ + - ]: 20754 : typereg::Reader reader(manager.getTypeReader(type));
56 : 20754 : m_valid = reader.isValid();
57 [ + - ]: 20754 : if (m_valid) {
58 : : // Not everything is checked for consistency, just things that are cheap
59 : : // to test:
60 : : try {
61 : 20754 : RTTypeClass tc = reader.getTypeClass();
62 [ + + ]: 20754 : if (tc != RT_TYPE_SERVICE) {
63 [ + + ]: 25006 : for (sal_Int16 i = 0; i < reader.getSuperTypeCount(); ++i) {
64 [ + - ][ + - ]: 9810 : insert(reader.getSuperTypeName(i), true);
65 : : }
66 : : }
67 [ + + ]: 20754 : if (tc != RT_TYPE_ENUM) {
68 [ + + ]: 73492 : {for (sal_Int16 i = 0; i < reader.getFieldCount(); ++i) {
69 [ + + ]: 53570 : if ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE)
70 : : == 0)
71 : : {
72 [ + - ][ + - ]: 53542 : insert(reader.getFieldTypeName(i), false);
73 : : }
74 : : }}
75 : : }
76 [ + + ]: 47136 : for (sal_Int16 i = 0; i < reader.getMethodCount(); ++i) {
77 [ + - ][ + - ]: 26382 : insert(reader.getMethodReturnTypeName(i), false);
78 [ + + ]: 53620 : for (sal_Int16 j = 0; j < reader.getMethodParameterCount(i);
79 : : ++j)
80 : : {
81 [ + + ]: 27238 : if ((reader.getMethodParameterFlags(i, j) & RT_PARAM_REST)
82 : : != 0)
83 : : {
84 : 4 : m_sequenceDependency = true;
85 : : }
86 [ + - ][ + - ]: 27238 : insert(reader.getMethodParameterTypeName(i, j), false);
87 : : }
88 [ + + ]: 38730 : for (sal_Int16 j = 0; j < reader.getMethodExceptionCount(i);
89 : : ++j)
90 : : {
91 [ + - ][ + - ]: 12348 : insert(reader.getMethodExceptionTypeName(i, j), false);
92 : : }
93 : : }
94 [ + + ]: 32526 : for (sal_Int16 i = 0; i < reader.getReferenceCount(); ++i) {
95 [ + + ]: 11772 : if (reader.getReferenceSort(i) != RT_REF_TYPE_PARAMETER) {
96 [ + - ][ + - ]: 11740 : insert(reader.getReferenceTypeName(i), false);
97 : : }
98 : : }
99 [ # # ]: 0 : } catch (Bad &) {
100 [ # # ]: 0 : m_map.clear();
101 : 0 : m_valid = false;
102 : 0 : m_voidDependency = false;
103 : 0 : m_booleanDependency = false;
104 : 0 : m_byteDependency = false;
105 : 0 : m_shortDependency = false;
106 : 0 : m_unsignedShortDependency = false;
107 : 0 : m_longDependency = false;
108 : 0 : m_unsignedLongDependency = false;
109 : 0 : m_hyperDependency = false;
110 : 0 : m_unsignedHyperDependency = false;
111 : 0 : m_floatDependency = false;
112 : 0 : m_doubleDependency = false;
113 : 0 : m_charDependency = false;
114 : 0 : m_stringDependency = false;
115 : 0 : m_typeDependency = false;
116 : 0 : m_anyDependency = false;
117 : 0 : m_sequenceDependency = false;
118 : : }
119 : 20754 : }
120 : 20754 : }
121 : :
122 : 20754 : Dependencies::~Dependencies()
123 : 20754 : {}
124 : :
125 : 141060 : void Dependencies::insert(rtl::OUString const & type, bool base) {
126 : 141060 : rtl::OString t;
127 [ - + ]: 141060 : if (!type.convertToString(
128 : : &t, RTL_TEXTENCODING_UTF8,
129 : : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
130 : 141060 : | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
131 : : {
132 : 0 : throw Bad();
133 : : }
134 [ + - ]: 141060 : insert(t, base);
135 : 141060 : }
136 : :
137 : 149228 : void Dependencies::insert(rtl::OString const & type, bool base) {
138 : : sal_Int32 rank;
139 [ + - ]: 149228 : std::vector< rtl::OString > args;
140 [ + - ]: 149228 : rtl::OString t(UnoType::decompose(type, &rank, &args));
141 [ + + ]: 149228 : if (rank > 0) {
142 : 5296 : m_sequenceDependency = true;
143 : : }
144 [ + - ][ + + : 149228 : switch (UnoType::getSort(t)) {
+ + + + +
+ + + + +
+ + + +
- ]
145 : : case UnoType::SORT_VOID:
146 [ + - ][ - + ]: 11828 : if (rank != 0 || !args.empty()) {
[ - + ]
147 : 0 : throw Bad();
148 : : }
149 : 11828 : m_voidDependency = true;
150 : 11828 : break;
151 : :
152 : : case UnoType::SORT_BOOLEAN:
153 [ - + ]: 9014 : if (!args.empty()) {
154 : 0 : throw Bad();
155 : : }
156 : 9014 : m_booleanDependency = true;
157 : 9014 : break;
158 : :
159 : : case UnoType::SORT_BYTE:
160 [ - + ]: 1928 : if (!args.empty()) {
161 : 0 : throw Bad();
162 : : }
163 : 1928 : m_byteDependency = true;
164 : 1928 : break;
165 : :
166 : : case UnoType::SORT_SHORT:
167 [ - + ]: 12266 : if (!args.empty()) {
168 : 0 : throw Bad();
169 : : }
170 : 12266 : m_shortDependency = true;
171 : 12266 : break;
172 : :
173 : : case UnoType::SORT_UNSIGNED_SHORT:
174 [ - + ]: 254 : if (!args.empty()) {
175 : 0 : throw Bad();
176 : : }
177 : 254 : m_unsignedShortDependency = true;
178 : 254 : break;
179 : :
180 : : case UnoType::SORT_LONG:
181 [ - + ]: 29902 : if (!args.empty()) {
182 : 0 : throw Bad();
183 : : }
184 : 29902 : m_longDependency = true;
185 : 29902 : break;
186 : :
187 : : case UnoType::SORT_UNSIGNED_LONG:
188 [ - + ]: 408 : if (!args.empty()) {
189 : 0 : throw Bad();
190 : : }
191 : 408 : m_unsignedLongDependency = true;
192 : 408 : break;
193 : :
194 : : case UnoType::SORT_HYPER:
195 [ - + ]: 480 : if (!args.empty()) {
196 : 0 : throw Bad();
197 : : }
198 : 480 : m_hyperDependency = true;
199 : 480 : break;
200 : :
201 : : case UnoType::SORT_UNSIGNED_HYPER:
202 [ - + ]: 78 : if (!args.empty()) {
203 : 0 : throw Bad();
204 : : }
205 : 78 : m_unsignedHyperDependency = true;
206 : 78 : break;
207 : :
208 : : case UnoType::SORT_FLOAT:
209 [ - + ]: 428 : if (!args.empty()) {
210 : 0 : throw Bad();
211 : : }
212 : 428 : m_floatDependency = true;
213 : 428 : break;
214 : :
215 : : case UnoType::SORT_DOUBLE:
216 [ - + ]: 1716 : if (!args.empty()) {
217 : 0 : throw Bad();
218 : : }
219 : 1716 : m_doubleDependency = true;
220 : 1716 : break;
221 : :
222 : : case UnoType::SORT_CHAR:
223 [ - + ]: 210 : if (!args.empty()) {
224 : 0 : throw Bad();
225 : : }
226 : 210 : m_charDependency = true;
227 : 210 : break;
228 : :
229 : : case UnoType::SORT_STRING:
230 [ - + ]: 13974 : if (!args.empty()) {
231 : 0 : throw Bad();
232 : : }
233 : 13974 : m_stringDependency = true;
234 : 13974 : break;
235 : :
236 : : case UnoType::SORT_TYPE:
237 [ - + ]: 194 : if (!args.empty()) {
238 : 0 : throw Bad();
239 : : }
240 : 194 : m_typeDependency = true;
241 : 194 : break;
242 : :
243 : : case UnoType::SORT_ANY:
244 [ - + ]: 4010 : if (!args.empty()) {
245 : 0 : throw Bad();
246 : : }
247 : 4010 : m_anyDependency = true;
248 : 4010 : break;
249 : :
250 : : case UnoType::SORT_COMPLEX:
251 : : {
252 [ + - ][ + + ]: 125748 : {for (std::vector< rtl::OString >::iterator i(args.begin());
253 : 62874 : i != args.end(); ++i)
254 : : {
255 [ + - ]: 336 : insert(*i, false);
256 : : }}
257 [ + - ]: 62538 : Map::iterator i(m_map.find(t));
258 [ + - ][ + + ]: 62538 : if (i == m_map.end()) {
259 : : m_map.insert(
260 [ + + ][ + - ]: 45920 : Map::value_type(t, base ? KIND_BASE : KIND_NO_BASE));
261 [ - + ]: 16618 : } else if (base) {
262 [ # # ]: 62538 : i->second = KIND_BASE;
263 : : }
264 : : break;
265 : : }
266 : :
267 : : default:
268 : : OSL_ASSERT(false);
269 : 0 : break;
270 : 149228 : }
271 : 149228 : }
272 : :
273 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|