diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /include/codemaker | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/codemaker')
-rw-r--r-- | include/codemaker/codemaker.hxx | 38 | ||||
-rw-r--r-- | include/codemaker/commoncpp.hxx | 62 | ||||
-rw-r--r-- | include/codemaker/commonjava.hxx | 42 | ||||
-rw-r--r-- | include/codemaker/exceptiontree.hxx | 119 | ||||
-rw-r--r-- | include/codemaker/generatedtypeset.hxx | 71 | ||||
-rw-r--r-- | include/codemaker/global.hxx | 100 | ||||
-rw-r--r-- | include/codemaker/options.hxx | 71 | ||||
-rw-r--r-- | include/codemaker/typemanager.hxx | 76 | ||||
-rw-r--r-- | include/codemaker/unotype.hxx | 91 |
9 files changed, 670 insertions, 0 deletions
diff --git a/include/codemaker/codemaker.hxx b/include/codemaker/codemaker.hxx new file mode 100644 index 000000000..81e4a5e37 --- /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 <sal/config.h> + +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 000000000..b7586e872 --- /dev/null +++ b/include/codemaker/commoncpp.hxx @@ -0,0 +1,62 @@ +/* -*- 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_COMMONCPP_HXX +#define INCLUDED_CODEMAKER_COMMONCPP_HXX + +#include <sal/config.h> + +#include <codemaker/unotype.hxx> + +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, rtl::OUString const & nucleus); + +enum class IdentifierTranslationMode { + Global, + NonGlobal +}; + +rtl::OString translateUnoToCppIdentifier( + rtl::OString const & identifier, rtl::OString const & prefix, + IdentifierTranslationMode transmode = IdentifierTranslationMode::Global, + rtl::OString const * forbidden = nullptr); + +} + +#endif // INCLUDED_CODEMAKER_COMMONCPP_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/codemaker/commonjava.hxx b/include/codemaker/commonjava.hxx new file mode 100644 index 000000000..11e1446bf --- /dev/null +++ b/include/codemaker/commonjava.hxx @@ -0,0 +1,42 @@ +/* -*- 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 <sal/config.h> + +#include <codemaker/unotype.hxx> + +namespace rtl { class OString; } + +namespace codemaker::java { + +rtl::OString translateUnoToJavaType( + codemaker::UnoType::Sort sort, rtl::OString const & nucleus, + bool referenceType); + +rtl::OString translateUnoToJavaIdentifier( + rtl::OString const & identifier, rtl::OString const & 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 000000000..eec504a39 --- /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 <codemaker/global.hxx> +#include <rtl/ref.hxx> +#include <rtl/string.hxx> + +#include <memory> +#include <vector> + +class TypeManager; + +namespace codemaker { + +/** + Represents a node of the hierarchy from the ExceptionTree class. + */ +struct ExceptionTreeNode { + typedef std::vector< std::unique_ptr<ExceptionTreeNode> > Children; + + // Internally used by ExceptionTree: + ExceptionTreeNode(rtl::OString const & theName): + name(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") {} + + /** + 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 000000000..d82c8fb1c --- /dev/null +++ b/include/codemaker/generatedtypeset.hxx @@ -0,0 +1,71 @@ +/* -*- 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 <rtl/string.hxx> + +#include <unordered_set> + +/// @HTML + +namespace codemaker { + +/** + A simple class to track which types have already been processed by a code + maker. + + <p>This class is not multi-thread–safe.</p> + */ +class GeneratedTypeSet { +public: + GeneratedTypeSet() {} + + /** + Add a type to the set of generated types. + + <p>If the type was already present, nothing happens.</p> + + @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< OString > 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 000000000..d453a0e0b --- /dev/null +++ b/include/codemaker/global.hxx @@ -0,0 +1,100 @@ +/* -*- 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 <list> +#include <vector> +#include <set> + +#include <stdio.h> + +#include <osl/file.hxx> +#include <rtl/ustring.hxx> +#include <rtl/strbuf.hxx> + +typedef ::std::list< ::rtl::OString > StringList; +typedef ::std::vector< ::rtl::OString > StringVector; +typedef ::std::set< ::rtl::OString > StringSet; + + +// 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, rtl::OUString const & 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 const & message): message_(message) {} + + ~CannotDumpException() throw (); + + 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 000000000..ca86fa1b3 --- /dev/null +++ b/include/codemaker/options.hxx @@ -0,0 +1,71 @@ +/* -*- 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 <codemaker/global.hxx> +#include <unordered_map> + +typedef std::unordered_map +< + ::rtl::OString, + ::rtl::OString, + OStringHash +> OptionMap; + +class IllegalArgument +{ +public: + IllegalArgument(const ::rtl::OString& msg) + : m_message(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 000000000..5a2d50ec0 --- /dev/null +++ b/include/codemaker/typemanager.hxx @@ -0,0 +1,76 @@ +/* -*- 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 <sal/config.h> + +#include <vector> + +#include <codemaker/unotype.hxx> +#include <rtl/ref.hxx> +#include <rtl/string.hxx> +#include <rtl/textenc.h> +#include <rtl/ustring.hxx> +#include <salhelper/simplereferenceobject.hxx> + +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( + OUString const & 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(OUString const & s) { + return OUStringToOString(s, RTL_TEXTENCODING_UTF8); +} + +inline OUString b2u(OString const & 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 000000000..90e17f519 --- /dev/null +++ b/include/codemaker/unotype.hxx @@ -0,0 +1,91 @@ +/* -*- 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 <sal/types.h> + +#include <vector> + +namespace rtl { class OString; } + +namespace codemaker { + +namespace 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: */ |