1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
26 #include "codemaker/global.hxx"
27 #include "codemaker/typemanager.hxx"
28 #include "codemaker/unotype.hxx"
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"
37 #include "dependencies.hxx"
39 namespace codemaker
{ namespace cppumaker
{
41 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 m_sequenceDependency(false)
53 rtl::Reference
< unoidl::Entity
> ent
;
54 switch (m_manager
->getSort(name
, &ent
)) {
55 case UnoType::SORT_ENUM_TYPE
:
57 case UnoType::SORT_PLAIN_STRUCT_TYPE
:
59 rtl::Reference
< unoidl::PlainStructTypeEntity
> ent2(
60 static_cast< unoidl::PlainStructTypeEntity
* >(ent
.get()));
61 if (!ent2
->getDirectBase().isEmpty()) {
62 insert(ent2
->getDirectBase());
64 for (std::vector
< unoidl::PlainStructTypeEntity::Member
>::
65 const_iterator
i(ent2
->getDirectMembers().begin());
66 i
!= ent2
->getDirectMembers().end(); ++i
)
72 case UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
74 rtl::Reference
< unoidl::PolymorphicStructTypeTemplateEntity
> ent2(
75 static_cast< unoidl::PolymorphicStructTypeTemplateEntity
* >(
77 for (std::vector
< unoidl::PolymorphicStructTypeTemplateEntity::
78 Member
>::const_iterator
i(ent2
->getMembers().begin());
79 i
!= ent2
->getMembers().end(); ++i
)
81 if (!i
->parameterized
) {
87 case UnoType::SORT_EXCEPTION_TYPE
:
89 rtl::Reference
< unoidl::ExceptionTypeEntity
> ent2(
90 static_cast< unoidl::ExceptionTypeEntity
* >(ent
.get()));
91 if (!ent2
->getDirectBase().isEmpty()) {
92 insert(ent2
->getDirectBase());
94 for (std::vector
< unoidl::ExceptionTypeEntity::Member
>::
95 const_iterator
i(ent2
->getDirectMembers().begin());
96 i
!= ent2
->getDirectMembers().end(); ++i
)
102 case UnoType::SORT_INTERFACE_TYPE
:
104 rtl::Reference
< unoidl::InterfaceTypeEntity
> ent2(
105 static_cast< unoidl::InterfaceTypeEntity
* >(ent
.get()));
106 for (std::vector
< unoidl::AnnotatedReference
>::const_iterator
i(
107 ent2
->getDirectMandatoryBases().begin());
108 i
!= ent2
->getDirectMandatoryBases().end(); ++i
)
110 insert(i
->name
, true);
112 if (!(ent2
->getDirectAttributes().empty()
113 && ent2
->getDirectMethods().empty()))
115 insert("com.sun.star.uno.RuntimeException");
117 for (std::vector
< unoidl::InterfaceTypeEntity::Attribute
>::
118 const_iterator
i(ent2
->getDirectAttributes().begin());
119 i
!= ent2
->getDirectAttributes().end(); ++i
)
122 for (std::vector
< OUString
>::const_iterator
j(
123 i
->getExceptions
.begin());
124 j
!= i
->getExceptions
.end(); ++j
)
128 for (std::vector
< OUString
>::const_iterator
j(
129 i
->setExceptions
.begin());
130 j
!= i
->setExceptions
.end(); ++j
)
135 for (std::vector
< unoidl::InterfaceTypeEntity::Method
>::
136 const_iterator
i(ent2
->getDirectMethods().begin());
137 i
!= ent2
->getDirectMethods().end(); ++i
)
139 insert(i
->returnType
);
141 unoidl::InterfaceTypeEntity::Method::Parameter
>::
142 const_iterator
j(i
->parameters
.begin());
143 j
!= i
->parameters
.end(); ++j
)
147 for (std::vector
< OUString
>::const_iterator
j(
148 i
->exceptions
.begin());
149 j
!= i
->exceptions
.end(); ++j
)
156 case UnoType::SORT_TYPEDEF
:
157 insert(static_cast< unoidl::TypedefEntity
* >(ent
.get())->getType());
159 case UnoType::SORT_CONSTANT_GROUP
:
161 rtl::Reference
< unoidl::ConstantGroupEntity
> ent2(
162 static_cast< unoidl::ConstantGroupEntity
* >(ent
.get()));
163 for (std::vector
< unoidl::ConstantGroupEntity::Member
>::
164 const_iterator
i(ent2
->getMembers().begin());
165 i
!= ent2
->getMembers().end(); ++i
)
167 switch (i
->value
.type
) {
168 case unoidl::ConstantValue::TYPE_BOOLEAN
:
169 m_booleanDependency
= true;
171 case unoidl::ConstantValue::TYPE_BYTE
:
172 m_byteDependency
= true;
174 case unoidl::ConstantValue::TYPE_SHORT
:
175 m_shortDependency
= true;
177 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT
:
178 m_unsignedShortDependency
= true;
180 case unoidl::ConstantValue::TYPE_LONG
:
181 m_longDependency
= true;
183 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG
:
184 m_unsignedLongDependency
= true;
186 case unoidl::ConstantValue::TYPE_HYPER
:
187 m_hyperDependency
= true;
189 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER
:
190 m_unsignedHyperDependency
= true;
192 case unoidl::ConstantValue::TYPE_FLOAT
:
193 m_floatDependency
= true;
195 case unoidl::ConstantValue::TYPE_DOUBLE
:
196 m_doubleDependency
= true;
202 case UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE
:
204 rtl::Reference
< unoidl::SingleInterfaceBasedServiceEntity
> ent2(
205 static_cast< unoidl::SingleInterfaceBasedServiceEntity
* >(
207 if (!ent2
->getConstructors().empty()) {
208 insert(ent2
->getBase());
211 unoidl::SingleInterfaceBasedServiceEntity::Constructor
>::
212 const_iterator
i(ent2
->getConstructors().begin());
213 i
!= ent2
->getConstructors().end(); ++i
)
216 unoidl::SingleInterfaceBasedServiceEntity::
217 Constructor::Parameter
>::const_iterator
j(
218 i
->parameters
.begin());
219 j
!= i
->parameters
.end(); ++j
)
223 m_sequenceDependency
= true;
226 for (std::vector
< OUString
>::const_iterator
j(
227 i
->exceptions
.begin());
228 j
!= i
->exceptions
.end(); ++j
)
235 case UnoType::SORT_INTERFACE_BASED_SINGLETON
:
237 static_cast< unoidl::InterfaceBasedSingletonEntity
* >(ent
.get())->
241 assert(false); // this cannot happen
245 Dependencies::~Dependencies() {}
247 void Dependencies::insert(OUString
const & name
, bool base
) {
249 std::vector
< OString
> args
;
250 OUString
n(b2u(UnoType::decompose(u2b(name
), &k
, &args
)));
252 m_sequenceDependency
= true;
254 switch (m_manager
->getSort(n
)) {
255 case UnoType::SORT_VOID
:
256 m_voidDependency
= true;
258 case UnoType::SORT_BOOLEAN
:
259 m_booleanDependency
= true;
261 case UnoType::SORT_BYTE
:
262 m_byteDependency
= true;
264 case UnoType::SORT_SHORT
:
265 m_shortDependency
= true;
267 case UnoType::SORT_UNSIGNED_SHORT
:
268 m_unsignedShortDependency
= true;
270 case UnoType::SORT_LONG
:
271 m_longDependency
= true;
273 case UnoType::SORT_UNSIGNED_LONG
:
274 m_unsignedLongDependency
= true;
276 case UnoType::SORT_HYPER
:
277 m_hyperDependency
= true;
279 case UnoType::SORT_UNSIGNED_HYPER
:
280 m_unsignedHyperDependency
= true;
282 case UnoType::SORT_FLOAT
:
283 m_floatDependency
= true;
285 case UnoType::SORT_DOUBLE
:
286 m_doubleDependency
= true;
288 case UnoType::SORT_CHAR
:
289 m_charDependency
= true;
291 case UnoType::SORT_STRING
:
292 m_stringDependency
= true;
294 case UnoType::SORT_TYPE
:
295 m_typeDependency
= true;
297 case UnoType::SORT_ANY
:
298 m_anyDependency
= true;
300 case UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
:
301 for (std::vector
< OString
>::iterator
i(args
.begin()); i
!= args
.end();
304 insert(b2u(*i
), false);
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
:
314 std::pair
< Map::iterator
, bool > i(
316 Map::value_type(n
, base
? KIND_BASE
: KIND_NO_BASE
)));
317 if (!i
.second
&& base
) {
318 i
.first
->second
= KIND_BASE
;
323 throw CannotDumpException(
324 "unexpected type \"" + name
325 + "\" in call to codemaker::cppumaker::Dependencies::Dependencies");
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */