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 : #include "sal/config.h"
21 :
22 : #include <cassert>
23 : #include <utility>
24 : #include <vector>
25 :
26 : #include "codemaker/global.hxx"
27 : #include "codemaker/typemanager.hxx"
28 : #include "codemaker/unotype.hxx"
29 :
30 : #include "osl/diagnose.h"
31 : #include "rtl/ref.hxx"
32 : #include "rtl/string.hxx"
33 : #include "rtl/ustring.hxx"
34 : #include "sal/types.h"
35 : #include "unoidl/unoidl.hxx"
36 :
37 : #include "dependencies.hxx"
38 :
39 : namespace codemaker { namespace cppumaker {
40 :
41 0 : Dependencies::Dependencies(
42 : rtl::Reference< TypeManager > const & manager, OUString const & name):
43 : m_manager(manager), m_voidDependency(false), m_booleanDependency(false),
44 : m_byteDependency(false), m_shortDependency(false),
45 : m_unsignedShortDependency(false), m_longDependency(false),
46 : m_unsignedLongDependency(false), m_hyperDependency(false),
47 : m_unsignedHyperDependency(false), m_floatDependency(false),
48 : m_doubleDependency(false), m_charDependency(false),
49 : m_stringDependency(false), m_typeDependency(false), m_anyDependency(false),
50 0 : m_sequenceDependency(false)
51 : {
52 : assert(manager.is());
53 0 : rtl::Reference< unoidl::Entity > ent;
54 0 : switch (m_manager->getSort(name, &ent)) {
55 : case UnoType::SORT_ENUM_TYPE:
56 0 : break;
57 : case UnoType::SORT_PLAIN_STRUCT_TYPE:
58 : {
59 : rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
60 0 : static_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
61 0 : if (!ent2->getDirectBase().isEmpty()) {
62 0 : insert(ent2->getDirectBase());
63 : }
64 0 : for (std::vector< unoidl::PlainStructTypeEntity::Member >::
65 0 : const_iterator i(ent2->getDirectMembers().begin());
66 0 : i != ent2->getDirectMembers().end(); ++i)
67 : {
68 0 : insert(i->type);
69 : }
70 0 : break;
71 : }
72 : case UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
73 : {
74 : rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
75 : static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
76 0 : ent.get()));
77 0 : for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::
78 0 : Member >::const_iterator i(ent2->getMembers().begin());
79 0 : i != ent2->getMembers().end(); ++i)
80 : {
81 0 : if (!i->parameterized) {
82 0 : insert(i->type);
83 : }
84 : }
85 0 : break;
86 : }
87 : case UnoType::SORT_EXCEPTION_TYPE:
88 : {
89 : rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
90 0 : static_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
91 0 : if (!ent2->getDirectBase().isEmpty()) {
92 0 : insert(ent2->getDirectBase());
93 : }
94 0 : for (std::vector< unoidl::ExceptionTypeEntity::Member >::
95 0 : const_iterator i(ent2->getDirectMembers().begin());
96 0 : i != ent2->getDirectMembers().end(); ++i)
97 : {
98 0 : insert(i->type);
99 : }
100 0 : break;
101 : }
102 : case UnoType::SORT_INTERFACE_TYPE:
103 : {
104 : rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
105 0 : static_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
106 0 : for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
107 0 : ent2->getDirectMandatoryBases().begin());
108 0 : i != ent2->getDirectMandatoryBases().end(); ++i)
109 : {
110 0 : insert(i->name, true);
111 : }
112 0 : if (!(ent2->getDirectAttributes().empty()
113 0 : && ent2->getDirectMethods().empty()))
114 : {
115 0 : insert("com.sun.star.uno.RuntimeException");
116 : }
117 0 : for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::
118 0 : const_iterator i(ent2->getDirectAttributes().begin());
119 0 : i != ent2->getDirectAttributes().end(); ++i)
120 : {
121 0 : insert(i->type);
122 0 : for (std::vector< OUString >::const_iterator j(
123 0 : i->getExceptions.begin());
124 0 : j != i->getExceptions.end(); ++j)
125 : {
126 0 : insert(*j);
127 : }
128 0 : for (std::vector< OUString >::const_iterator j(
129 0 : i->setExceptions.begin());
130 0 : j != i->setExceptions.end(); ++j)
131 : {
132 0 : insert(*j);
133 : }
134 : }
135 0 : for (std::vector< unoidl::InterfaceTypeEntity::Method >::
136 0 : const_iterator i(ent2->getDirectMethods().begin());
137 0 : i != ent2->getDirectMethods().end(); ++i)
138 : {
139 0 : insert(i->returnType);
140 0 : for (std::vector<
141 : unoidl::InterfaceTypeEntity::Method::Parameter >::
142 0 : const_iterator j(i->parameters.begin());
143 0 : j != i->parameters.end(); ++j)
144 : {
145 0 : insert(j->type);
146 : }
147 0 : for (std::vector< OUString >::const_iterator j(
148 0 : i->exceptions.begin());
149 0 : j != i->exceptions.end(); ++j)
150 : {
151 0 : insert(*j);
152 : }
153 : }
154 0 : break;
155 : }
156 : case UnoType::SORT_TYPEDEF:
157 0 : insert(static_cast< unoidl::TypedefEntity * >(ent.get())->getType());
158 0 : break;
159 : case UnoType::SORT_CONSTANT_GROUP:
160 : {
161 : rtl::Reference< unoidl::ConstantGroupEntity > ent2(
162 0 : static_cast< unoidl::ConstantGroupEntity * >(ent.get()));
163 0 : for (std::vector< unoidl::ConstantGroupEntity::Member >::
164 0 : const_iterator i(ent2->getMembers().begin());
165 0 : i != ent2->getMembers().end(); ++i)
166 : {
167 0 : switch (i->value.type) {
168 : case unoidl::ConstantValue::TYPE_BOOLEAN:
169 0 : m_booleanDependency = true;
170 0 : break;
171 : case unoidl::ConstantValue::TYPE_BYTE:
172 0 : m_byteDependency = true;
173 0 : break;
174 : case unoidl::ConstantValue::TYPE_SHORT:
175 0 : m_shortDependency = true;
176 0 : break;
177 : case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
178 0 : m_unsignedShortDependency = true;
179 0 : break;
180 : case unoidl::ConstantValue::TYPE_LONG:
181 0 : m_longDependency = true;
182 0 : break;
183 : case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
184 0 : m_unsignedLongDependency = true;
185 0 : break;
186 : case unoidl::ConstantValue::TYPE_HYPER:
187 0 : m_hyperDependency = true;
188 0 : break;
189 : case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
190 0 : m_unsignedHyperDependency = true;
191 0 : break;
192 : case unoidl::ConstantValue::TYPE_FLOAT:
193 0 : m_floatDependency = true;
194 0 : break;
195 : case unoidl::ConstantValue::TYPE_DOUBLE:
196 0 : m_doubleDependency = true;
197 0 : break;
198 : }
199 : }
200 0 : break;
201 : }
202 : case UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
203 : {
204 : rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
205 : static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
206 0 : ent.get()));
207 0 : if (!ent2->getConstructors().empty()) {
208 0 : insert(ent2->getBase());
209 : }
210 0 : for (std::vector<
211 : unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
212 0 : const_iterator i(ent2->getConstructors().begin());
213 0 : i != ent2->getConstructors().end(); ++i)
214 : {
215 0 : for (std::vector<
216 : unoidl::SingleInterfaceBasedServiceEntity::
217 : Constructor::Parameter >::const_iterator j(
218 0 : i->parameters.begin());
219 0 : j != i->parameters.end(); ++j)
220 : {
221 0 : insert(j->type);
222 0 : if (j->rest) {
223 0 : m_sequenceDependency = true;
224 : }
225 : }
226 0 : for (std::vector< OUString >::const_iterator j(
227 0 : i->exceptions.begin());
228 0 : j != i->exceptions.end(); ++j)
229 : {
230 0 : insert(*j);
231 : }
232 : }
233 0 : break;
234 : }
235 : case UnoType::SORT_INTERFACE_BASED_SINGLETON:
236 : insert(
237 0 : static_cast< unoidl::InterfaceBasedSingletonEntity * >(ent.get())->
238 0 : getBase());
239 0 : break;
240 : default:
241 : assert(false); // this cannot happen
242 0 : }
243 0 : }
244 :
245 0 : Dependencies::~Dependencies() {}
246 :
247 0 : void Dependencies::insert(OUString const & name, bool base) {
248 : sal_Int32 k;
249 0 : std::vector< OString > args;
250 0 : OUString n(b2u(UnoType::decompose(u2b(name), &k, &args)));
251 0 : if (k != 0) {
252 0 : m_sequenceDependency = true;
253 : }
254 0 : switch (m_manager->getSort(n)) {
255 : case UnoType::SORT_VOID:
256 0 : m_voidDependency = true;
257 0 : break;
258 : case UnoType::SORT_BOOLEAN:
259 0 : m_booleanDependency = true;
260 0 : break;
261 : case UnoType::SORT_BYTE:
262 0 : m_byteDependency = true;
263 0 : break;
264 : case UnoType::SORT_SHORT:
265 0 : m_shortDependency = true;
266 0 : break;
267 : case UnoType::SORT_UNSIGNED_SHORT:
268 0 : m_unsignedShortDependency = true;
269 0 : break;
270 : case UnoType::SORT_LONG:
271 0 : m_longDependency = true;
272 0 : break;
273 : case UnoType::SORT_UNSIGNED_LONG:
274 0 : m_unsignedLongDependency = true;
275 0 : break;
276 : case UnoType::SORT_HYPER:
277 0 : m_hyperDependency = true;
278 0 : break;
279 : case UnoType::SORT_UNSIGNED_HYPER:
280 0 : m_unsignedHyperDependency = true;
281 0 : break;
282 : case UnoType::SORT_FLOAT:
283 0 : m_floatDependency = true;
284 0 : break;
285 : case UnoType::SORT_DOUBLE:
286 0 : m_doubleDependency = true;
287 0 : break;
288 : case UnoType::SORT_CHAR:
289 0 : m_charDependency = true;
290 0 : break;
291 : case UnoType::SORT_STRING:
292 0 : m_stringDependency = true;
293 0 : break;
294 : case UnoType::SORT_TYPE:
295 0 : m_typeDependency = true;
296 0 : break;
297 : case UnoType::SORT_ANY:
298 0 : m_anyDependency = true;
299 0 : break;
300 : case UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
301 0 : for (std::vector< OString >::iterator i(args.begin()); i != args.end();
302 : ++i)
303 : {
304 0 : insert(b2u(*i), false);
305 : }
306 : // fall through
307 : case UnoType::SORT_SEQUENCE_TYPE:
308 : case UnoType::SORT_ENUM_TYPE:
309 : case UnoType::SORT_PLAIN_STRUCT_TYPE:
310 : case UnoType::SORT_EXCEPTION_TYPE:
311 : case UnoType::SORT_INTERFACE_TYPE:
312 : case UnoType::SORT_TYPEDEF:
313 : {
314 : std::pair< Map::iterator, bool > i(
315 : m_map.insert(
316 0 : Map::value_type(n, base ? KIND_BASE : KIND_NO_BASE)));
317 0 : if (!i.second && base) {
318 0 : i.first->second = KIND_BASE;
319 : }
320 0 : break;
321 : }
322 : default:
323 : throw CannotDumpException(
324 0 : "unexpected type \"" + name
325 0 : + "\" in call to codemaker::cppumaker::Dependencies::Dependencies");
326 0 : }
327 0 : }
328 :
329 : } }
330 :
331 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|