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 <rtl/ref.hxx>
31 #include <rtl/string.hxx>
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
34 #include <unoidl/unoidl.hxx>
36 #include "dependencies.hxx"
38 namespace codemaker::cppumaker
{
40 Dependencies::Dependencies(
41 rtl::Reference
< TypeManager
> const & manager
, OUString
const & name
):
42 m_manager(manager
), m_voidDependency(false), m_booleanDependency(false),
43 m_byteDependency(false), m_shortDependency(false),
44 m_unsignedShortDependency(false), m_longDependency(false),
45 m_unsignedLongDependency(false), m_hyperDependency(false),
46 m_unsignedHyperDependency(false), m_charDependency(false),
47 m_stringDependency(false), m_typeDependency(false), m_anyDependency(false),
48 m_sequenceDependency(false)
51 rtl::Reference
< unoidl::Entity
> ent
;
52 switch (m_manager
->getSort(name
, &ent
)) {
53 case UnoType::Sort::Enum
:
55 case UnoType::Sort::PlainStruct
:
57 rtl::Reference
< unoidl::PlainStructTypeEntity
> ent2(
58 static_cast< unoidl::PlainStructTypeEntity
* >(ent
.get()));
59 if (!ent2
->getDirectBase().isEmpty()) {
60 insert(ent2
->getDirectBase(), KIND_NORMAL
);
62 for (const unoidl::PlainStructTypeEntity::Member
& member
: ent2
->getDirectMembers())
64 insert(member
.type
, KIND_NORMAL
);
68 case UnoType::Sort::PolymorphicStructTemplate
:
70 rtl::Reference
< unoidl::PolymorphicStructTypeTemplateEntity
> ent2(
71 static_cast< unoidl::PolymorphicStructTypeTemplateEntity
* >(
73 for (const unoidl::PolymorphicStructTypeTemplateEntity::Member
& member
: ent2
->getMembers())
75 if (!member
.parameterized
) {
76 insert(member
.type
, KIND_NORMAL
);
81 case UnoType::Sort::Exception
:
83 rtl::Reference
< unoidl::ExceptionTypeEntity
> ent2(
84 static_cast< unoidl::ExceptionTypeEntity
* >(ent
.get()));
85 if (!ent2
->getDirectBase().isEmpty()) {
86 insert(ent2
->getDirectBase(), KIND_NORMAL
);
88 for (const unoidl::ExceptionTypeEntity::Member
& member
: ent2
->getDirectMembers())
90 insert(member
.type
, KIND_NORMAL
);
94 case UnoType::Sort::Interface
:
96 rtl::Reference
< unoidl::InterfaceTypeEntity
> ent2(
97 static_cast< unoidl::InterfaceTypeEntity
* >(ent
.get()));
98 for (const unoidl::AnnotatedReference
& ar
: ent2
->getDirectMandatoryBases())
100 insert(ar
.name
, KIND_BASE
);
102 if (!(ent2
->getDirectAttributes().empty()
103 && ent2
->getDirectMethods().empty()))
105 insert(u
"com.sun.star.uno.RuntimeException", KIND_EXCEPTION
);
107 for (const unoidl::InterfaceTypeEntity::Attribute
& attr
: ent2
->getDirectAttributes())
109 insert(attr
.type
, KIND_NORMAL
);
110 for (const OUString
& ex
: attr
.getExceptions
)
112 insert(ex
, KIND_EXCEPTION
);
114 for (const OUString
& ex
: attr
.setExceptions
)
116 insert(ex
, KIND_EXCEPTION
);
119 for (const unoidl::InterfaceTypeEntity::Method
& method
: ent2
->getDirectMethods())
121 insert(method
.returnType
, KIND_NORMAL
);
122 for (const unoidl::InterfaceTypeEntity::Method::Parameter
& param
: method
.parameters
)
124 insert(param
.type
, KIND_NORMAL
);
126 for (const OUString
& ex
: method
.exceptions
)
128 insert(ex
, KIND_EXCEPTION
);
133 case UnoType::Sort::Typedef
:
135 static_cast< unoidl::TypedefEntity
* >(ent
.get())->getType(),
138 case UnoType::Sort::ConstantGroup
:
140 rtl::Reference
< unoidl::ConstantGroupEntity
> ent2(
141 static_cast< unoidl::ConstantGroupEntity
* >(ent
.get()));
142 for (const unoidl::ConstantGroupEntity::Member
& member
: ent2
->getMembers())
144 switch (member
.value
.type
) {
145 case unoidl::ConstantValue::TYPE_BOOLEAN
:
146 m_booleanDependency
= true;
148 case unoidl::ConstantValue::TYPE_BYTE
:
149 m_byteDependency
= true;
151 case unoidl::ConstantValue::TYPE_SHORT
:
152 m_shortDependency
= true;
154 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT
:
155 m_unsignedShortDependency
= true;
157 case unoidl::ConstantValue::TYPE_LONG
:
158 m_longDependency
= true;
160 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG
:
161 m_unsignedLongDependency
= true;
163 case unoidl::ConstantValue::TYPE_HYPER
:
164 m_hyperDependency
= true;
166 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER
:
167 m_unsignedHyperDependency
= true;
169 case unoidl::ConstantValue::TYPE_FLOAT
:
171 case unoidl::ConstantValue::TYPE_DOUBLE
:
177 case UnoType::Sort::SingleInterfaceBasedService
:
179 rtl::Reference
< unoidl::SingleInterfaceBasedServiceEntity
> ent2(
180 static_cast< unoidl::SingleInterfaceBasedServiceEntity
* >(
182 if (!ent2
->getConstructors().empty()) {
183 insert(ent2
->getBase(), KIND_NORMAL
);
185 for (const unoidl::SingleInterfaceBasedServiceEntity::Constructor
& cons
: ent2
->getConstructors())
187 for (const unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
& param
190 insert(param
.type
, KIND_NORMAL
);
192 m_sequenceDependency
= true;
195 for (const OUString
& ex
: cons
.exceptions
)
197 insert(ex
, KIND_EXCEPTION
);
202 case UnoType::Sort::InterfaceBasedSingleton
:
204 static_cast< unoidl::InterfaceBasedSingletonEntity
* >(ent
.get())->
209 assert(false); // this cannot happen
213 Dependencies::~Dependencies() {}
215 void Dependencies::insert(std::u16string_view name
, Kind kind
) {
217 std::vector
< OString
> args
;
218 OUString
n(b2u(UnoType::decompose(u2b(name
), &k
, &args
)));
220 m_sequenceDependency
= true;
222 switch (m_manager
->getSort(n
)) {
223 case UnoType::Sort::Void
:
224 m_voidDependency
= true;
226 case UnoType::Sort::Boolean
:
227 m_booleanDependency
= true;
229 case UnoType::Sort::Byte
:
230 m_byteDependency
= true;
232 case UnoType::Sort::Short
:
233 m_shortDependency
= true;
235 case UnoType::Sort::UnsignedShort
:
236 m_unsignedShortDependency
= true;
238 case UnoType::Sort::Long
:
239 m_longDependency
= true;
241 case UnoType::Sort::UnsignedLong
:
242 m_unsignedLongDependency
= true;
244 case UnoType::Sort::Hyper
:
245 m_hyperDependency
= true;
247 case UnoType::Sort::UnsignedHyper
:
248 m_unsignedHyperDependency
= true;
250 case UnoType::Sort::Float
:
252 case UnoType::Sort::Double
:
254 case UnoType::Sort::Char
:
255 m_charDependency
= true;
257 case UnoType::Sort::String
:
258 m_stringDependency
= true;
260 case UnoType::Sort::Type
:
261 m_typeDependency
= true;
263 case UnoType::Sort::Any
:
264 m_anyDependency
= true;
266 case UnoType::Sort::PolymorphicStructTemplate
:
267 for (const OString
& arg
: args
)
269 insert(b2u(arg
), KIND_NORMAL
);
272 case UnoType::Sort::Sequence
:
273 case UnoType::Sort::Enum
:
274 case UnoType::Sort::PlainStruct
:
275 case UnoType::Sort::Exception
:
276 case UnoType::Sort::Interface
:
277 case UnoType::Sort::Typedef
:
279 std::pair
< Map::iterator
, bool > i(
280 m_map
.emplace(n
, kind
));
281 if (!i
.second
&& kind
== KIND_BASE
) {
282 assert(i
.first
->second
!= KIND_EXCEPTION
);
283 i
.first
->second
= KIND_BASE
;
288 throw CannotDumpException(
289 OUString::Concat("unexpected type \"") + name
290 + "\" in call to codemaker::cppumaker::Dependencies::Dependencies");
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */