File: pythonmaker.cxx

package info (click to toggle)
libreoffice 4%3A26.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,833,120 kB
  • sloc: cpp: 4,395,780; xml: 499,109; java: 254,438; python: 81,820; ansic: 33,823; perl: 30,297; javascript: 19,722; sh: 12,050; makefile: 10,854; cs: 8,865; yacc: 8,549; objc: 2,131; lex: 1,385; asm: 1,231; awk: 996; pascal: 914; csh: 20; sed: 5
file content (118 lines) | stat: -rw-r--r-- 3,917 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* -*- 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/.
 */

#include <sal/config.h>

#include <cstdlib>
#include <iostream>
#include <vector>

#include <codemaker/generatedtypeset.hxx>
#include <codemaker/typemanager.hxx>
#include <codemaker/global.hxx>
#include <rtl/ref.hxx>
#include <rtl/string.hxx>
#include <rtl/ustring.hxx>
#include <sal/main.h>
#include <unoidl/unoidl.hxx>
#include <o3tl/string_view.hxx>

#include "pythonoptions.hxx"
#include "pythontype.hxx"

// coverity[tainted_data] - this is a build time tool
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
{
    // Object to hold parsed command-line options.
    PythonOptions options;
    try
    {
        // Initialize the options object from command-line arguments.
        // If it fails (e.g., --help or invalid options), it returns false.
        if (!options.initOptions(argc, argv))
        {
            return EXIT_FAILURE;
        }

        rtl::Reference<TypeManager> typeMgr(new TypeManager);
        for (const OString& f : options.getExtraInputFiles())
        {
            typeMgr->loadProvider(convertToFileUrl(f), false);
        }

        // Load the primary RDB files. Types from these files are the main candidates for stub generation.
        for (const OString& f : options.getInputFiles())
        {
            typeMgr->loadProvider(convertToFileUrl(f), true);
        }

        // `GeneratedTypeSet` keeps track of which types have already been processed
        // to avoid redundant work and infinite loops in case of circular dependencies.
        codemaker::GeneratedTypeSet generated;
        if (options.isValid("-T"_ostr))
        {
            OUString names(b2u(options.getOption("-T"_ostr)));
            for (sal_Int32 i = 0; i != -1;)
            {
                std::u16string_view name(o3tl::getToken(names, 0, ';', i));
                if (!name.empty())
                {
                    codemaker::pythonmaker::produce(
                        OUString(name == u"*"
                                     ? u""
                                     : o3tl::ends_with(name, u".*")
                                           ? name.substr(0, name.size() - std::strlen(".*"))
                                           : name),
                        typeMgr, generated, options);
                }
            }
        }
        else
        {
            // If -T is not specified, start the generation process from the root (global) namespace.
            codemaker::pythonmaker::produce(u""_ustr, typeMgr, generated, options);
        }
    }
    // Catch specific, known exceptions to provide clear error messages.
    catch (CannotDumpException const& e)
    {
        std::cerr << "ERROR: " << u2b(e.getMessage()) << '\n';
        return EXIT_FAILURE;
    }
    catch (unoidl::NoSuchFileException const& e)
    {
        std::cerr << "ERROR: No such file <" << u2b(e.getUri()) << ">\n";
        return EXIT_FAILURE;
    }
    catch (unoidl::FileFormatException const& e)
    {
        std::cerr << "ERROR: Bad format of <" << u2b(e.getUri()) << ">, \"" << u2b(e.getDetail())
                  << "\"\n";
        return EXIT_FAILURE;
    }
    catch (IllegalArgument const& e)
    {
        std::cerr << "Illegal option: " << e.m_message << '\n';
        return EXIT_FAILURE;
    }
    catch (std::exception const& e)
    {
        std::cerr << "Standard exception: " << e.what() << '\n';
        return EXIT_FAILURE;
    }
    catch (...)
    {
        std::cerr << "Unknown C++ exception occurred.\n";
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */