LibreOffice Module codemaker (master) 1
cppumaker.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 <iostream>
25#include <vector>
26
29#include <rtl/ref.hxx>
30#include <rtl/string.hxx>
31#include <rtl/ustring.hxx>
32#include <sal/main.h>
33#include <sal/types.h>
34#include <unoidl/unoidl.hxx>
35#include <o3tl/string_view.hxx>
36
37#include "cppuoptions.hxx"
38#include "cpputype.hxx"
39
40// coverity[tainted_data] - this is a build time tool
42 CppuOptions options;
43 try {
44 if (!options.initOptions(argc, argv)) {
45 return EXIT_FAILURE;
46 }
47
48 rtl::Reference typeMgr(new TypeManager);
49 for (const OString& f :options.getExtraInputFiles())
50 {
51 typeMgr->loadProvider(convertToFileUrl(f), false);
52 }
53 for (const OString& f : options.getInputFiles())
54 {
55 typeMgr->loadProvider(convertToFileUrl(f), true);
56 }
58 if (options.isValid("-T")) {
59 OUString names(b2u(options.getOption("-T")));
60 for (sal_Int32 i = 0; i != -1;) {
61 std::u16string_view name(o3tl::getToken(names, 0, ';', i));
62 if (!name.empty()) {
63 produce(
64 OUString(name == u"*"
65 ? u""
66 : o3tl::ends_with(name, u".*")
67 ? name.substr(0, name.size() - std::strlen(".*"))
68 : name),
69 typeMgr, generated, options);
70 }
71 }
72 } else {
73 produce("", typeMgr, generated, options);
74 }
75 if (!options.isValid("-nD")) {
76 // C++ header files generated for the following UNO types are
77 // included in header files in cppu/inc/com/sun/star/uno (Any.hxx,
78 // Reference.hxx, Type.h), so it seems best to always generate those
79 // C++ header files:
80 produce(
81 "com.sun.star.uno.RuntimeException", typeMgr, generated,
82 options);
83 produce(
84 "com.sun.star.uno.TypeClass", typeMgr, generated, options);
85 produce(
86 "com.sun.star.uno.XInterface", typeMgr, generated, options);
87 }
88 } catch (CannotDumpException & e) {
89 std::cerr << "ERROR: " << e.getMessage() << '\n';
90 return EXIT_FAILURE;
91 } catch (unoidl::NoSuchFileException & e) {
92 std::cerr << "ERROR: No such file <" << e.getUri() << ">\n";
93 return EXIT_FAILURE;
94 } catch (unoidl::FileFormatException & e) {
95 std::cerr
96 << "ERROR: Bad format of <" << e.getUri() << ">, \""
97 << e.getDetail() << "\"\n";
98 return EXIT_FAILURE;
99 } catch (IllegalArgument& e) {
100 std::cerr << "Illegal option " << e.m_message << '\n';
101 return EXIT_FAILURE;
102 } catch (std::exception& e) {
103 std::cerr << "Failure " << e.what() << '\n';
104 return EXIT_FAILURE;
105 }
106
107 return EXIT_SUCCESS;
108}
109
110/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & getMessage() const
Definition: global.hxx:88
bool initOptions(int ac, char *av[], bool bCmdFile=false) override
Definition: cppuoptions.cxx:31
bool isValid(const ::rtl::OString &option) const
Definition: options.cxx:26
const OString & getOption(const ::rtl::OString &option) const
Definition: options.cxx:31
const StringVector & getExtraInputFiles() const
Definition: options.hxx:61
const StringVector & getInputFiles() const
Definition: options.hxx:59
A simple class to track which types have already been processed by a code maker.
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
Definition: cppumaker.cxx:41
void produce(OUString const &name, rtl::Reference< TypeManager > const &manager, codemaker::GeneratedTypeSet &generated, CppuOptions const &options)
Definition: cpputype.cxx:4000
float u
OUString convertToFileUrl(const OString &fileName)
Definition: global.cxx:221
const char * name
int i
constexpr bool ends_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OUString b2u(std::string_view s)
Definition: typemanager.hxx:71