From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- include/codemaker/codemaker.hxx | 38 +++++++++++ include/codemaker/commoncpp.hxx | 60 +++++++++++++++++ include/codemaker/commonjava.hxx | 44 ++++++++++++ include/codemaker/exceptiontree.hxx | 119 +++++++++++++++++++++++++++++++++ include/codemaker/generatedtypeset.hxx | 70 +++++++++++++++++++ include/codemaker/global.hxx | 96 ++++++++++++++++++++++++++ include/codemaker/options.hxx | 72 ++++++++++++++++++++ include/codemaker/typemanager.hxx | 77 +++++++++++++++++++++ include/codemaker/unotype.hxx | 88 ++++++++++++++++++++++++ 9 files changed, 664 insertions(+) create mode 100644 include/codemaker/codemaker.hxx create mode 100644 include/codemaker/commoncpp.hxx create mode 100644 include/codemaker/commonjava.hxx create mode 100644 include/codemaker/exceptiontree.hxx create mode 100644 include/codemaker/generatedtypeset.hxx create mode 100644 include/codemaker/global.hxx create mode 100644 include/codemaker/options.hxx create mode 100644 include/codemaker/typemanager.hxx create mode 100644 include/codemaker/unotype.hxx (limited to 'include/codemaker') diff --git a/include/codemaker/codemaker.hxx b/include/codemaker/codemaker.hxx new file mode 100644 index 0000000000..cf22b8a1f4 --- /dev/null +++ b/include/codemaker/codemaker.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_CODEMAKER_HXX +#define INCLUDED_CODEMAKER_CODEMAKER_HXX + +#include + +namespace rtl +{ +class OString; +class OUString; +} + +namespace codemaker +{ +rtl::OString convertString(rtl::OUString const& string); +} + +#endif // INCLUDED_CODEMAKER_CODEMAKER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/commoncpp.hxx b/include/codemaker/commoncpp.hxx new file mode 100644 index 0000000000..629941044d --- /dev/null +++ b/include/codemaker/commoncpp.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include + +#include + +#include + +namespace rtl { + class OString; + class OUString; +} + +namespace codemaker::cpp { + +/** Stick a namespace scope to c++ type + + @param type + Undecorated type + + @param ns_alias + Use common namespace aliases instead of fully specified (nested) + namespace. currently replaces com::sun::star with css. + */ +rtl::OString scopedCppName(rtl::OString const & type, bool ns_alias=true); + +rtl::OString translateUnoToCppType( + codemaker::UnoType::Sort sort, std::u16string_view nucleus); + +enum class IdentifierTranslationMode { + Global, + NonGlobal +}; + +rtl::OString translateUnoToCppIdentifier( + rtl::OString const & identifier, std::string_view prefix, + IdentifierTranslationMode transmode = IdentifierTranslationMode::Global, + rtl::OString const * forbidden = nullptr); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/commonjava.hxx b/include/codemaker/commonjava.hxx new file mode 100644 index 0000000000..daac32263c --- /dev/null +++ b/include/codemaker/commonjava.hxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_COMMONJAVA_HXX +#define INCLUDED_CODEMAKER_COMMONJAVA_HXX + +#include + +#include + +#include + +namespace rtl { class OString; } + +namespace codemaker::java { + +rtl::OString translateUnoToJavaType( + codemaker::UnoType::Sort sort, std::string_view nucleus, + bool referenceType); + +rtl::OString translateUnoToJavaIdentifier( + rtl::OString const & identifier, std::string_view prefix); + +} + +#endif // INCLUDED_CODEMAKER_COMMONJAVA_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/exceptiontree.hxx b/include/codemaker/exceptiontree.hxx new file mode 100644 index 0000000000..46291e4917 --- /dev/null +++ b/include/codemaker/exceptiontree.hxx @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_EXCEPTIONTREE_HXX +#define INCLUDED_CODEMAKER_EXCEPTIONTREE_HXX + +#include +#include + +#include +#include +#include + +class TypeManager; + +namespace codemaker { + +/** + Represents a node of the hierarchy from the ExceptionTree class. + */ +struct ExceptionTreeNode { + typedef std::vector< std::unique_ptr > Children; + + // Internally used by ExceptionTree: + ExceptionTreeNode(rtl::OString theName): + name(std::move(theName)), present(false) {} + + // Internally used by ExceptionTree: + ~ExceptionTreeNode() { clearChildren(); } + + // Internally used by ExceptionTree: + void setPresent() { present = true; clearChildren(); } + + // Internally used by ExceptionTree: + ExceptionTreeNode * add(rtl::OString const & theName); + + rtl::OString name; + bool present; + Children children; + +private: + ExceptionTreeNode(ExceptionTreeNode const &) = delete; + ExceptionTreeNode& operator =(ExceptionTreeNode const &) = delete; + + void clearChildren(); +}; + +/** + Represents the hierarchy formed by a set of UNO exception types. + + The hierarchy is rooted at com.sun.star.uno.Exception. For each exception E + from the given set S, the hierarchy from com.sun.star.uno.Exception to the + first supertype E' of E which is itself a member of S is represented (i.e., + subtypes that are hidden by supertypes are pruned from the hierarchy). The + exception com.sun.star.uno.RuntimeException and its subtypes are pruned + completely from the hierarchy. Each node of the hierarchy is represented by + an instance of ExceptionTreeNode, where `name` gives the name of the UNO + exception type, `present` is true iff the given exception type is a member of + the set S, and `children` contains all the relevant direct subtypes of the + given exception type, in no particular order (for nodes other than the root + node it holds that `children` is non-empty iff `present` is false). + */ +class ExceptionTree { +public: + ExceptionTree(): m_root("com.sun.star.uno.Exception"_ostr) {} + + /** + Builds the exception hierarchy, by adding one exception type at a time. + + This function can be called more than once for the same exception name. + + @param name the name of a UNO exception type; it is an error if the given + name does not represent a UNO exception type + + @param manager a type manager, used to resolve type names; it is an error + if different calls to this member function use different, incompatible + type managers + */ + void add( + rtl::OString const & name, + rtl::Reference< TypeManager > const & manager); + + /** + Gives access to the resultant exception hierarchy. + + @return a reference to the root of the exception hierarchy, as + formed by all previous calls to add; it is an error if any calls to add + follow the first call to getRoot + */ + ExceptionTreeNode const & getRoot() const { return m_root; } + +private: + ExceptionTree(ExceptionTree const &) = delete; + ExceptionTree& operator =(const ExceptionTree&) = delete; + + ExceptionTreeNode m_root; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/generatedtypeset.hxx b/include/codemaker/generatedtypeset.hxx new file mode 100644 index 0000000000..cc2827cb9a --- /dev/null +++ b/include/codemaker/generatedtypeset.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_GENERATEDTYPESET_HXX +#define INCLUDED_CODEMAKER_GENERATEDTYPESET_HXX + +#include + +#include + +/// @HTML + +namespace codemaker +{ +/** + A simple class to track which types have already been processed by a code + maker. + +

