-
Notifications
You must be signed in to change notification settings - Fork 2
/
lp_creation_python_policy.hh
136 lines (110 loc) · 4.11 KB
/
lp_creation_python_policy.hh
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Copyright (C) 2024 SUSE Software Solutions Germany GmbH
*
* This file is part of klp-ccp.
*
* klp-ccp is free software: you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* klp-ccp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with klp-ccp. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _LP_CREATION_PYTHON_POLICY_HH
#define _LP_CREATION_PYTHON_POLICY_HH
#include <memory>
#include <stdexcept>
#include "lp_creation_policy.hh"
#include "ast.hh"
namespace klp
{
namespace ccp
{
class python_except : public std::runtime_error
{
public:
python_except(const char *what);
virtual ~python_except() noexcept override;
};
void handle_python_except();
class lp_creation_python_policy final : public lp_creation_policy
{
public:
lp_creation_python_policy
(const pp_result &pp_result,
std::vector<std::string> &&patched_functions,
const char * const python_policy_mod,
const char * const python_policy_cls);
virtual ~lp_creation_python_policy() noexcept override;
virtual bool
is_patched(const ast::function_definition &fd,
code_remarks &remarks) const override;
virtual bool
is_header_eligible(const pp_result::header_inclusion_root &pre_include,
code_remarks &remarks) const override;
virtual bool
is_header_eligible(const pp_result::header_inclusion_child &h,
code_remarks &remarks) const override;
virtual bool
is_function_externalizable(const ast::function_definition &fd,
code_remarks &remarks) const override;
virtual bool
is_function_externalizable(const ast::init_declarator &id,
code_remarks &remarks) const override;
virtual bool
is_function_externalization_preferred(const ast::function_definition &fd,
const bool in_eligible_headers,
code_remarks &remarks)
const override;
virtual bool
shall_externalize_object(const ast::init_declarator &id,
code_remarks &remarks) const override;
virtual externalized_symbol_modification
get_sym_mod_for_externalized_fun(const ast::direct_declarator_id &ddid,
const allocated_ids_type &allocated_ids,
code_remarks &remarks) const override;
virtual symbol_modification
get_sym_mod_for_patched_fun(const ast::function_definition &fd,
const allocated_ids_type &allocated_ids,
code_remarks &remarks) const override;
virtual std::string
rename_rewritten_closure_fun(const ast::function_definition &fd,
const allocated_ids_type &allocated_ids,
code_remarks &remarks) const override;
virtual externalized_symbol_modification
get_sym_mod_for_externalized_obj(const ast::init_declarator &id,
const allocated_ids_type &allocated_ids,
code_remarks &remarks) const override;
static void teardown_python() noexcept;
private:
// Avoid pulling in declarations from Python.h here, keep all
// related data encapuslated in a implementation internal
// struct.
struct _data;
bool
_is_header_eligible(const pp_result::header_inclusion_node &h,
const bool is_pre_include,
code_remarks &remarks) const;
bool
_is_function_externalizable(const pp_token_index id_tok,
const ast::linkage::linkage_kind linkage,
const bool is_definition,
code_remarks &remarks) const;
static pp_token_index _get_id_tok(const ast::init_declarator &id)
noexcept;
static pp_token_index _get_id_tok(const ast::function_definition &fd)
noexcept;
static pp_token_index _get_id_tok(const ast::direct_declarator_id &ddid)
noexcept;
const pp_result &_pp_result;
std::vector<std::string> _patched_functions;
std::unique_ptr<_data> _d;
};
}
}
#endif