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 10444 : 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 10444 : m_sequenceDependency(false)
54 : {
55 10444 : typereg::Reader reader(manager.getTypeReader(type));
56 10444 : m_valid = reader.isValid();
57 10444 : if (m_valid) {
58 : // Not everything is checked for consistency, just things that are cheap
59 : // to test:
60 : try {
61 10444 : RTTypeClass tc = reader.getTypeClass();
62 10444 : if (tc != RT_TYPE_SERVICE) {
63 12745 : for (sal_Int16 i = 0; i < reader.getSuperTypeCount(); ++i) {
64 5121 : insert(reader.getSuperTypeName(i), true);
65 : }
66 : }
67 10444 : if (tc != RT_TYPE_ENUM) {
68 36232 : {for (sal_Int16 i = 0; i < reader.getFieldCount(); ++i) {
69 26185 : if ((reader.getFieldFlags(i) & RT_ACCESS_PARAMETERIZED_TYPE)
70 : == 0)
71 : {
72 26166 : insert(reader.getFieldTypeName(i), false);
73 : }
74 : }}
75 : }
76 23866 : for (sal_Int16 i = 0; i < reader.getMethodCount(); ++i) {
77 13422 : insert(reader.getMethodReturnTypeName(i), false);
78 27026 : for (sal_Int16 j = 0; j < reader.getMethodParameterCount(i);
79 : ++j)
80 : {
81 13604 : if ((reader.getMethodParameterFlags(i, j) & RT_PARAM_REST)
82 : != 0)
83 : {
84 2 : m_sequenceDependency = true;
85 : }
86 13604 : insert(reader.getMethodParameterTypeName(i, j), false);
87 : }
88 19867 : for (sal_Int16 j = 0; j < reader.getMethodExceptionCount(i);
89 : ++j)
90 : {
91 6445 : insert(reader.getMethodExceptionTypeName(i, j), false);
92 : }
93 : }
94 16100 : for (sal_Int16 i = 0; i < reader.getReferenceCount(); ++i) {
95 5656 : if (reader.getReferenceSort(i) != RT_REF_TYPE_PARAMETER) {
96 5635 : 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 10444 : }
120 10444 : }
121 :
122 10444 : Dependencies::~Dependencies()
123 10444 : {}
124 :
125 70393 : void Dependencies::insert(rtl::OUString const & type, bool base) {
126 70393 : rtl::OString t;
127 70393 : if (!type.convertToString(
128 : &t, RTL_TEXTENCODING_UTF8,
129 : (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
130 70393 : | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR)))
131 : {
132 0 : throw Bad();
133 : }
134 70393 : insert(t, base);
135 70393 : }
136 :
137 74699 : void Dependencies::insert(rtl::OString const & type, bool base) {
138 : sal_Int32 rank;
139 74699 : std::vector< rtl::OString > args;
140 74699 : rtl::OString t(UnoType::decompose(type, &rank, &args));
141 74699 : if (rank > 0) {
142 2528 : m_sequenceDependency = true;
143 : }
144 74699 : switch (UnoType::getSort(t)) {
145 : case UnoType::SORT_VOID:
146 6115 : if (rank != 0 || !args.empty()) {
147 0 : throw Bad();
148 : }
149 6115 : m_voidDependency = true;
150 6115 : break;
151 :
152 : case UnoType::SORT_BOOLEAN:
153 4420 : if (!args.empty()) {
154 0 : throw Bad();
155 : }
156 4420 : m_booleanDependency = true;
157 4420 : break;
158 :
159 : case UnoType::SORT_BYTE:
160 892 : if (!args.empty()) {
161 0 : throw Bad();
162 : }
163 892 : m_byteDependency = true;
164 892 : break;
165 :
166 : case UnoType::SORT_SHORT:
167 6062 : if (!args.empty()) {
168 0 : throw Bad();
169 : }
170 6062 : m_shortDependency = true;
171 6062 : break;
172 :
173 : case UnoType::SORT_UNSIGNED_SHORT:
174 102 : if (!args.empty()) {
175 0 : throw Bad();
176 : }
177 102 : m_unsignedShortDependency = true;
178 102 : break;
179 :
180 : case UnoType::SORT_LONG:
181 14928 : if (!args.empty()) {
182 0 : throw Bad();
183 : }
184 14928 : m_longDependency = true;
185 14928 : break;
186 :
187 : case UnoType::SORT_UNSIGNED_LONG:
188 80 : if (!args.empty()) {
189 0 : throw Bad();
190 : }
191 80 : m_unsignedLongDependency = true;
192 80 : break;
193 :
194 : case UnoType::SORT_HYPER:
195 224 : if (!args.empty()) {
196 0 : throw Bad();
197 : }
198 224 : m_hyperDependency = true;
199 224 : break;
200 :
201 : case UnoType::SORT_UNSIGNED_HYPER:
202 20 : if (!args.empty()) {
203 0 : throw Bad();
204 : }
205 20 : m_unsignedHyperDependency = true;
206 20 : break;
207 :
208 : case UnoType::SORT_FLOAT:
209 194 : if (!args.empty()) {
210 0 : throw Bad();
211 : }
212 194 : m_floatDependency = true;
213 194 : break;
214 :
215 : case UnoType::SORT_DOUBLE:
216 865 : if (!args.empty()) {
217 0 : throw Bad();
218 : }
219 865 : m_doubleDependency = true;
220 865 : break;
221 :
222 : case UnoType::SORT_CHAR:
223 89 : if (!args.empty()) {
224 0 : throw Bad();
225 : }
226 89 : m_charDependency = true;
227 89 : break;
228 :
229 : case UnoType::SORT_STRING:
230 6897 : if (!args.empty()) {
231 0 : throw Bad();
232 : }
233 6897 : m_stringDependency = true;
234 6897 : break;
235 :
236 : case UnoType::SORT_TYPE:
237 116 : if (!args.empty()) {
238 0 : throw Bad();
239 : }
240 116 : m_typeDependency = true;
241 116 : break;
242 :
243 : case UnoType::SORT_ANY:
244 2049 : if (!args.empty()) {
245 0 : throw Bad();
246 : }
247 2049 : m_anyDependency = true;
248 2049 : break;
249 :
250 : case UnoType::SORT_COMPLEX:
251 : {
252 95448 : {for (std::vector< rtl::OString >::iterator i(args.begin());
253 63632 : i != args.end(); ++i)
254 : {
255 170 : insert(*i, false);
256 : }}
257 31646 : Map::iterator i(m_map.find(t));
258 31646 : if (i == m_map.end()) {
259 : m_map.insert(
260 23273 : Map::value_type(t, base ? KIND_BASE : KIND_NO_BASE));
261 8373 : } else if (base) {
262 0 : i->second = KIND_BASE;
263 : }
264 : break;
265 : }
266 :
267 : default:
268 : OSL_ASSERT(false);
269 0 : break;
270 74699 : }
271 74699 : }
272 :
273 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|