Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / codemaker / source / cppumaker / dependencies.cxx
blob00c333d2346034d6f11be1acea4ffe4b95df3b08
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 #include <cassert>
23 #include <utility>
24 #include <vector>
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)
52 assert(manager.is());
53 rtl::Reference< unoidl::Entity > ent;
54 switch (m_manager->getSort(name, &ent)) {
55 case UnoType::Sort::Enum:
56 break;
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())
66 insert(member.type);
68 break;
70 case UnoType::Sort::PolymorphicStructTemplate:
72 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
73 static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
74 ent.get()));
75 for (const unoidl::PolymorphicStructTypeTemplateEntity::Member& member : ent2->getMembers())
77 if (!member.parameterized) {
78 insert(member.type);
81 break;
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())
92 insert(member.type);
94 break;
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())
111 insert(attr.type);
112 for (const OUString& ex : attr.getExceptions)
114 insert(ex);
116 for (const OUString& ex : attr.setExceptions)
118 insert(ex);
121 for (const unoidl::InterfaceTypeEntity::Method& method : ent2->getDirectMethods())
123 insert(method.returnType);
124 for (const unoidl::InterfaceTypeEntity::Method::Parameter& param : method.parameters)
126 insert(param.type);
128 for (const OUString& ex : method.exceptions)
130 insert(ex);
133 break;
135 case UnoType::Sort::Typedef:
136 insert(static_cast< unoidl::TypedefEntity * >(ent.get())->getType());
137 break;
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;
147 break;
148 case unoidl::ConstantValue::TYPE_BYTE:
149 m_byteDependency = true;
150 break;
151 case unoidl::ConstantValue::TYPE_SHORT:
152 m_shortDependency = true;
153 break;
154 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
155 m_unsignedShortDependency = true;
156 break;
157 case unoidl::ConstantValue::TYPE_LONG:
158 m_longDependency = true;
159 break;
160 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
161 m_unsignedLongDependency = true;
162 break;
163 case unoidl::ConstantValue::TYPE_HYPER:
164 m_hyperDependency = true;
165 break;
166 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
167 m_unsignedHyperDependency = true;
168 break;
169 case unoidl::ConstantValue::TYPE_FLOAT:
170 m_floatDependency = true;
171 break;
172 case unoidl::ConstantValue::TYPE_DOUBLE:
173 m_doubleDependency = true;
174 break;
177 break;
179 case UnoType::Sort::SingleInterfaceBasedService:
181 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
182 static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
183 ent.get()));
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
190 : cons.parameters)
192 insert(param.type);
193 if (param.rest) {
194 m_sequenceDependency = true;
197 for (const OUString& ex : cons.exceptions)
199 insert(ex);
202 break;
204 case UnoType::Sort::InterfaceBasedSingleton:
205 insert(
206 static_cast< unoidl::InterfaceBasedSingletonEntity * >(ent.get())->
207 getBase());
208 break;
209 default:
210 assert(false); // this cannot happen
214 Dependencies::~Dependencies() {}
216 void Dependencies::insert(OUString const & name, bool base) {
217 sal_Int32 k;
218 std::vector< OString > args;
219 OUString n(b2u(UnoType::decompose(u2b(name), &k, &args)));
220 if (k != 0) {
221 m_sequenceDependency = true;
223 switch (m_manager->getSort(n)) {
224 case UnoType::Sort::Void:
225 m_voidDependency = true;
226 break;
227 case UnoType::Sort::Boolean:
228 m_booleanDependency = true;
229 break;
230 case UnoType::Sort::Byte:
231 m_byteDependency = true;
232 break;
233 case UnoType::Sort::Short:
234 m_shortDependency = true;
235 break;
236 case UnoType::Sort::UnsignedShort:
237 m_unsignedShortDependency = true;
238 break;
239 case UnoType::Sort::Long:
240 m_longDependency = true;
241 break;
242 case UnoType::Sort::UnsignedLong:
243 m_unsignedLongDependency = true;
244 break;
245 case UnoType::Sort::Hyper:
246 m_hyperDependency = true;
247 break;
248 case UnoType::Sort::UnsignedHyper:
249 m_unsignedHyperDependency = true;
250 break;
251 case UnoType::Sort::Float:
252 m_floatDependency = true;
253 break;
254 case UnoType::Sort::Double:
255 m_doubleDependency = true;
256 break;
257 case UnoType::Sort::Char:
258 m_charDependency = true;
259 break;
260 case UnoType::Sort::String:
261 m_stringDependency = true;
262 break;
263 case UnoType::Sort::Type:
264 m_typeDependency = true;
265 break;
266 case UnoType::Sort::Any:
267 m_anyDependency = true;
268 break;
269 case UnoType::Sort::PolymorphicStructTemplate:
270 for (const OString& arg : args)
272 insert(b2u(arg));
274 SAL_FALLTHROUGH;
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(
283 m_map.insert(
284 Map::value_type(n, base ? KIND_BASE : KIND_NO_BASE)));
285 if (!i.second && base) {
286 i.first->second = KIND_BASE;
288 break;
290 default:
291 throw CannotDumpException(
292 "unexpected type \"" + name
293 + "\" in call to codemaker::cppumaker::Dependencies::Dependencies");
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */