LibreOffice Module codemaker (master) 1
dependencies.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <cassert>
23#include <utility>
24#include <vector>
25
26#include <codemaker/global.hxx>
28#include <codemaker/unotype.hxx>
29
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>
35
36#include "dependencies.hxx"
37
39
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)
49{
50 assert(manager.is());
52 switch (m_manager->getSort(name, &ent)) {
54 break;
56 {
58 static_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
59 if (!ent2->getDirectBase().isEmpty()) {
60 insert(ent2->getDirectBase(), KIND_NORMAL);
61 }
62 for (const unoidl::PlainStructTypeEntity::Member& member : ent2->getDirectMembers())
63 {
64 insert(member.type, KIND_NORMAL);
65 }
66 break;
67 }
69 {
72 ent.get()));
73 for (const unoidl::PolymorphicStructTypeTemplateEntity::Member& member : ent2->getMembers())
74 {
75 if (!member.parameterized) {
76 insert(member.type, KIND_NORMAL);
77 }
78 }
79 break;
80 }
82 {
84 static_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
85 if (!ent2->getDirectBase().isEmpty()) {
86 insert(ent2->getDirectBase(), KIND_NORMAL);
87 }
88 for (const unoidl::ExceptionTypeEntity::Member& member : ent2->getDirectMembers())
89 {
90 insert(member.type, KIND_NORMAL);
91 }
92 break;
93 }
95 {
97 static_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
98 for (const unoidl::AnnotatedReference& ar : ent2->getDirectMandatoryBases())
99 {
100 insert(ar.name, KIND_BASE);
101 }
102 if (!(ent2->getDirectAttributes().empty()
103 && ent2->getDirectMethods().empty()))
104 {
105 insert(u"com.sun.star.uno.RuntimeException", KIND_EXCEPTION);
106 }
107 for (const unoidl::InterfaceTypeEntity::Attribute& attr : ent2->getDirectAttributes())
108 {
109 insert(attr.type, KIND_NORMAL);
110 for (const OUString& ex : attr.getExceptions)
111 {
113 }
114 for (const OUString& ex : attr.setExceptions)
115 {
117 }
118 }
119 for (const unoidl::InterfaceTypeEntity::Method& method : ent2->getDirectMethods())
120 {
121 insert(method.returnType, KIND_NORMAL);
122 for (const unoidl::InterfaceTypeEntity::Method::Parameter& param : method.parameters)
123 {
124 insert(param.type, KIND_NORMAL);
125 }
126 for (const OUString& ex : method.exceptions)
127 {
129 }
130 }
131 break;
132 }
134 insert(
135 static_cast< unoidl::TypedefEntity * >(ent.get())->getType(),
137 break;
139 {
141 static_cast< unoidl::ConstantGroupEntity * >(ent.get()));
142 for (const unoidl::ConstantGroupEntity::Member& member : ent2->getMembers())
143 {
144 switch (member.value.type) {
146 m_booleanDependency = true;
147 break;
149 m_byteDependency = true;
150 break;
152 m_shortDependency = true;
153 break;
156 break;
158 m_longDependency = true;
159 break;
162 break;
164 m_hyperDependency = true;
165 break;
168 break;
170 break;
172 break;
173 }
174 }
175 break;
176 }
178 {
181 ent.get()));
182 if (!ent2->getConstructors().empty()) {
183 insert(ent2->getBase(), KIND_NORMAL);
184 }
185 for (const unoidl::SingleInterfaceBasedServiceEntity::Constructor& cons : ent2->getConstructors())
186 {
188 : cons.parameters)
189 {
190 insert(param.type, KIND_NORMAL);
191 if (param.rest) {
193 }
194 }
195 for (const OUString& ex : cons.exceptions)
196 {
198 }
199 }
200 break;
201 }
203 insert(
204 static_cast< unoidl::InterfaceBasedSingletonEntity * >(ent.get())->
205 getBase(),
207 break;
208 default:
209 assert(false); // this cannot happen
210 }
211}
212
214
215void 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) {
221 }
222 switch (m_manager->getSort(n)) {
224 m_voidDependency = true;
225 break;
227 m_booleanDependency = true;
228 break;
230 m_byteDependency = true;
231 break;
233 m_shortDependency = true;
234 break;
237 break;
239 m_longDependency = true;
240 break;
243 break;
245 m_hyperDependency = true;
246 break;
249 break;
251 break;
253 break;
255 m_charDependency = true;
256 break;
258 m_stringDependency = true;
259 break;
261 m_typeDependency = true;
262 break;
264 m_anyDependency = true;
265 break;
267 for (const OString& arg : args)
268 {
269 insert(b2u(arg), KIND_NORMAL);
270 }
271 [[fallthrough]];
278 {
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;
284 }
285 break;
286 }
287 default:
289 OUString::Concat("unexpected type \"") + name
290 + "\" in call to codemaker::cppumaker::Dependencies::Dependencies");
291 }
292}
293
294}
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference< TypeManager > m_manager
Dependencies(rtl::Reference< TypeManager > const &manager, OUString const &name)
Constructs the dependencies for a given entity.
Kind
Flags to distinguish whether one entity depends on another entity because the second is a direct base...
void insert(std::u16string_view name, Kind kind)
const OUString & getType() const
rtl::Reference< ParseManager > manager
float u
const char * name
sal_Int64 n
rtl::OString decompose(rtl::OString const &type, sal_Int32 *rank=nullptr, std::vector< rtl::OString > *arguments=nullptr)
Decomposes a UNO type name or UNO type registry name.
int i
args
OUString b2u(std::string_view s)
Definition: typemanager.hxx:71
OString u2b(std::u16string_view s)
Definition: typemanager.hxx:67