This class is not multi-thread–safe.

+ */ +class GeneratedTypeSet +{ +public: + GeneratedTypeSet() {} + + /** + Add a type to the set of generated types. + +

If the type was already present, nothing happens.

+ + @param type a UNO type registry name + */ + void add(OString const& type) { m_set.insert(type); } + + /** + Checks whether a given type has already been generated. + + @param type a UNO type registry name + + @return true iff the given type has already been generated + */ + bool contains(OString const& type) const { return m_set.find(type) != m_set.end(); } + +private: + GeneratedTypeSet(GeneratedTypeSet const&) = delete; + GeneratedTypeSet& operator=(GeneratedTypeSet const&) = delete; + + std::unordered_set m_set; +}; +} + +#endif // INCLUDED_CODEMAKER_GENERATEDTYPESET_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/global.hxx b/include/codemaker/global.hxx new file mode 100644 index 0000000000..e62e1a9732 --- /dev/null +++ b/include/codemaker/global.hxx @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_GLOBAL_HXX +#define INCLUDED_CODEMAKER_GLOBAL_HXX + +#include +#include +#include + +#include +#include +#include + +typedef ::std::vector< ::rtl::OString > StringVector; + + +// FileStream + +class FileStream final +{ +public: + FileStream(); + ~FileStream(); + + bool isValid() const; + + void createTempFile(const ::rtl::OString& sPath); + void close(); + + const ::rtl::OString& getName() const { return m_name; } + + bool write(void const * buffer, sal_uInt64 size); + + // friend functions + friend FileStream &operator<<(FileStream& o, sal_uInt32 i); + friend FileStream &operator<<(FileStream& o, char const * s); + friend FileStream &operator<<(FileStream& o, ::rtl::OString const * s); + friend FileStream &operator<<(FileStream& o, const ::rtl::OString& s); + friend FileStream &operator<<(FileStream& o, ::rtl::OStringBuffer const * s); + friend FileStream &operator<<(FileStream& o, const ::rtl::OStringBuffer& s); + friend FileStream & operator <<(FileStream & out, std::u16string_view s); + +private: + oslFileHandle m_file; + ::rtl::OString m_name; +}; + + +// Helper functions + +::rtl::OString getTempDir(const ::rtl::OString& sFileName); + +::rtl::OString createFileNameFromType(const ::rtl::OString& destination, + const ::rtl::OString& type, + const ::rtl::OString& postfix); + +bool fileExists(const ::rtl::OString& fileName); +bool makeValidTypeFile(const ::rtl::OString& targetFileName, + const ::rtl::OString& tmpFileName, + bool bFileCheck); +bool removeTypeFile(const ::rtl::OString& fileName); + +::rtl::OUString convertToFileUrl(const ::rtl::OString& fileName); + +class CannotDumpException final { +public: + CannotDumpException(OUString message): message_(std::move(message)) {} + + ~CannotDumpException() noexcept; + + const OUString& getMessage() const { return message_; } + +private: + OUString message_; +}; + +#endif // INCLUDED_CODEMAKER_GLOBAL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/options.hxx b/include/codemaker/options.hxx new file mode 100644 index 0000000000..803274901a --- /dev/null +++ b/include/codemaker/options.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_OPTIONS_HXX +#define INCLUDED_CODEMAKER_OPTIONS_HXX + +#include +#include +#include + +typedef std::unordered_map +< + ::rtl::OString, + ::rtl::OString, + OStringHash +> OptionMap; + +class IllegalArgument +{ +public: + IllegalArgument(::rtl::OString msg) + : m_message(std::move(msg)) {} + + ::rtl::OString m_message; +}; + +class Options +{ +public: + Options(); + virtual ~Options(); + + /// @throws IllegalArgument + virtual bool initOptions(int ac, char* av[], bool bCmdFile=false) = 0; + + virtual ::rtl::OString prepareHelp() = 0; + + const ::rtl::OString& getProgramName() const { return m_program;} + bool isValid(const ::rtl::OString& option) const; + /// @throws IllegalArgument + const OString& getOption(const ::rtl::OString& option) const; + + const StringVector& getInputFiles() const { return m_inputFiles;} + + const StringVector& getExtraInputFiles() const + { return m_extra_input_files; } +protected: + ::rtl::OString m_program; + StringVector m_inputFiles; + StringVector m_extra_input_files; + OptionMap m_options; +}; + +#endif // INCLUDED_CODEMAKER_OPTIONS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/typemanager.hxx b/include/codemaker/typemanager.hxx new file mode 100644 index 0000000000..3e6f67fe4b --- /dev/null +++ b/include/codemaker/typemanager.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_TYPEMANAGER_HXX +#define INCLUDED_CODEMAKER_TYPEMANAGER_HXX + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace unoidl { + class Entity; + class Manager; + class MapCursor; + class Provider; +} + +class TypeManager final : public salhelper::SimpleReferenceObject { +public: + TypeManager(); + + void loadProvider(OUString const & uri, bool primary); + + bool foundAtPrimaryProvider(OUString const & name) const; + + codemaker::UnoType::Sort getSort( + OUString const & name, rtl::Reference< unoidl::Entity > * entity = nullptr, + rtl::Reference< unoidl::MapCursor > * cursor = nullptr) const; + + 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; + +private: + virtual ~TypeManager() override; + + rtl::Reference< unoidl::Manager > manager_; + std::vector< rtl::Reference< unoidl::Provider > > primaryProviders_; +}; + + +inline OString u2b(std::u16string_view s) { + return OUStringToOString(s, RTL_TEXTENCODING_UTF8); +} + +inline OUString b2u(std::string_view s) { + return OStringToOUString(s, RTL_TEXTENCODING_UTF8); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/unotype.hxx b/include/codemaker/unotype.hxx new file mode 100644 index 0000000000..6063218732 --- /dev/null +++ b/include/codemaker/unotype.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CODEMAKER_UNOTYPE_HXX +#define INCLUDED_CODEMAKER_UNOTYPE_HXX + +#include + +#include + +namespace rtl { class OString; } + +namespace codemaker::UnoType { + /** + An enumeration of all the sorts of relevant UNOIDL entities. + */ + enum class Sort { + Void, + Boolean, + Byte, + Short, + UnsignedShort, + Long, + UnsignedLong, + Hyper, + UnsignedHyper, + Float, + Double, + Char, + String, + Type, + Any, + Sequence, + Module, + Enum, + PlainStruct, + PolymorphicStructTemplate, + InstantiatedPolymorphicStruct, + Exception, + Interface, + Typedef, + ConstantGroup, + SingleInterfaceBasedService, + AccumulationBasedService, + InterfaceBasedSingleton, + ServiceBasedSingleton + }; + + /** + Decomposes a UNO type name or UNO type registry name. + + @param type a binary UNO type name or UNO type registry name + + @param rank if non-null, returns the rank of the denoted UNO type (which + is zero for any given type that does not denote a UNO sequence type) + + @param arguments if non-null, the type arguments are stripped from an + instantiated polymorphic struct type and returned via this parameter (in + the correct order); if null, type arguments are not stripped from + instantiated polymorphic struct types + + @return the base part of the given type + */ + rtl::OString decompose( + rtl::OString const & type, sal_Int32 * rank = nullptr, + std::vector< rtl::OString > * arguments = nullptr); + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3