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
:
57 case UnoType::Sort::PlainStruct
:
59 rtl::Reference
< unoidl::PlainStructTypeEntity
> ent2(
60 static_cast< unoidl::PlainStructTypeEntity
* >(ent
.get()));
61 if (!ent2
->getDirectBase().isEmpty()) {
62 insert(ent2
->getDirectBase());
64 for (const unoidl::PlainStructTypeEntity::Member
& member
: ent2
->getDirectMembers())
70 case UnoType::Sort::PolymorphicStructTemplate
:
72 rtl::Reference
< unoidl::PolymorphicStructTypeTemplateEntity
> ent2(
73 static_cast< unoidl::PolymorphicStructTypeTemplateEntity
* >(
75 for (const unoidl::PolymorphicStructTypeTemplateEntity::Member
& member
: ent2
->getMembers())
77 if (!member
.parameterized
) {
83 case UnoType::Sort::Exception
:
85 rtl::Reference
< unoidl::ExceptionTypeEntity
> ent2(
86 static_cast< unoidl::ExceptionTypeEntity
* >(ent
.get()));
87 if (!ent2
->getDirectBase().isEmpty()) {
88 insert(ent2
->getDirectBase());
90 for (const unoidl::ExceptionTypeEntity::Member
& member
: ent2
->getDirectMembers())
96 case UnoType::Sort::Interface
:
98 rtl::Reference
< unoidl::InterfaceTypeEntity
> ent2(
99 static_cast< unoidl::InterfaceTypeEntity
* >(ent
.get()));
100 for (const unoidl::AnnotatedReference
& ar
: ent2
->getDirectMandatoryBases())
102 insert(ar
.name
, true);
104 if (!(ent2
->getDirectAttributes().empty()
105 && ent2
->getDirectMethods().empty()))
107 insert("com.sun.star.uno.RuntimeException");
109 for (const unoidl::InterfaceTypeEntity::Attribute
& attr
: ent2
->getDirectAttributes())
112 for (const OUString
& ex
: attr
.getExceptions
)
116 for (const OUString
& ex
: attr
.setExceptions
)
121 for (const unoidl::InterfaceTypeEntity::Method
& method
: ent2
->getDirectMethods())
123 insert(method
.returnType
);
124 for (const unoidl::InterfaceTypeEntity::Method::Parameter
& param
: method
.parameters
)
128 for (const OUString
& ex
: method
.exceptions
)
135 case UnoType::Sort::Typedef
:
136 insert(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
:
170 m_floatDependency
= true;
172 case unoidl::ConstantValue::TYPE_DOUBLE
:
173 m_doubleDependency
= true;
179 case UnoType::Sort::SingleInterfaceBasedService
:
181 rtl::Reference
< unoidl::SingleInterfaceBasedServiceEntity
> ent2(
182 static_cast< unoidl::SingleInterfaceBasedServiceEntity
* >(
184 if (!ent2
->getConstructors().empty()) {
185 insert(ent2
->getBase());
187 for (const unoidl::SingleInterfaceBasedServiceEntity::Constructor
& cons
: ent2
->getConstructors())
189 for (const unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
& param
194 m_sequenceDependency
= true;
197 for (const OUString
& ex
: cons
.exceptions
)
204 case UnoType::Sort::InterfaceBasedSingleton
:
206 static_cast< unoidl::InterfaceBasedSingletonEntity
* >(ent
.get())->
210 assert(false); // this cannot happen
214 Dependencies::~Dependencies() {}
216 void Dependencies::insert(OUString
const & name
, bool base
) {
218 std::vector
< OString
> args
;
219 OUString
n(b2u(UnoType::decompose(u2b(name
), &k
, &args
)));
221 m_sequenceDependency
= true;
223 switch (m_manager
->getSort(n
)) {
224 case UnoType::Sort::Void
:
225 m_voidDependency
= true;
227 case UnoType::Sort::Boolean
:
228 m_booleanDependency
= true;
230 case UnoType::Sort::Byte
:
231 m_byteDependency
= true;
233 case UnoType::Sort::Short
:
234 m_shortDependency
= true;
236 case UnoType::Sort::UnsignedShort
:
237 m_unsignedShortDependency
= true;
239 case UnoType::Sort::Long
:
240 m_longDependency
= true;
242 case UnoType::Sort::UnsignedLong
:
243 m_unsignedLongDependency
= true;
245 case UnoType::Sort::Hyper
:
246 m_hyperDependency
= true;
248 case UnoType::Sort::UnsignedHyper
:
249 m_unsignedHyperDependency
= true;
251 case UnoType::Sort::Float
:
252 m_floatDependency
= true;
254 case UnoType::Sort::Double
:
255 m_doubleDependency
= true;
257 case UnoType::Sort::Char
:
258 m_charDependency
= true;
260 case UnoType::Sort::String
:
261 m_stringDependency
= true;
263 case UnoType::Sort::Type
:
264 m_typeDependency
= true;
266 case UnoType::Sort::Any
:
267 m_anyDependency
= true;
269 case UnoType::Sort::PolymorphicStructTemplate
:
270 for (const OString
& arg
: args
)
275 case UnoType::Sort::Sequence
:
276 case UnoType::Sort::Enum
:
277 case UnoType::Sort::PlainStruct
:
278 case UnoType::Sort::Exception
:
279 case UnoType::Sort::Interface
:
280 case UnoType::Sort::Typedef
:
282 std::pair
< Map::iterator
, bool > i(
284 Map::value_type(n
, base
? KIND_BASE
: KIND_NO_BASE
)));
285 if (!i
.second
&& base
) {
286 i
.first
->second
= KIND_BASE
;
291 throw CannotDumpException(
292 "unexpected type \"" + name
293 + "\" in call to codemaker::cppumaker::Dependencies::Dependencies");
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */