LibreOffice Module codemaker (master) 1
typemanager.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 <cstdlib>
23#include <cstring>
24#include <vector>
25
26#include <codemaker/global.hxx>
28#include <rtl/ref.hxx>
29#include <rtl/ustring.hxx>
30#include <unoidl/unoidl.hxx>
31
33
35
36void TypeManager::loadProvider(OUString const & uri, bool primary) {
37 rtl::Reference< unoidl::Provider > prov(manager_->addProvider(uri));
38 if (primary) {
39 primaryProviders_.push_back(prov);
40 }
41}
42
43bool TypeManager::foundAtPrimaryProvider(OUString const & name) const {
44 if (name.isEmpty()) {
45 return !primaryProviders_.empty();
46 }
48 {
49 if (xProvider->findEntity(name).is()) {
50 return true;
51 }
52 }
53 if (!manager_->findEntity(name).is()) {
54 throw CannotDumpException("Unknown entity '" + name + "'");
55 }
56 return false;
57}
58
60 OUString const & name, rtl::Reference< unoidl::Entity > * entity,
62{
63 if (name.isEmpty()) {
64 if (cursor != nullptr) {
65 *cursor = manager_->createCursor("");
66 }
68 }
69 if (name == "void") {
71 }
72 if (name == "boolean") {
74 }
75 if (name == "byte") {
77 }
78 if (name == "short") {
80 }
81 if (name == "unsigned short") {
83 }
84 if (name == "long") {
86 }
87 if (name == "unsigned long") {
89 }
90 if (name == "hyper") {
92 }
93 if (name == "unsigned hyper") {
95 }
96 if (name == "float") {
98 }
99 if (name == "double") {
101 }
102 if (name == "char") {
104 }
105 if (name == "string") {
107 }
108 if (name == "type") {
110 }
111 if (name == "any") {
113 }
114 if (name.startsWith("[")) {
116 }
117 if (name.indexOf('<') != -1) {
119 }
121 if (!ent.is()) {
122 throw CannotDumpException("Unknown entity '" + name + "'");
123 }
124 if (entity != nullptr) {
125 *entity = ent;
126 }
127 switch (ent->getSort()) {
129 if (cursor != nullptr) {
130 *cursor = manager_->createCursor(name);
131 }
155 default:
156 for (;;) { std::abort(); } // this cannot happen
157 }
158}
159
161 std::u16string_view name, bool resolveTypedefs, OUString * nucleus,
162 sal_Int32 * rank, std::vector< OUString > * arguments,
164{
165 sal_Int32 k;
166 std::vector< OString > args;
167 OUString n = b2u(codemaker::UnoType::decompose(u2b(name), &k, &args));
168 for (;;) {
171 if (args.empty()
173 {
175 "template arguments mismatch for \"" + n
176 + "\" resolved from \"" + name + "\"");
177 }
178 switch (s) {
180 if (resolveTypedefs) {
181 n = dynamic_cast<unoidl::TypedefEntity&>(*ent).getType();
182 while (n.startsWith("[]")) {
183 ++k; //TODO: overflow
184 n = n.copy(std::strlen("[]"));
185 }
186 break;
187 }
188 [[fallthrough]];
208 if (nucleus != nullptr) {
209 *nucleus = n;
210 }
211 if (rank != nullptr) {
212 *rank = k;
213 }
214 if (arguments != nullptr) {
215 arguments->clear();
216 }
217 if (entity != nullptr) {
218 *entity = ent;
219 }
220 return s;
222 if (args.size()
223 != (dynamic_cast<unoidl::PolymorphicStructTypeTemplateEntity&>(*ent).
224 getTypeParameters().size()))
225 {
227 "bad number of template arguments for \"" + n
228 + "\" resolved from \"" + name + "\"");
229 }
230 if (nucleus != nullptr) {
231 *nucleus = n;
232 }
233 if (rank != nullptr) {
234 *rank = k;
235 }
236 if (arguments != nullptr) {
237 arguments->clear();
238 for (const OString& rArg : args)
239 {
240 arguments->push_back(b2u(rArg));
241 }
242 }
243 if (entity != nullptr) {
244 *entity = ent;
245 }
246 return
249 for (;;) std::abort(); // this cannot happen
250 default:
252 "unexpected \"" + n + "\" resolved from \"" + name
253 + "\"in call to TypeManager::decompose");
254 }
255 }
256}
257
258/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< rtl::Reference< unoidl::Provider > > primaryProviders_
Definition: typemanager.hxx:63
codemaker::UnoType::Sort decompose(std::u16string_view name, bool resolveTypedefs, OUString *nucleus, sal_Int32 *rank, std::vector< OUString > *arguments, rtl::Reference< unoidl::Entity > *entity) const
virtual ~TypeManager() override
Definition: typemanager.cxx:34
codemaker::UnoType::Sort getSort(OUString const &name, rtl::Reference< unoidl::Entity > *entity=nullptr, rtl::Reference< unoidl::MapCursor > *cursor=nullptr) const
Definition: typemanager.cxx:59
bool foundAtPrimaryProvider(OUString const &name) const
Definition: typemanager.cxx:43
void loadProvider(OUString const &uri, bool primary)
Definition: typemanager.cxx:36
rtl::Reference< unoidl::Manager > manager_
Definition: typemanager.hxx:62
SORT_SINGLE_INTERFACE_BASED_SERVICE
SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
const OUString & getType() const
const char * name
sal_Int64 n
constexpr LanguageType primary(LanguageType lt)
rtl::Reference< Manager > manager_
size
Sort
An enumeration of all the sorts of relevant UNOIDL entities.
Definition: unotype.hxx:33
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.
args
OUString b2u(std::string_view s)
Definition: typemanager.hxx:71
OString u2b(std::u16string_view s)
Definition: typemanager.hxx:67