tdf#130857 qt weld: Support "Insert Breaks" dialog
[LibreOffice.git] / codemaker / source / cppumaker / dependencies.cxx
blob1af6b9d46061a8cfc49c5fc07983e6f295501a1a
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 <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)
50 assert(manager.is());
51 rtl::Reference< unoidl::Entity > ent;
52 switch (m_manager->getSort(name, &ent)) {
53 case UnoType::Sort::Enum:
54 break;
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);
66 break;
68 case UnoType::Sort::PolymorphicStructTemplate:
70 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
71 static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
72 ent.get()));
73 for (const unoidl::PolymorphicStructTypeTemplateEntity::Member& member : ent2->getMembers())
75 if (!member.parameterized) {
76 insert(member.type, KIND_NORMAL);
79 break;
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);
92 break;
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);
131 break;
133 case UnoType::Sort::Typedef:
134 insert(
135 static_cast< unoidl::TypedefEntity * >(ent.get())->getType(),
136 KIND_NORMAL);
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 break;
171 case unoidl::ConstantValue::TYPE_DOUBLE:
172 break;
175 break;
177 case UnoType::Sort::SingleInterfaceBasedService:
179 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
180 static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
181 ent.get()));
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
188 : cons.parameters)
190 insert(param.type, KIND_NORMAL);
191 if (param.rest) {
192 m_sequenceDependency = true;
195 for (const OUString& ex : cons.exceptions)
197 insert(ex, KIND_EXCEPTION);
200 break;
202 case UnoType::Sort::InterfaceBasedSingleton:
203 insert(
204 static_cast< unoidl::InterfaceBasedSingletonEntity * >(ent.get())->
205 getBase(),
206 KIND_NORMAL);
207 break;
208 default:
209 assert(false); // this cannot happen
213 Dependencies::~Dependencies() {}
215 void Dependencies::insert(std::u16string_view name, Kind kind) {
216 sal_Int32 k;
217 std::vector< OString > args;
218 OUString n(b2u(UnoType::decompose(u2b(name), &k, &args)));
219 if (k != 0) {
220 m_sequenceDependency = true;
222 switch (m_manager->getSort(n)) {
223 case UnoType::Sort::Void:
224 m_voidDependency = true;
225 break;
226 case UnoType::Sort::Boolean:
227 m_booleanDependency = true;
228 break;
229 case UnoType::Sort::Byte:
230 m_byteDependency = true;
231 break;
232 case UnoType::Sort::Short:
233 m_shortDependency = true;
234 break;
235 case UnoType::Sort::UnsignedShort:
236 m_unsignedShortDependency = true;
237 break;
238 case UnoType::Sort::Long:
239 m_longDependency = true;
240 break;
241 case UnoType::Sort::UnsignedLong:
242 m_unsignedLongDependency = true;
243 break;
244 case UnoType::Sort::Hyper:
245 m_hyperDependency = true;
246 break;
247 case UnoType::Sort::UnsignedHyper:
248 m_unsignedHyperDependency = true;
249 break;
250 case UnoType::Sort::Float:
251 break;
252 case UnoType::Sort::Double:
253 break;
254 case UnoType::Sort::Char:
255 m_charDependency = true;
256 break;
257 case UnoType::Sort::String:
258 m_stringDependency = true;
259 break;
260 case UnoType::Sort::Type:
261 m_typeDependency = true;
262 break;
263 case UnoType::Sort::Any:
264 m_anyDependency = true;
265 break;
266 case UnoType::Sort::PolymorphicStructTemplate:
267 for (const OString& arg : args)
269 insert(b2u(arg), KIND_NORMAL);
271 [[fallthrough]];
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;
285 break;
287 default:
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: */